Fix isometric rendered blocks being slightly misaligned on OpenGL/Direct3D 11 (Thanks 123DMWM), fix sometimes not compiling on recent macOS due to CGDisplayBitsPerPixel no longer being defined

This commit is contained in:
UnknownShadow200 2023-06-12 18:59:22 +10:00
parent d453eb3d97
commit cca8ff64a3
8 changed files with 41 additions and 31 deletions

View File

@ -126,8 +126,6 @@ jobs:
if: matrix.config.plat == 'Mac' && matrix.config.bits == 64
run: |
cd src
# fix for "error: implicit declaration of function 'CGDisplayBitsPerPixel'"
sed -i '' 's|#include <Cocoa/Cocoa.h>|&\'$'\nextern size_t CGDisplayBitsPerPixel(CGDirectDisplayID display);|' interop_cocoa.m
make mac_x64
- name: Build for ${{ matrix.config.plat }} (${{ matrix.config.bits }} bit)

View File

@ -6,35 +6,41 @@ TODO introduction (explaining platform specific modules, and how classicube has
Two ways
1) Changing the defines in `Core.h`
2) Adding `-DCC_BUILD_MANUAL` to compilation flags and manually defining module backends
2) Adding `-DCC_BUILD_MANUAL` to compilation flags and then manually defining module backends via additional compilation flags
Graphics backends
When manually compiling the source code, 1) is usually the easiest. <br>
For automated scripts compiling every single commit, 2) is the recommended approach
### 3D Graphics backends
* CC_BUILD_D3D9 - Direct3D 9
* CC_BUILD_D3D11 - Direct3D 11
* CC_BUILD_GL - OpenGL
The OpenGL backend can be further customised:
* CC_BUILD_GL11 - (must also have CC_BUILD_GL defined)
* CC_BUILD_GLMODERN - (must also have CC_BUILD_GL defined)
* CC_BUILD_GLES (must also have CC_BUILD_GL defined)
* CC_BUILD_GL11 - (must also have CC_BUILD_GL defined)
OpenGL context backends
### OpenGL context backends
* CC_BUILD_EGL
* CC_BUILD_WGL
HTTP backends
### HTTP backends
* CC_BUILD_CURL
* CC_BUILD_HTTPCLIENT - custom HTTP client
* CC_BUILD_WININET
* CC_BUILD_CFNETWORK
SSL backends
### SSL backends
* CC_BUILD_SCHANNEL
Window backends
### Window backends
* CC_BUILD_SDL
* CC_BUILD_X11
* CC_BUILD_WINGUI
Platform backends
### Platform backends
* CC_BUILD_POSIX
* CC_BUILD_WIN

View File

