Dolphin shader handler

This commit is contained in:
2026-04-10 18:34:58 -05:00
parent 673d8e0a18
commit d16ea13c14
5 changed files with 50 additions and 20 deletions
+19
View File
@@ -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));
@@ -58,6 +67,10 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
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(
mesh,
@@ -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.
@@ -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(
+16 -12
View File
@@ -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_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();
}
+12 -4
View File
@@ -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)
@@ -8,6 +8,5 @@
#include "display/shader/shaderunlit.h"
shaderdefinition_t SHADER_UNLIT_DEFINITION = {
.platform = { 0 },
.upload = shaderUnlitUpload
.setMaterial = shaderUnlitSetMaterial
};