diff --git a/src/dusk/engine/engine.c b/src/dusk/engine/engine.c index c1e8f74a..b9c9f2b7 100644 --- a/src/dusk/engine/engine.c +++ b/src/dusk/engine/engine.c @@ -22,6 +22,15 @@ #include "display/mesh/cube.h" engine_t ENGINE; +texture_t TEXTURE; +#pragma pack(push, 1) +color_t TEXTURE_COLORS[] = { + COLOR_RED, COLOR_GREEN, COLOR_MAGENTA, COLOR_CYAN, + COLOR_BLUE, COLOR_WHITE, COLOR_YELLOW, COLOR_BLACK, + COLOR_CYAN, COLOR_MAGENTA, COLOR_GREEN, COLOR_RED, + COLOR_WHITE, COLOR_BLUE, COLOR_BLACK, COLOR_YELLOW +}; +#pragma pack(pop) errorret_t engineInit(const int32_t argc, const char_t **argv) { memoryZero(&ENGINE, sizeof(engine_t)); @@ -57,6 +66,10 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { componentid_t ent1Pos = entityAddComponent(ent1, COMPONENT_TYPE_POSITION); componentid_t ent1Mesh = entityAddComponent(ent1, COMPONENT_TYPE_MESH); componentid_t ent1Mat = entityAddComponent(ent1, COMPONENT_TYPE_MATERIAL); + + textureInit(&TEXTURE, 4, 4, TEXTURE_FORMAT_RGBA, (texturedata_t){ + .rgbaColors = TEXTURE_COLORS + }); mesh_t *mesh = entityMeshGetMesh(ent1, ent1Mesh); errorChain(meshInit( @@ -65,6 +78,12 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { CUBE_VERTEX_COUNT, CUBE_MESH_SIMPLE_VERTICES )); + + shadermaterial_t *mat = entityMaterialGetShaderMaterial(ent1, ent1Mat); + // mat->unlit.color = COLOR_WHITE; + mat->unlit.color = COLOR_RED; + mat->unlit.texture = &TEXTURE; + // EOF // Run the init script. diff --git a/src/dusk/entity/component/display/entitymaterial.c b/src/dusk/entity/component/display/entitymaterial.c index 692b406d..5aa7d9a0 100644 --- a/src/dusk/entity/component/display/entitymaterial.c +++ b/src/dusk/entity/component/display/entitymaterial.c @@ -16,7 +16,7 @@ void entityMaterialInit( entityId, componentId, COMPONENT_TYPE_MATERIAL ); mat->shader = &SHADER_UNLIT; - mat->material.unlit.color = COLOR_MAGENTA; + mat->material.unlit.color = COLOR_WHITE; } shadermaterial_t * entityMaterialGetShaderMaterial( diff --git a/src/duskdolphin/display/shader/shaderdolphin.c b/src/duskdolphin/display/shader/shaderdolphin.c index 8ed06f04..e1142a10 100644 --- a/src/duskdolphin/display/shader/shaderdolphin.c +++ b/src/duskdolphin/display/shader/shaderdolphin.c @@ -22,6 +22,8 @@ errorret_t shaderInitDolphin( memoryZero(shader, sizeof(shaderdolphin_t)); + shader->definition = def; + glm_mat4_identity(shader->view); glm_mat4_identity(shader->proj); glm_mat4_identity(shader->model); @@ -87,22 +89,19 @@ errorret_t shaderSetTextureDolphin( assertStrLenMin(name, 1, "Uniform name cannot be empty"); if(texture == NULL) { - // GX_SetNumChans(0); GX_SetNumChans(1); GX_SetChanCtrl( GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, - GX_SRC_VTX, + GX_SRC_REG, GX_LIGHTNULL, GX_DF_NONE, GX_AF_NONE ); - GX_SetChanAmbColor(GX_COLOR0A0, (GXColor){ 0, 0, 0, 0 }); - GX_SetChanMatColor(GX_COLOR0A0, (GXColor){ 255, 255, 255, 255 }); + GX_SetChanAmbColor(GX_COLOR0A0, (GXColor){0,0,0,0}); GX_SetNumTexGens(0); - GX_SetNumTevStages(1); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); @@ -117,13 +116,13 @@ errorret_t shaderSetTextureDolphin( GX_LoadTexObj(&texture->texObj, GX_TEXMAP0); GX_SetNumChans(1); GX_SetChanCtrl( - GX_COLOR0A0,// Store in color channel 0 - GX_DISABLE,// Lighting disabled - GX_SRC_REG,// Ambient color? - GX_SRC_VTX,// Material color? - GX_LIGHTNULL,// Light Mask - GX_DF_NONE,// Diffuse function - GX_AF_NONE// Attenuation function + GX_COLOR0A0, + GX_DISABLE, + GX_SRC_REG, + GX_SRC_REG, + GX_LIGHTNULL, + GX_DF_NONE, + GX_AF_NONE ); // One set of UVs @@ -168,7 +167,12 @@ errorret_t shaderSetColorDolphin( assertNotNull(name, "Uniform name must not be null"); assertStrLenMin(name, 1, "Uniform name cannot be empty"); - GX_SetChanMatColor(GX_COLOR0A0, (GXColor){ color.r, color.g, color.b, color.a }); + GX_SetChanMatColor(GX_COLOR0A0, (GXColor){ + color.r, + color.g, + color.b, + color.a + }); errorOk(); } diff --git a/src/duskdolphin/display/shader/shaderdolphin.h b/src/duskdolphin/display/shader/shaderdolphin.h index dd97dcb1..69b3f58a 100644 --- a/src/duskdolphin/display/shader/shaderdolphin.h +++ b/src/duskdolphin/display/shader/shaderdolphin.h @@ -8,7 +8,19 @@ #pragma once #include "display/texture/texture.h" +typedef union shadermaterial_u shadermaterial_t; +typedef struct shaderdolphin_s shaderdolphin_t; + typedef struct { + errorret_t (*setMaterial)( + shaderdolphin_t *shader, + const shadermaterial_t *material + ); +} shaderdefinitiondolphin_t; + +typedef struct shaderdolphin_s { + shaderdefinitiondolphin_t *definition; + mat4 view; mat4 proj; mat4 model; @@ -22,10 +34,6 @@ typedef struct { uint_fast8_t dirtyMatrix; } shaderdolphin_t; -typedef struct { - void *empty; -} shaderdefinitiondolphin_t; - #define SHADER_DOLPHIN_DIRTY_MODEL (1 << 0) #define SHADER_DOLPHIN_DIRTY_PROJ (1 << 1) #define SHADER_DOLPHIN_DIRTY_VIEW (1 << 2) diff --git a/src/duskdolphin/display/shader/shaderunlitdolphin.c b/src/duskdolphin/display/shader/shaderunlitdolphin.c index 02d43783..c0e854ac 100644 --- a/src/duskdolphin/display/shader/shaderunlitdolphin.c +++ b/src/duskdolphin/display/shader/shaderunlitdolphin.c @@ -8,6 +8,5 @@ #include "display/shader/shaderunlit.h" shaderdefinition_t SHADER_UNLIT_DEFINITION = { - .platform = { 0 }, - .upload = shaderUnlitUpload + .setMaterial = shaderUnlitSetMaterial }; \ No newline at end of file