Files
dusk/src/duskdolphin/display/shader/shaderdolphin.h

113 lines
2.6 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 struct {
mat4 view;
mat4 proj;
mat4 model;
bool_t isProjectionPerspective;
Mtx44 matrixProjection;
Mtx matrixView;
Mtx matrixModel;
Mtx matrixModelView;
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)
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
);
/**
* 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);