From c9cd91cbd8373d2a29fd85c110e9a1923b88c055 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 13 Apr 2026 12:29:06 -0500 Subject: [PATCH] Make color optional --- .../asset/loader/display/assetmeshloader.c | 22 ++-- src/dusk/display/mesh/cube.c | 23 ++-- src/dusk/display/mesh/meshvertex.h | 9 +- src/dusk/display/mesh/quad.c | 110 ++++++++++++++---- src/dusk/display/mesh/quad.h | 8 +- src/dusk/display/screen/screen.c | 8 +- src/dusk/display/spritebatch/spritebatch.c | 18 ++- src/dusk/display/spritebatch/spritebatch.h | 8 +- src/dusk/display/text/text.c | 20 +++- src/dusk/display/text/text.h | 8 +- src/dusk/engine/engine.c | 10 +- .../script/module/display/modulespritebatch.c | 4 +- src/dusk/script/module/display/moduletext.c | 4 +- src/dusk/util/memory.c | 7 ++ src/duskgl/display/mesh/meshgl.c | 47 +++++--- src/duskgl/display/shader/shaderunlitgl.c | 18 ++- 16 files changed, 242 insertions(+), 82 deletions(-) diff --git a/src/dusk/asset/loader/display/assetmeshloader.c b/src/dusk/asset/loader/display/assetmeshloader.c index 08eebc29..92ca40c3 100644 --- a/src/dusk/asset/loader/display/assetmeshloader.c +++ b/src/dusk/asset/loader/display/assetmeshloader.c @@ -57,16 +57,18 @@ errorret_t assetMeshLoader(assetfile_t *file) { // Fix endianess of of data for(uint8_t j = 0; j < 3; j++) { - verts[i * 3 + j].color.r = (uint8_t)(endianLittleToHostFloat( - triData.normal[0] - ) * 255.0f); - verts[i * 3 + j].color.g = (uint8_t)(endianLittleToHostFloat( - triData.normal[1] - ) * 255.0f); - verts[i * 3 + j].color.b = (uint8_t)(endianLittleToHostFloat( - triData.normal[2] - ) * 255.0f); - verts[i * 3 + j].color.a = 0xFF; + #if MESH_ENABLE_COLOR + verts[i * 3 + j].color.r = (uint8_t)(endianLittleToHostFloat( + triData.normal[0] + ) * 255.0f); + verts[i * 3 + j].color.g = (uint8_t)(endianLittleToHostFloat( + triData.normal[1] + ) * 255.0f); + verts[i * 3 + j].color.b = (uint8_t)(endianLittleToHostFloat( + triData.normal[2] + ) * 255.0f); + verts[i * 3 + j].color.a = 0xFF; + #endif verts[i * 3 + j].uv[0] = 0.0f; // No UV data in STL, just set to 0 verts[i * 3 + j].uv[1] = 0.0f; diff --git a/src/dusk/display/mesh/cube.c b/src/dusk/display/mesh/cube.c index 84852152..14c5e2c1 100644 --- a/src/dusk/display/mesh/cube.c +++ b/src/dusk/display/mesh/cube.c @@ -25,13 +25,22 @@ errorret_t cubeInit() { } // Helper macro: set one vertex position, UV and color. -#define CUBE_VERT(i, px, py, pz, u, v) \ - vertices[i].pos[0] = (px); \ - vertices[i].pos[1] = (py); \ - vertices[i].pos[2] = (pz); \ - vertices[i].uv[0] = (u); \ - vertices[i].uv[1] = (v); \ - vertices[i].color = color +#if MESH_ENABLE_COLOR + #define CUBE_VERT(i, px, py, pz, u, v) \ + vertices[i].color = color; \ + vertices[i].pos[0] = (px); \ + vertices[i].pos[1] = (py); \ + vertices[i].pos[2] = (pz); \ + vertices[i].uv[0] = (u); \ + vertices[i].uv[1] = (v); +#else + #define CUBE_VERT(i, px, py, pz, u, v) \ + vertices[i].pos[0] = (px); \ + vertices[i].pos[1] = (py); \ + vertices[i].pos[2] = (pz); \ + vertices[i].uv[0] = (u); \ + vertices[i].uv[1] = (v); +#endif void cubeBuffer( meshvertex_t *vertices, diff --git a/src/dusk/display/mesh/meshvertex.h b/src/dusk/display/mesh/meshvertex.h index ea976cac..b4fba54e 100644 --- a/src/dusk/display/mesh/meshvertex.h +++ b/src/dusk/display/mesh/meshvertex.h @@ -9,11 +9,18 @@ #include "dusk.h" #include "display/color.h" +#ifndef MESH_ENABLE_COLOR + #define MESH_ENABLE_COLOR 0 +#endif + #define MESH_VERTEX_UV_SIZE 2 #define MESH_VERTEX_POS_SIZE 3 typedef struct { - color_t color; + #if MESH_ENABLE_COLOR + color_t color; + #endif + float_t uv[MESH_VERTEX_UV_SIZE]; float_t pos[MESH_VERTEX_POS_SIZE]; } meshvertex_t; \ No newline at end of file diff --git a/src/dusk/display/mesh/quad.c b/src/dusk/display/mesh/quad.c index dc87cef0..dc3fa265 100644 --- a/src/dusk/display/mesh/quad.c +++ b/src/dusk/display/mesh/quad.c @@ -10,13 +10,55 @@ mesh_t QUAD_MESH_SIMPLE; meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = { - { .color = COLOR_WHITE_4B, .uv = { 0.0f, 0.0f }, .pos = { 0.0f, 0.0f, 0.0f } }, - { .color = COLOR_WHITE_4B, .uv = { 1.0f, 0.0f }, .pos = { 1.0f, 0.0f, 0.0f } }, - { .color = COLOR_WHITE_4B, .uv = { 1.0f, 1.0f }, .pos = { 1.0f, 1.0f, 0.0f } }, + { + #if MESH_ENABLE_COLOR + .color = COLOR_WHITE_4B, + #endif - { .color = COLOR_WHITE_4B, .uv = { 0.0f, 0.0f }, .pos = { 0.0f, 0.0f, 0.0f } }, - { .color = COLOR_WHITE_4B, .uv = { 1.0f, 1.0f }, .pos = { 1.0f, 1.0f, 0.0f } }, - { .color = COLOR_WHITE_4B, .uv = { 0.0f, 1.0f }, .pos = { 0.0f, 1.0f, 0.0f } } + .uv = { 0.0f, 0.0f }, + .pos = { 0.0f, 0.0f, 0.0f } + }, + + { + #if MESH_ENABLE_COLOR + .color = COLOR_WHITE_4B, + #endif + .uv = { 1.0f, 0.0f }, + .pos = { 1.0f, 0.0f, 0.0f } + }, + + { + #if MESH_ENABLE_COLOR + .color = COLOR_WHITE_4B, + #endif + .uv = { 1.0f, 1.0f }, + .pos = { 1.0f, 1.0f, 0.0f } + }, + + + { + #if MESH_ENABLE_COLOR + .color = COLOR_WHITE_4B, + #endif + .uv = { 0.0f, 0.0f }, + .pos = { 0.0f, 0.0f, 0.0f } + }, + + { + #if MESH_ENABLE_COLOR + .color = COLOR_WHITE_4B, + #endif + .uv = { 1.0f, 1.0f }, + .pos = { 1.0f, 1.0f, 0.0f } + }, + + { + #if MESH_ENABLE_COLOR + .color = COLOR_WHITE_4B, + #endif + .uv = { 0.0f, 1.0f }, + .pos = { 0.0f, 1.0f, 0.0f } + } }; errorret_t quadInit() { @@ -35,7 +77,9 @@ void quadBuffer( const float_t minY, const float_t maxX, const float_t maxY, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const float_t u0, const float_t v0, const float_t u1, @@ -45,21 +89,27 @@ void quadBuffer( assertNotNull(vertices, "Vertices cannot be NULL"); // First triangle - vertices[0].color = color; + #if MESH_ENABLE_COLOR + vertices[0].color = color; + #endif vertices[0].uv[0] = u0; vertices[0].uv[1] = v1; vertices[0].pos[0] = minX; vertices[0].pos[1] = maxY; vertices[0].pos[2] = z; - vertices[1].color = color; + #if MESH_ENABLE_COLOR + vertices[1].color = color; + #endif vertices[1].uv[0] = u1; vertices[1].uv[1] = v0; vertices[1].pos[0] = maxX; vertices[1].pos[1] = minY; vertices[1].pos[2] = z; - vertices[2].color = color; + #if MESH_ENABLE_COLOR + vertices[2].color = color; + #endif vertices[2].uv[0] = u0; vertices[2].uv[1] = v0; vertices[2].pos[0] = minX; @@ -67,21 +117,27 @@ void quadBuffer( vertices[2].pos[2] = z; // Second triangle - vertices[3].color = color; + #if MESH_ENABLE_COLOR + vertices[3].color = color; + #endif vertices[3].uv[0] = u0; vertices[3].uv[1] = v1; vertices[3].pos[0] = minX; vertices[3].pos[1] = maxY; vertices[3].pos[2] = z; - vertices[4].color = color; + #if MESH_ENABLE_COLOR + vertices[4].color = color; + #endif vertices[4].uv[0] = u1; vertices[4].uv[1] = v1; vertices[4].pos[0] = maxX; vertices[4].pos[1] = maxY; vertices[4].pos[2] = z; - vertices[5].color = color; + #if MESH_ENABLE_COLOR + vertices[5].color = color; + #endif vertices[5].uv[0] = u1; vertices[5].uv[1] = v0; vertices[5].pos[0] = maxX; @@ -93,7 +149,9 @@ void quadBuffer3D( meshvertex_t *vertices, const vec3 min, const vec3 max, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const vec2 uvMin, const vec2 uvMax ) { @@ -104,21 +162,27 @@ void quadBuffer3D( assertNotNull(uvMax, "UV Max vector cannot be NULL"); // First triangle - vertices[0].color = color; + #if MESH_ENABLE_COLOR + vertices[0].color = color; + #endif vertices[0].uv[0] = uvMin[0]; vertices[0].uv[1] = uvMin[1]; vertices[0].pos[0] = min[0]; vertices[0].pos[1] = min[1]; vertices[0].pos[2] = min[2]; - vertices[1].color = color; + #if MESH_ENABLE_COLOR + vertices[1].color = color; + #endif vertices[1].uv[0] = uvMax[0]; vertices[1].uv[1] = uvMin[1]; vertices[1].pos[0] = max[0]; vertices[1].pos[1] = min[1]; vertices[1].pos[2] = min[2]; - vertices[2].color = color; + #if MESH_ENABLE_COLOR + vertices[2].color = color; + #endif vertices[2].uv[0] = uvMax[0]; vertices[2].uv[1] = uvMax[1]; vertices[2].pos[0] = max[0]; @@ -126,21 +190,27 @@ void quadBuffer3D( vertices[2].pos[2] = min[2]; // Second triangle - vertices[3].color = color; + #if MESH_ENABLE_COLOR + vertices[3].color = color; + #endif vertices[3].uv[0] = uvMin[0]; vertices[3].uv[1] = uvMin[1]; vertices[3].pos[0] = min[0]; vertices[3].pos[1] = min[1]; vertices[3].pos[2] = min[2]; - vertices[4].color = color; + #if MESH_ENABLE_COLOR + vertices[4].color = color; + #endif vertices[4].uv[0] = uvMax[0]; vertices[4].uv[1] = uvMax[1]; vertices[4].pos[0] = max[0]; vertices[4].pos[1] = max[1]; vertices[4].pos[2] = min[2]; - vertices[5].color = color; + #if MESH_ENABLE_COLOR + vertices[5].color = color; + #endif vertices[5].uv[0] = uvMin[0]; vertices[5].uv[1] = uvMax[1]; vertices[5].pos[0] = min[0]; diff --git a/src/dusk/display/mesh/quad.h b/src/dusk/display/mesh/quad.h index 6c160f80..cf60d638 100644 --- a/src/dusk/display/mesh/quad.h +++ b/src/dusk/display/mesh/quad.h @@ -42,7 +42,9 @@ void quadBuffer( const float_t minY, const float_t maxX, const float_t maxY, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const float_t u0, const float_t v0, const float_t u1, @@ -63,7 +65,9 @@ void quadBuffer3D( meshvertex_t *vertices, const vec3 min, const vec3 max, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const vec2 uvMin, const vec2 uvMax ); \ No newline at end of file diff --git a/src/dusk/display/screen/screen.c b/src/dusk/display/screen/screen.c index 5e793bd7..2acab6b6 100644 --- a/src/dusk/display/screen/screen.c +++ b/src/dusk/display/screen/screen.c @@ -26,7 +26,9 @@ errorret_t screenInit() { SCREEN.frameBufferMeshVertices, 0.0f, 0.0f, 1.0f, 1.0f, - COLOR_WHITE, + #if MESH_ENABLE_COLOR + COLOR_WHITE, + #endif 0.0f, 0.0f, 1.0f, 1.0f ); @@ -361,7 +363,9 @@ errorret_t screenRender() { SCREEN.frameBufferMeshVertices, centerX - fbWidth * 0.5f, centerY + fbHeight * 0.5f, // top-left centerX + fbWidth * 0.5f, centerY - fbHeight * 0.5f, // bottom-right - COLOR_WHITE, + #if MESH_ENABLE_COLOR + COLOR_WHITE, + #endif 0.0f, 0.0f, 1.0f, 1.0f ); diff --git a/src/dusk/display/spritebatch/spritebatch.c b/src/dusk/display/spritebatch/spritebatch.c index 4571af50..2e62bacb 100644 --- a/src/dusk/display/spritebatch/spritebatch.c +++ b/src/dusk/display/spritebatch/spritebatch.c @@ -29,7 +29,9 @@ errorret_t spriteBatchPush( const float_t minY, const float_t maxX, const float_t maxY, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const float_t u0, const float_t v0, const float_t u1, @@ -38,7 +40,9 @@ errorret_t spriteBatchPush( return spriteBatchPush3D( (vec3){ minX, minY, 0 }, (vec3){ maxX, maxY, 0 }, - color, + #if MESH_ENABLE_COLOR + color, + #endif (vec2){ u0, v0 }, (vec2){ u1, v1 } ); @@ -47,7 +51,9 @@ errorret_t spriteBatchPush( errorret_t spriteBatchPush3D( const vec3 min, const vec3 max, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const vec2 uv0, const vec2 uv1 ) { @@ -62,7 +68,11 @@ errorret_t spriteBatchPush3D( ) * QUAD_VERTEX_COUNT; quadBuffer3D( &SPRITEBATCH_VERTICES[vertexOffset], - min, max, color, uv0, uv1 + min, max, + #if MESH_ENABLE_COLOR + color, + #endif + uv0, uv1 ); SPRITEBATCH.spriteCount++; errorOk(); diff --git a/src/dusk/display/spritebatch/spritebatch.h b/src/dusk/display/spritebatch/spritebatch.h index 3c8da32d..d7a4f878 100644 --- a/src/dusk/display/spritebatch/spritebatch.h +++ b/src/dusk/display/spritebatch/spritebatch.h @@ -57,7 +57,9 @@ errorret_t spriteBatchPush( const float_t minY, const float_t maxX, const float_t maxY, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const float_t u0, const float_t v0, const float_t u1, @@ -78,7 +80,9 @@ errorret_t spriteBatchPush( errorret_t spriteBatchPush3D( const vec3 min, const vec3 max, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const vec2 uvMin, const vec2 uvMax ); diff --git a/src/dusk/display/text/text.c b/src/dusk/display/text/text.c index 73eb5a68..196a3a23 100644 --- a/src/dusk/display/text/text.c +++ b/src/dusk/display/text/text.c @@ -33,7 +33,9 @@ errorret_t textDrawChar( const float_t x, const float_t y, const char_t c, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const tileset_t *tileset, texture_t *texture ) { @@ -55,7 +57,9 @@ errorret_t textDrawChar( x, y, x + tileset->tileWidth, y + tileset->tileHeight, - color, + #if MESH_ENABLE_COLOR + color, + #endif uv[0], uv[1], uv[2], uv[3] )); errorOk(); @@ -66,7 +70,9 @@ errorret_t textDraw( const float_t x, const float_t y, const char_t *text, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const tileset_t *tileset, texture_t *texture ) { @@ -100,7 +106,13 @@ errorret_t textDraw( continue; } - errorChain(textDrawChar(posX, posY, c, color, tileset, texture)); + errorChain(textDrawChar( + posX, posY, c, + #if MESH_ENABLE_COLOR + color, + #endif + tileset, texture + )); posX += tileset->tileWidth; } errorOk(); diff --git a/src/dusk/display/text/text.h b/src/dusk/display/text/text.h index 487e56a9..d2a43208 100644 --- a/src/dusk/display/text/text.h +++ b/src/dusk/display/text/text.h @@ -44,7 +44,9 @@ errorret_t textDrawChar( const float_t x, const float_t y, const char_t c, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const tileset_t *tileset, texture_t *texture ); @@ -64,7 +66,9 @@ errorret_t textDraw( const float_t x, const float_t y, const char_t *text, - const color_t color, + #if MESH_ENABLE_COLOR + const color_t color, + #endif const tileset_t *tileset, texture_t *texture ); diff --git a/src/dusk/engine/engine.c b/src/dusk/engine/engine.c index 8c2d0ec0..75a39f8c 100644 --- a/src/dusk/engine/engine.c +++ b/src/dusk/engine/engine.c @@ -52,22 +52,24 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { // FOF entityid_t cam = entityManagerAdd(); componentid_t camPos = entityAddComponent(cam, COMPONENT_TYPE_POSITION); + float_t distance = 200.0f; + float_t up = 50.0f; entityPositionLookAt( cam, camPos, - (vec3){ 0.0f, 20.0f, 0.0f }, + (vec3){ 0.0f, up, 0.0f }, (vec3){ 0.0f, 1.0f, 0.0f }, - (vec3){ 50.0f, 70.0f, 50.0f } + (vec3){ distance, distance + up, distance } ); componentid_t camCam = entityAddComponent(cam, COMPONENT_TYPE_CAMERA); - entityCameraSetZFar(cam, camCam, 500.0f); + entityCameraSetZFar(cam, camCam, distance * 5.0f); ent1 = entityManagerAdd(); ent1Pos = entityAddComponent(ent1, COMPONENT_TYPE_POSITION); ent1Mesh = entityAddComponent(ent1, COMPONENT_TYPE_MESH); ent1Mat = entityAddComponent(ent1, COMPONENT_TYPE_MATERIAL); - errorChain(assetMeshLoad("test/RosaTh.stl", &loadedMesh, &loadedVertices)); + errorChain(assetMeshLoad("test/test.stl", &loadedMesh, &loadedVertices)); entityMeshSetMesh(ent1, ent1Mesh, &loadedMesh); shadermaterial_t *mat = entityMaterialGetShaderMaterial(ent1, ent1Mat); diff --git a/src/dusk/script/module/display/modulespritebatch.c b/src/dusk/script/module/display/modulespritebatch.c index 3daa7aed..c042c1fd 100644 --- a/src/dusk/script/module/display/modulespritebatch.c +++ b/src/dusk/script/module/display/modulespritebatch.c @@ -84,7 +84,9 @@ int moduleSpriteBatchPush(lua_State *L) { minY, maxX, maxY, - color == NULL ? COLOR_WHITE : *color, + #if MESH_ENABLE_COLOR + color == NULL ? COLOR_WHITE : *color, + #endif u0, v0, u1, diff --git a/src/dusk/script/module/display/moduletext.c b/src/dusk/script/module/display/moduletext.c index de18aecc..e20cd739 100644 --- a/src/dusk/script/module/display/moduletext.c +++ b/src/dusk/script/module/display/moduletext.c @@ -52,7 +52,9 @@ int moduleTextDraw(lua_State *L) { x, y, text, - color == NULL ? COLOR_WHITE : *color, + #if MESH_ENABLE_COLOR + color == NULL ? COLOR_WHITE : *color, + #endif &DEFAULT_FONT_TILESET, &DEFAULT_FONT_TEXTURE ); diff --git a/src/dusk/util/memory.c b/src/dusk/util/memory.c index ff69eb79..f1426e84 100644 --- a/src/dusk/util/memory.c +++ b/src/dusk/util/memory.c @@ -8,12 +8,19 @@ #include "memory.h" #include "assert/assert.h" #include "util/math.h" +#include "log/log.h" size_t memoryGetAllocatedCount(void) { return MEMORY_POINTERS_IN_USE; } void * memoryAllocate(const size_t size) { + logDebug( + "Attempt to allocate %u bytes (%.2fKB) of memory\n", + size, + size / 1024.0f + ); + assertTrue(size > 0, "Cannot allocate 0 bytes of memory."); void *ptr = malloc(size); assertNotNull(ptr, "Memory allocation failed."); diff --git a/src/duskgl/display/mesh/meshgl.c b/src/duskgl/display/mesh/meshgl.c index df137a94..42e8bba2 100644 --- a/src/duskgl/display/mesh/meshgl.c +++ b/src/duskgl/display/mesh/meshgl.c @@ -26,8 +26,11 @@ errorret_t meshInitGL( #ifdef DUSK_OPENGL_LEGACY // Nothing needed. - glEnableClientState(GL_COLOR_ARRAY); - errorChain(errorGLCheck()); + #if MESH_ENABLE_COLOR + glEnableClientState(GL_COLOR_ARRAY); + errorChain(errorGLCheck()); + #endif + glEnableClientState(GL_TEXTURE_COORD_ARRAY); errorChain(errorGLCheck()); glEnableClientState(GL_VERTEX_ARRAY); @@ -79,17 +82,19 @@ errorret_t meshInitGL( glEnableVertexAttribArray(1); errorChain(errorGLCheck()); - glVertexAttribPointer( - 2, - sizeof(color_t) / sizeof(GLubyte), - GL_UNSIGNED_BYTE, - GL_TRUE, - sizeof(meshvertex_t), - (const GLvoid*)offsetof(meshvertex_t, color) - ); - errorChain(errorGLCheck()); - glEnableVertexAttribArray(2); - errorChain(errorGLCheck()); + #if MESH_ENABLE_COLOR + glVertexAttribPointer( + 2, + sizeof(color_t) / sizeof(GLubyte), + GL_UNSIGNED_BYTE, + GL_TRUE, + sizeof(meshvertex_t), + (const GLvoid*)offsetof(meshvertex_t, color) + ); + errorChain(errorGLCheck()); + glEnableVertexAttribArray(2); + errorChain(errorGLCheck()); + #endif // Unbind VAO and VBO to prevent accidental modification glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -133,18 +138,22 @@ errorret_t meshDrawGL( // Legacy pointer style rendering const GLsizei stride = sizeof(meshvertex_t); - glColorPointer( - sizeof(color4b_t), - GL_UNSIGNED_BYTE, - stride, - (const GLvoid*)&mesh->vertices[offset].color - ); + #if MESH_ENABLE_COLOR + glColorPointer( + sizeof(color4b_t), + GL_UNSIGNED_BYTE, + stride, + (const GLvoid*)&mesh->vertices[offset].color + ); + #endif + glTexCoordPointer( MESH_VERTEX_UV_SIZE, GL_FLOAT, stride, (const GLvoid*)&mesh->vertices[offset].uv[0] ); + glVertexPointer( MESH_VERTEX_POS_SIZE, GL_FLOAT, diff --git a/src/duskgl/display/shader/shaderunlitgl.c b/src/duskgl/display/shader/shaderunlitgl.c index 18c4742d..f2e3f544 100644 --- a/src/duskgl/display/shader/shaderunlitgl.c +++ b/src/duskgl/display/shader/shaderunlitgl.c @@ -90,7 +90,9 @@ // Attributes "layout(location = 0) in vec3 a_Pos;\n" "layout(location = 1) in vec2 a_TexCoord;\n" - "layout(location = 2) in vec4 a_Color;\n" + #if MESH_ENABLE_COLOR + "layout(location = 2) in vec4 a_Color;\n" + #endif // Uniforms "uniform mat4 u_Proj;\n" "uniform mat4 u_View;\n" @@ -100,7 +102,11 @@ "out vec2 v_TexCoord;\n" "void main() {\n" " gl_Position = u_Proj * u_View * u_Model * vec4(a_Pos, 1.0);\n" + #if MESH_ENABLE_COLOR " v_Color = a_Color;\n" + #else + " v_Color = vec4(1.0);\n" + #endif " v_TexCoord = a_TexCoord;\n" "}\n", #else @@ -108,7 +114,9 @@ // Attributes "layout(location = 0) in vec3 a_Pos;\n" "layout(location = 1) in vec2 a_TexCoord;\n" - "layout(location = 2) in vec4 a_Color;\n" + #if MESH_ENABLE_COLOR + "layout(location = 2) in vec4 a_Color;\n" + #endif // Uniforms "uniform mat4 u_Proj;\n" "uniform mat4 u_View;\n" @@ -118,7 +126,11 @@ "out vec2 v_TexCoord;\n" "void main() {\n" " gl_Position = u_Proj * u_View * u_Model * vec4(a_Pos, 1.0);\n" - " v_Color = a_Color;\n" + #if MESH_ENABLE_COLOR + " v_Color = a_Color;\n" + #else + " v_Color = vec4(1.0);\n" + #endif " v_TexCoord = a_TexCoord;\n" "}\n", #endif