diff --git a/src/Graphics_3DS.c b/src/Graphics_3DS.c index 87f3d6888..448290165 100644 --- a/src/Graphics_3DS.c +++ b/src/Graphics_3DS.c @@ -21,9 +21,6 @@ extern const u32 offset_shbin_size; (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) - -// Current format and size of vertices -static int gfx_stride, gfx_format = -1; /*########################################################################################################################* @@ -442,11 +439,6 @@ void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) { void Gfx_UnlockDynamicVb(GfxResourceID vb) { gfx_vertices = vb; } -void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { - gfx_vertices = vb; - Mem_Copy(vb, vertices, vCount * gfx_stride); -} - void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } diff --git a/src/Graphics_D3D11.c b/src/Graphics_D3D11.c index 6c6a5ef78..56aed15a3 100644 --- a/src/Graphics_D3D11.c +++ b/src/Graphics_D3D11.c @@ -23,8 +23,7 @@ static const GUID guid_IXDGIDevice = { 0x54ec77fa, 0x1377, 0x44e6, { 0x8c, 0 // Some generally useful background links // https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052 -static int gfx_format = -1, depthBits; // TODO implement depthBits?? for ZNear calc -static UINT gfx_stride; +static int depthBits; // TODO implement depthBits?? for ZNear calc static GfxResourceID white_square; #ifdef _MSC_VER @@ -396,12 +395,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) { Gfx_BindDynamicVb(vb); } -void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { - void* data = Gfx_LockDynamicVb(vb, gfx_format, vCount); - Mem_Copy(data, vertices, vCount * gfx_stride); - Gfx_UnlockDynamicVb(vb); -} - /*########################################################################################################################* *-----------------------------------------------------Vertex rendering----------------------------------------------------* diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index 187223d6d..e8a656f69 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -19,8 +19,6 @@ /* https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dfvf-texcoordsizen */ static DWORD d3d9_formatMappings[] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 }; -/* Current format and size of vertices */ -static int gfx_stride, gfx_format = -1; static IDirect3D9* d3d; static IDirect3DDevice9* device; diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index 5693bf232..77a8c563d 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -9,9 +9,6 @@ #include #include #include - -/* Current format and size of vertices */ -static int gfx_stride, gfx_format = -1; static cc_bool renderingDisabled; @@ -166,12 +163,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) { //dcache_flush_range(vb, vb_size); } -void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { - gfx_vertices = vb; - Mem_Copy(vb, vertices, vCount * gfx_stride); - //dcache_flush_range(vertices, vCount * gfx_stride); -} - void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } diff --git a/src/Graphics_GCWii.c b/src/Graphics_GCWii.c index 92a69bb07..21568ca63 100644 --- a/src/Graphics_GCWii.c +++ b/src/Graphics_GCWii.c @@ -332,14 +332,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) { DCFlushRange(vb, vb_size); } -// Current size of vertices -static int gfx_stride; // TODO move down to Drawing area ?? -void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { - gfx_vertices = vb; - Mem_Copy(vb, vertices, vCount * gfx_stride); - DCFlushRange(vertices, vCount * gfx_stride); -} - void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } @@ -476,9 +468,6 @@ void Gfx_DisableTextureOffset(void) { /*########################################################################################################################* *---------------------------------------------------------Drawing---------------------------------------------------------* *#########################################################################################################################*/ -// Current format and size of vertices -static int gfx_format = -1; - void Gfx_SetVertexFormat(VertexFormat fmt) { if (fmt == gfx_format) return; gfx_format = fmt; diff --git a/src/Graphics_GL1.c b/src/Graphics_GL1.c index aaf55ca4c..03597f898 100644 --- a/src/Graphics_GL1.c +++ b/src/Graphics_GL1.c @@ -159,8 +159,6 @@ typedef void (*GL_SetupVBFunc)(void); typedef void (*GL_SetupVBRangeFunc)(int startVertex); static GL_SetupVBFunc gfx_setupVBFunc; static GL_SetupVBRangeFunc gfx_setupVBRangeFunc; -/* Current format and size of vertices */ -static int gfx_stride, gfx_format = -1; #if defined CC_BUILD_WIN && !defined CC_BUILD_GL11 /* Note the following about calling OpenGL functions on Windows */ diff --git a/src/Graphics_GL2.c b/src/Graphics_GL2.c index 090fa3ff3..cc036598d 100644 --- a/src/Graphics_GL2.c +++ b/src/Graphics_GL2.c @@ -86,8 +86,6 @@ static const struct DynamicLibSym core_funcs[] = { #endif #include "_GLShared.h" -/* Current format and size of vertices */ -static int gfx_stride, gfx_format = -1; static GfxResourceID white_square; diff --git a/src/Graphics_N64.c b/src/Graphics_N64.c index 143a9a397..4506a0cdd 100644 --- a/src/Graphics_N64.c +++ b/src/Graphics_N64.c @@ -9,8 +9,6 @@ #include #include -/* Current format and size of vertices */ -static int gfx_stride, gfx_format; typedef void (*GL_SetupVBFunc)(void); typedef void (*GL_SetupVBRangeFunc)(int startVertex); static GL_SetupVBFunc gfx_setupVBFunc; @@ -319,11 +317,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) { gfx_vertices = vb; } -void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { - gfx_vertices = vb; - Mem_Copy(vb, vertices, vCount * gfx_stride); -} - void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } diff --git a/src/Graphics_PS3.c b/src/Graphics_PS3.c index 4cdc7300c..30a9ff88f 100644 --- a/src/Graphics_PS3.c +++ b/src/Graphics_PS3.c @@ -7,9 +7,6 @@ #include #include #include - -/* Current format and size of vertices */ -static int gfx_stride, gfx_format = -1; static cc_bool renderingDisabled; static gcmContextData* context; @@ -550,12 +547,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) { rsxInvalidateVertexCache(context); // TODO needed? } -void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { - Mem_Copy(vb, vertices, vCount * gfx_stride); - Gfx_BindVb(vb); - rsxInvalidateVertexCache(context); // TODO needed? -} - void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } diff --git a/src/Graphics_PSP.c b/src/Graphics_PSP.c index ceec1c593..5e2b59701 100644 --- a/src/Graphics_PSP.c +++ b/src/Graphics_PSP.c @@ -266,8 +266,7 @@ void Gfx_OnWindowResize(void) { } static cc_uint8* gfx_vertices; -/* Current format and size of vertices */ -static int gfx_stride, gfx_format = -1, gfx_fields; +static int gfx_fields; /*########################################################################################################################* @@ -323,12 +322,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) { sceKernelDcacheWritebackInvalidateRange(vb, vb_size); } -void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { - gfx_vertices = vb; - Mem_Copy(vb, vertices, vCount * gfx_stride); - sceKernelDcacheWritebackInvalidateRange(vertices, vCount * gfx_stride); -} - void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } diff --git a/src/Graphics_PSVita.c b/src/Graphics_PSVita.c index bc2cd7a32..01529f407 100644 --- a/src/Graphics_PSVita.c +++ b/src/Graphics_PSVita.c @@ -7,8 +7,6 @@ #include // TODO track last frame used on -/* Current format and size of vertices */ -static int gfx_stride, gfx_format = -1; static cc_bool gfx_depthOnly; static cc_bool gfx_alphaTesting, gfx_alphaBlending; static int frontBufferIndex, backBufferIndex; diff --git a/src/Graphics_Xbox.c b/src/Graphics_Xbox.c index 0c247cc1f..dcf204c8a 100644 --- a/src/Graphics_Xbox.c +++ b/src/Graphics_Xbox.c @@ -18,10 +18,6 @@ // A lot of figuring out which GPU registers to use came from: // - comparing against pbgl and pbkit -// Current format and size of vertices -static int gfx_stride, gfx_format = -1; - - static void LoadVertexShader(uint32_t* program, int programSize) { uint32_t* p; @@ -461,11 +457,6 @@ void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) { void Gfx_UnlockDynamicVb(GfxResourceID vb) { Gfx_BindVb(vb); } -void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { - Mem_Copy(vb, vertices, vCount * gfx_stride); - Gfx_BindVb(vb); -} - void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); } diff --git a/src/Model.c b/src/Model.c index c67ebcd8c..2582d185e 100644 --- a/src/Model.c +++ b/src/Model.c @@ -882,17 +882,19 @@ struct ModelSet { struct ModelPart head, torso, hat, torsoLayer; struct ModelLimbs limbs[3]; }; +#define HUMAN_BASE_VERTICES (6 * MODEL_BOX_VERTICES) +#define HUMAN_HAT32_VERTICES (1 * MODEL_BOX_VERTICES) +#define HUMAN_HAT64_VERTICES (6 * MODEL_BOX_VERTICES) -static void HumanModel_DrawCore(struct Entity* e, struct ModelSet* model, cc_bool opaque) { +static void HumanModel_DrawCore(struct Entity* e, struct ModelSet* model, cc_bool opaqueBody) { struct ModelLimbs* set; - int type; - + int type, num; Model_ApplyTexture(e); - /* human model draws the body opaque so players can't have invisible skins */ - if (opaque) Gfx_SetAlphaTest(false); type = Models.skinType; set = &model->limbs[type & 0x3]; + num = HUMAN_BASE_VERTICES + (type == SKIN_64x32 ? HUMAN_HAT32_VERTICES : HUMAN_HAT64_VERTICES); + Model_LockVB(num); Model_DrawRotate(-e->Pitch * MATH_DEG2RAD, 0, 0, &model->head, true); Model_DrawPart(&model->torso); @@ -904,12 +906,6 @@ static void HumanModel_DrawCore(struct Entity* e, struct ModelSet* model, cc_boo Model_DrawRotate(e->Anim.RightArmX, 0, e->Anim.RightArmZ, &set->rightArm, false); Models.Rotation = ROTATE_ORDER_ZYX; - /* have to seperately draw these vertices without alpha testing */ - if (opaque) { - Model_UpdateVB(); - Gfx_SetAlphaTest(true); - } - if (type != SKIN_64x32) { Model_DrawPart(&model->torsoLayer); Model_DrawRotate(e->Anim.LeftLegX, 0, e->Anim.LeftLegZ, &set->leftLegLayer, false); @@ -921,19 +917,33 @@ static void HumanModel_DrawCore(struct Entity* e, struct ModelSet* model, cc_boo Models.Rotation = ROTATE_ORDER_ZYX; } Model_DrawRotate(-e->Pitch * MATH_DEG2RAD, 0, 0, &model->hat, true); - Model_UpdateVB(); + + Model_UnlockVB(); + if (opaqueBody) { + /* human model draws the body opaque so players can't have invisible skins */ + Gfx_SetAlphaTest(false); + Gfx_DrawVb_IndexedTris_Range(HUMAN_BASE_VERTICES, 0); + Gfx_SetAlphaTest(true); + Gfx_DrawVb_IndexedTris_Range(num - HUMAN_BASE_VERTICES, HUMAN_BASE_VERTICES); + } else { + Gfx_DrawVb_IndexedTris(num); + } } static void HumanModel_DrawArmCore(struct ModelSet* model) { struct ModelLimbs* set; - int type; + int type, num; type = Models.skinType; set = &model->limbs[type & 0x3]; + num = type == SKIN_64x32 ? MODEL_BOX_VERTICES : (2 * MODEL_BOX_VERTICES); + Model_LockVB(num); Model_DrawArmPart(&set->rightArm); if (type != SKIN_64x32) Model_DrawArmPart(&set->rightArmLayer); - Model_UpdateVB(); + + Model_UnlockVB(); + Gfx_DrawVb_IndexedTris(num); } diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index 6e5c5a453..d8d76be90 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -19,6 +19,8 @@ const cc_string Gfx_LowPerfMessage = String_FromConst("&eRunning in reduced perf static const int strideSizes[] = { SIZEOF_VERTEX_COLOURED, SIZEOF_VERTEX_TEXTURED }; /* Whether mipmaps must be created for all dimensions down to 1x1 or not */ static cc_bool customMipmapsLevels; +/* Current format and size of vertices */ +static int gfx_stride, gfx_format = -1; static cc_bool gfx_vsync, gfx_fogEnabled; static float gfx_minFrameMs; @@ -389,6 +391,16 @@ GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices) { } } +#if defined CC_BUILD_GL || defined CC_BUILD_D3D9 +/* Slightly more efficient implementations are defined in the backends */ +#else +void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { + void* data = Gfx_LockDynamicVb(vb, gfx_format, vCount); + Mem_Copy(data, vertices, vCount * gfx_stride); + Gfx_UnlockDynamicVb(vb); +} +#endif + /*########################################################################################################################* *----------------------------------------------------Graphics component---------------------------------------------------*