134 lines
3.2 KiB
C
134 lines
3.2 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#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;
|
|
mat4 modelView;
|
|
|
|
Mtx dolphinProj;
|
|
Mtx dolphinModelView;
|
|
|
|
bool_t isProjectionPerspective;
|
|
uint_fast8_t dirtyMatrix;
|
|
} shaderdolphin_t;
|
|
|
|
#define SHADER_DOLPHIN_DIRTY_MODEL (1 << 0)
|
|
#define SHADER_DOLPHIN_DIRTY_PROJ (1 << 1)
|
|
#define SHADER_DOLPHIN_DIRTY_VIEW (1 << 2)
|
|
|
|
extern shaderdolphin_t *SHADER_BOUND;
|
|
|
|
/**
|
|
* Initializes a dolphin shader. Basically a render parameter pipeline.
|
|
*
|
|
* @param shader Shader to initialize.
|
|
* @param def Definition of the shader to initialize with.
|
|
* @return Error code if failure.
|
|
*/
|
|
errorret_t shaderInitDolphin(
|
|
shaderdolphin_t *shader,
|
|
const shaderdefinitiondolphin_t *def
|
|
);
|
|
|
|
/**
|
|
* Binds a dolphin shader. Basically sets the render parameters for rendering.
|
|
*
|
|
* @param shader Shader to bind.
|
|
* @return Error code if failure.
|
|
*/
|
|
errorret_t shaderBindDolphin(shaderdolphin_t *shader);
|
|
|
|
/**
|
|
* Sets a matrix uniform in the dolphin shader. Basically does nothing.
|
|
*
|
|
* @param shader Shader to set the matrix in.
|
|
* @param name Name of the uniform to set.
|
|
* @param matrix Matrix to set.
|
|
* @return Error code if failure.
|
|
*/
|
|
errorret_t shaderSetMatrixDolphin(
|
|
shaderdolphin_t *shader,
|
|
const char_t *name,
|
|
mat4 matrix
|
|
);
|
|
|
|
/**
|
|
* Sets a texture uniform in the dolphin shader. Basically does nothing.
|
|
*
|
|
* @param shader Shader to set the texture in.
|
|
* @param name Name of the uniform to set.
|
|
* @param texture Texture to set.
|
|
* @return Error code if failure.
|
|
*/
|
|
errorret_t shaderSetTextureDolphin(
|
|
shaderdolphin_t *shader,
|
|
const char_t *name,
|
|
texture_t *texture
|
|
);
|
|
|
|
/**
|
|
* Sets a color uniform in the dolphin shader.
|
|
*
|
|
* @param shader Shader to set the color in.
|
|
* @param name Name of the uniform to set.
|
|
* @param color Color to set.
|
|
* @return Error code if failure.
|
|
*/
|
|
errorret_t shaderSetColorDolphin(
|
|
shaderdolphin_t *shader,
|
|
const char_t *name,
|
|
color_t color
|
|
);
|
|
|
|
/**
|
|
* Disposes a dolphin shader. Basically does nothing.
|
|
*
|
|
* @param shader Shader to dispose.
|
|
* @return Error code if failure.
|
|
*/
|
|
errorret_t shaderDisposeDolphin(shaderdolphin_t *shader);
|
|
|
|
/**
|
|
* Internal Dolphin method, called right before a draw call to perform a matrix
|
|
* update and recalc.
|
|
*
|
|
* @return Error code if failure.
|
|
*/
|
|
errorret_t shaderUpdateMVPDolphin();
|
|
|
|
/**
|
|
* Converts a glm style column major mat4 to a GX compatible row major Mtx44.
|
|
*
|
|
* @param in Matrix to convert.
|
|
* @param out Output converted matrix.
|
|
*/
|
|
void shaderMat4ToMtx44(const mat4 in, Mtx44 out);
|
|
|
|
/**
|
|
* Converts a glm style column major mat4 to a GX compatible row major Mtx.
|
|
*
|
|
* @param inGlmMatrix Matrix to convert.
|
|
* @param outGXMatrix Output converted matrix.
|
|
*/
|
|
void shaderMat4ToMtx(const mat4 inGlmMatrix, Mtx outGXMatrix); |