@ -127,11 +127,13 @@ void IsometricDrawer_BeginBatch(struct VertexTextured* vertices, int* state) {
void IsometricDrawer_AddBatch(BlockID block, float size, float x, float y) {
struct VertexTextured* beg = iso_vertices;
if (Blocks.Draw[block] == DRAW_GAS) return;
/* See comment in GfxCommon_Draw2DTexture() for why 0.5 is subtracted */
/* TODO only for Direct3D 9?? pass in registers? */
iso_posX = x - 0.5f;
iso_posY = y - 0.5f;
iso_posX = x; iso_posY = y;
/* See comment in Gfx_Make2DQuad() for why 0.5 is subtracted in D3D9 */
/* TODO pass as arguments? test diff */
#ifdef CC_BUILD_D3D9
iso_posX -= 0.5f; iso_posY -= 0.5f;
#endif
if (Blocks.Draw[block] == DRAW_SPRITE) {
IsometricDrawer_Flat(block, size);

View File

@ -9,10 +9,10 @@ struct VertexTextured;
/* Maximum number of vertices used to draw a block in isometric way. */
#define ISOMETRICDRAWER_MAXVERTICES 12
/* Sets up state to begin drawing blocks isometrically. */
/* Sets up state to begin drawing blocks isometrically */
void IsometricDrawer_BeginBatch(struct VertexTextured* vertices, int* state);
/* Buffers the vertices needed to draw the given block at the given position. */
/* Buffers the vertices needed to draw the given block at the given position */
void IsometricDrawer_AddBatch(BlockID block, float size, float x, float y);
/* Flushes buffered vertices to the GPU, then restores state. */
/* Flushes buffered vertices to the GPU */
void IsometricDrawer_EndBatch(GfxResourceID vb);
#endif

View File

@ -1461,6 +1461,7 @@ static void InventoryScreen_UpdateTitle(struct InventoryScreen* s, BlockID block
String_InitArray(desc, descBuffer);
InventoryScreen_GetTitleText(&desc, block);
TextWidget_Set(&s->title, &desc, &s->font);
s->dirty = true;
}
static void InventoryScreen_OnUpdateTitle(BlockID block) {
@ -1475,6 +1476,9 @@ static void InventoryScreen_OnBlockChanged(void* screen) {
static void InventoryScreen_ContextLost(void* screen) {
struct InventoryScreen* s = (struct InventoryScreen*)screen;
Gfx_DeleteDynamicVb(&s->vb);
s->table.vb = 0;
Font_Free(&s->font);
Elem_Free(&s->table);
Elem_Free(&s->title);
@ -1482,11 +1486,15 @@ static void InventoryScreen_ContextLost(void* screen) {
static void InventoryScreen_ContextRecreated(void* screen) {
struct InventoryScreen* s = (struct InventoryScreen*)screen;
Gfx_RecreateDynamicVb(&s->vb, VERTEX_FORMAT_TEXTURED, TEXTWIDGET_MAX + TABLE_MAX_VERTICES);
s->table.vb = s->vb;
Gui_MakeBodyFont(&s->font);
TableWidget_Recreate(&s->table);
}
static void InventoryScreen_BuildMesh(void* screen) { }
static void InventoryScreen_BuildMesh(void* screen) {
}
static void InventoryScreen_MoveToSelected(struct InventoryScreen* s) {
struct TableWidget* table = &s->table;

View File

@ -4,8 +4,6 @@
#include "ExtMath.h"
#include "Funcs.h"
#include "Window.h"
#include "Inventory.h"
#include "IsometricDrawer.h"
#include "Utils.h"
#include "Model.h"
#include "Screens.h"
@ -636,11 +634,9 @@ void HotbarWidget_SetFont(struct HotbarWidget* w, struct FontDesc* font) {
*#########################################################################################################################*/
static int Table_X(struct TableWidget* w) { return w->x - w->paddingL; }
static int Table_Y(struct TableWidget* w) { return w->y - w->paddingT; }
static int Table_Width(struct TableWidget* w) { return w->width + w->paddingL + w->paddingR; }
static int Table_Width(struct TableWidget* w) { return w->width + w->paddingL + w->paddingR; }
static int Table_Height(struct TableWidget* w) { return w->height + w->paddingT + w->paddingB; }
#define TABLE_MAX_VERTICES (8 * 10 * ISOMETRICDRAWER_MAXVERTICES)
static cc_bool TableWidget_GetCoords(struct TableWidget* w, int i, int* cellX, int* cellY) {
int x, y;
x = i % w->blocksPerRow;
@ -756,15 +752,10 @@ static void TableWidget_Render(void* widget, double delta) {
IsometricDrawer_EndBatch(w->vb);
}
static void TableWidget_Free(void* widget) {
struct TableWidget* w = (struct TableWidget*)widget;
Gfx_DeleteDynamicVb(&w->vb);
w->lastCreatedIndex = -1000;
}
static void TableWidget_Free(void* widget) { }
void TableWidget_Recreate(struct TableWidget* w) {
Elem_Free(w);
Gfx_RecreateDynamicVb(&w->vb, VERTEX_FORMAT_TEXTURED, TABLE_MAX_VERTICES);
w->lastCreatedIndex = -1000;
TableWidget_RecreateTitle(w);
}

View File

@ -5,6 +5,7 @@
#include "Constants.h"
#include "Entity.h"
#include "Inventory.h"
#include "IsometricDrawer.h"
/* Contains all 2D widget implementations.
Copyright 2014-2022 ClassiCube | Licensed under BSD-3
*/
@ -99,6 +100,7 @@ struct TableWidget {
int paddingL, paddingR, paddingT, paddingB;
void (*UpdateTitle)(BlockID block);
};
#define TABLE_MAX_VERTICES (8 * 10 * ISOMETRICDRAWER_MAXVERTICES)
CC_NOINLINE void TableWidget_Create(struct TableWidget* w);
/* Sets the selected block in the table to the given block. */

View File

@ -18,6 +18,9 @@ static cc_bool scroll_debugging;
/*########################################################################################################################*
*---------------------------------------------------Shared with Carbon----------------------------------------------------*
*#########################################################################################################################*/
extern size_t CGDisplayBitsPerPixel(CGDirectDisplayID display);
// TODO: Try NSBitsPerPixelFromDepth([NSScreen mainScreen].depth) instead
// NOTE: If code here is changed, don't forget to update corresponding code in Window_Carbon.c
static void Window_CommonInit(void) {
CGDirectDisplayID display = CGMainDisplayID();