Final commit pre C++
This commit is contained in:
@ -46,9 +46,7 @@ renderpass_t * renderListRenderPass(
|
|||||||
return renderPass;
|
return renderPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderListRender(
|
void renderListRender(renderlist_t *list, shader_t *shader) {
|
||||||
renderlist_t *list, shader_t *shader, shaderuniform_t *uniforms
|
|
||||||
) {
|
|
||||||
camera_t camera;
|
camera_t camera;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
renderpass_t *pass;
|
renderpass_t *pass;
|
||||||
@ -62,13 +60,13 @@ void renderListRender(
|
|||||||
|
|
||||||
// Set the shader
|
// Set the shader
|
||||||
shaderUse(shader);
|
shaderUse(shader);
|
||||||
shaderUseCamera(shader, uniforms[0], uniforms[1], &camera);
|
shaderUseCamera(shader, &camera);
|
||||||
shaderUsePosition(shader, uniforms[2], 0,0,0, 0,0,0);
|
shaderUsePosition(shader, 0,0,0, 0,0,0);
|
||||||
|
|
||||||
// Render each pass.
|
// Render each pass.
|
||||||
for(i = 0; i < list->passCount; i++) {
|
for(i = 0; i < list->passCount; i++) {
|
||||||
pass = renderListGetPass(list, i);
|
pass = renderListGetPass(list, i);
|
||||||
shaderUseTexture(shader, uniforms[3+i], &pass->frame.texture);
|
shaderUseTexture(shader, &pass->frame.texture);
|
||||||
primitiveDraw(&list->quad, 0, -1);
|
primitiveDraw(&list->quad, 0, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,9 +86,9 @@ void renderListAsBackbuffer(
|
|||||||
|
|
||||||
// Set up the shader.
|
// Set up the shader.
|
||||||
shaderUse(shader);
|
shaderUse(shader);
|
||||||
shaderUseCamera(shader, uniforms[0], uniforms[1], &camera);
|
shaderUseCamera(shader, &camera);
|
||||||
shaderUsePosition(shader, uniforms[2], 0,0,0, 0,0,0);
|
shaderUsePosition(shader, 0,0,0, 0,0,0);
|
||||||
shaderUseTexture(shader, uniforms[3], &list->frame.texture);
|
shaderUseTexture(shader, &list->frame.texture);
|
||||||
|
|
||||||
// Render the quad to the back buffer.
|
// Render the quad to the back buffer.
|
||||||
primitiveDraw(&list->quad, 0, -1);
|
primitiveDraw(&list->quad, 0, -1);
|
||||||
|
@ -10,11 +10,9 @@
|
|||||||
void shaderInit(shader_t *shader,
|
void shaderInit(shader_t *shader,
|
||||||
char *vertexShaderSource, char* fragmentShaderSource
|
char *vertexShaderSource, char* fragmentShaderSource
|
||||||
) {
|
) {
|
||||||
int32_t isSuccess, maxLength, i, texture;
|
int isSuccess, maxLength;
|
||||||
char *error;
|
char *error;
|
||||||
GLuint shaderVertex, shaderFragment, shaderProgram;
|
GLuint shaderVertex, shaderFragment, shaderProgram;
|
||||||
GLint size; // size of the variable
|
|
||||||
GLsizei length; // name length
|
|
||||||
|
|
||||||
GLchar const* filesVertex[] = { vertexShaderSource };
|
GLchar const* filesVertex[] = { vertexShaderSource };
|
||||||
GLchar const* filesFragment[] = { fragmentShaderSource };
|
GLchar const* filesFragment[] = { fragmentShaderSource };
|
||||||
@ -68,49 +66,24 @@ void shaderInit(shader_t *shader,
|
|||||||
glDeleteShader(shaderFragment);
|
glDeleteShader(shaderFragment);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everything is okay, let's create the encapsulated shader.
|
// Everything is okay, let's create the encapsulated shader.
|
||||||
shader->shaderVertex = shaderVertex;
|
shader->shaderVertex = shaderVertex;
|
||||||
shader->shaderFrag = shaderFragment;
|
shader->shaderFrag = shaderFragment;
|
||||||
shader->shaderProgram = shaderProgram;
|
shader->shaderProgram = shaderProgram;
|
||||||
|
|
||||||
// Extract uniforms
|
shader->uniProj = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_PROJ);
|
||||||
glGetProgramiv(shaderProgram, GL_ACTIVE_UNIFORMS, &shader->uniformCount);
|
shader->uniView = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_VIEW);
|
||||||
|
shader->uniText = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_TEXT);
|
||||||
texture = 0;
|
shader->uniModl = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_MODL);
|
||||||
for(i = 0; i < shader->uniformCount; i++) {
|
shader->uniColr = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_COLR);
|
||||||
shader->uniformNames[i] = (
|
|
||||||
shader->uniformBuffer + (i * SHADER_UNIFORM_NAME_MAX)
|
|
||||||
);
|
|
||||||
|
|
||||||
glGetActiveUniform(
|
|
||||||
shaderProgram, (GLuint)i, SHADER_UNIFORM_NAME_MAX,
|
|
||||||
&length, &size, shader->types + i, shader->uniformNames[i]
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO: Reset uniforms to zero.
|
|
||||||
if(shader->types[i] == GL_SAMPLER_2D) shader->textureSlots[i] = texture++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind the shader
|
// Bind the shader
|
||||||
shaderUse(shader);
|
shaderUse(shader);
|
||||||
}
|
|
||||||
|
|
||||||
shaderuniform_t shaderGetUniform(shader_t *shader, char *name) {
|
// Reset position
|
||||||
int32_t i;
|
shaderUsePosition(shader, 0, 0, 0, 0, 0, 0);
|
||||||
for(i = 0; i < shader->uniformCount; i++) {
|
shaderUseColor(shader, PIXEL_COLOR_WHITE);
|
||||||
if(strcmp(shader->uniformNames[i], name) == 0) return i;
|
|
||||||
}
|
|
||||||
return (shaderuniform_t)0xFFFFFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
void shaderGetUniformArray(
|
|
||||||
shader_t *shader, shaderuniform_t *uniformSet,
|
|
||||||
char **uniforms, int32_t uniformCount
|
|
||||||
) {
|
|
||||||
int32_t i;
|
|
||||||
for(i = 0; i < uniformCount; i++) {
|
|
||||||
uniformSet[i] = shaderGetUniform(shader, uniforms[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderDispose(shader_t *shader) {
|
void shaderDispose(shader_t *shader) {
|
||||||
@ -123,33 +96,23 @@ void shaderUse(shader_t *shader) {
|
|||||||
glUseProgram(shader->shaderProgram);
|
glUseProgram(shader->shaderProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderUseTexture(
|
void shaderUseCamera(shader_t *shader, camera_t *camera) {
|
||||||
shader_t *shader, shaderuniform_t uniform, texture_t *texture
|
shaderUseMatrix(shader, shader->uniView, &camera->view);
|
||||||
) {
|
shaderUseMatrix(shader, shader->uniProj, &camera->projection);
|
||||||
int32_t i = shader->textureSlots[(int32_t)uniform];
|
|
||||||
// TODO: I need to be able to get the texture ID
|
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
|
||||||
glUniform1i(uniform, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderUseMatrix(
|
void shaderUseTexture(shader_t *shader, texture_t *texture) {
|
||||||
shader_t *shader, shaderuniform_t uniform, matrix_t *matrix
|
// OpenGL requires us to set the active texure.
|
||||||
) {
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||||
|
glUniform1i(shader->uniText, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shaderUseMatrix(shader_t *shader,shaderuniform_t uniform,matrix_t *matrix){
|
||||||
glUniformMatrix4fv(uniform, 1, GL_FALSE, matrix->internalMatrix[0]);
|
glUniformMatrix4fv(uniform, 1, GL_FALSE, matrix->internalMatrix[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderUseColor(shader_t *shader, shaderuniform_t uniform, pixel_t color) {
|
void shaderUsePosition(shader_t *shader,
|
||||||
glUniform4f(uniform,
|
|
||||||
(float)color.r / 255.0f,
|
|
||||||
(float)color.g / 255.0f,
|
|
||||||
(float)color.b / 255.0f,
|
|
||||||
(float)color.a / 255.0f
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void shaderUsePosition(
|
|
||||||
shader_t *shader, shaderuniform_t uniform,
|
|
||||||
float x, float y, float z,
|
float x, float y, float z,
|
||||||
float pitch, float yaw, float roll
|
float pitch, float yaw, float roll
|
||||||
) {
|
) {
|
||||||
@ -162,11 +125,10 @@ void shaderUsePosition(
|
|||||||
matrixRotate(&matrix, yaw, 0, 1, 0);
|
matrixRotate(&matrix, yaw, 0, 1, 0);
|
||||||
matrixRotate(&matrix, roll, 0, 0, 1);
|
matrixRotate(&matrix, roll, 0, 0, 1);
|
||||||
matrixRotate(&matrix, pitch, 1, 0, 0);
|
matrixRotate(&matrix, pitch, 1, 0, 0);
|
||||||
shaderUseMatrix(shader, uniform, &matrix);
|
shaderUseMatrix(shader, shader->uniModl, &matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderUsePositionAndScale(
|
void shaderUsePositionAndScale(shader_t *shader,
|
||||||
shader_t *shader, shaderuniform_t uniform,
|
|
||||||
float x, float y, float z,
|
float x, float y, float z,
|
||||||
float pitch, float yaw, float roll,
|
float pitch, float yaw, float roll,
|
||||||
float scaleX, float scaleY, float scaleZ
|
float scaleX, float scaleY, float scaleZ
|
||||||
@ -183,14 +145,14 @@ void shaderUsePositionAndScale(
|
|||||||
|
|
||||||
matrixScale(&matrix, scaleX, scaleY, scaleZ);
|
matrixScale(&matrix, scaleX, scaleY, scaleZ);
|
||||||
|
|
||||||
shaderUseMatrix(shader, uniform, &matrix);
|
shaderUseMatrix(shader, shader->uniModl, &matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shaderUseCamera(
|
void shaderUseColor(shader_t *shader, pixel_t color) {
|
||||||
shader_t *shader,
|
glUniform4f(shader->uniColr,
|
||||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
|
(float)color.r / 255.0f,
|
||||||
camera_t *camera
|
(float)color.g / 255.0f,
|
||||||
) {
|
(float)color.b / 255.0f,
|
||||||
shaderUseMatrix(shader, uniformView, &camera->view);
|
(float)color.a / 255.0f
|
||||||
shaderUseMatrix(shader, uniformProjection, &camera->projection);
|
);
|
||||||
}
|
}
|
@ -10,10 +10,12 @@
|
|||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "../util/array.h"
|
|
||||||
|
|
||||||
#define SHADER_UNIFORM_NAME_MAX 24
|
#define SHADER_UNI_VIEW "u_View"
|
||||||
#define SHADER_UNIFORM_COUNT 16
|
#define SHADER_UNI_PROJ "u_Proj"
|
||||||
|
#define SHADER_UNI_TEXT "u_Text"
|
||||||
|
#define SHADER_UNI_MODL "u_Model"
|
||||||
|
#define SHADER_UNI_COLR "u_Colr"
|
||||||
|
|
||||||
/** Representation of a shader uniform */
|
/** Representation of a shader uniform */
|
||||||
typedef GLuint shaderuniform_t;
|
typedef GLuint shaderuniform_t;
|
||||||
@ -24,26 +26,28 @@ typedef GLuint shaderuniform_t;
|
|||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** Pointer to an uploaded vertex shader program */
|
/** Pointer to an uploaded vertex shader program */
|
||||||
GLuint shaderVertex;
|
shaderuniform_t shaderVertex;
|
||||||
|
|
||||||
/** Pointer to an uploaded fragment shader program */
|
/** Pointer to an uploaded fragment shader program */
|
||||||
GLuint shaderFrag;
|
shaderuniform_t shaderFrag;
|
||||||
|
|
||||||
/** Pointer to an uploaded shader program linked */
|
/** Pointer to an uploaded shader program linked */
|
||||||
GLuint shaderProgram;
|
shaderuniform_t shaderProgram;
|
||||||
|
|
||||||
/** Buffer of chars where we store the uniform names */
|
/** Matrix for the view matrix */
|
||||||
char uniformBuffer[SHADER_UNIFORM_NAME_MAX * SHADER_UNIFORM_COUNT];
|
shaderuniform_t uniView;
|
||||||
|
|
||||||
/** Array of strings (pointers to the above buffer) of the uniform names */
|
/** Matrix for the projection matrix */
|
||||||
char *uniformNames[SHADER_UNIFORM_COUNT];
|
shaderuniform_t uniProj;
|
||||||
int32_t uniformCount;
|
|
||||||
|
|
||||||
/** Type of each uniform */
|
/** Uniform for the current texture */
|
||||||
GLenum types[SHADER_UNIFORM_COUNT];
|
shaderuniform_t uniText;
|
||||||
|
|
||||||
/** Texture Slots (which texture slot for GL to use for each uniform) */
|
/** Uniform for the current model world position */
|
||||||
uint8_t textureSlots[SHADER_UNIFORM_COUNT];
|
shaderuniform_t uniModl;
|
||||||
|
|
||||||
|
/** Uniform for the color multiplier */
|
||||||
|
shaderuniform_t uniColr;
|
||||||
} shader_t;
|
} shader_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,28 +60,6 @@ void shaderInit(shader_t *shader,
|
|||||||
char *vertexShaderSource, char* fragmentShaderSource
|
char *vertexShaderSource, char* fragmentShaderSource
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the shaderuniform_t for a given shader uniform name.
|
|
||||||
*
|
|
||||||
* @param shader Shader to get from
|
|
||||||
* @param name Name to look for
|
|
||||||
* @return The shader uniform, or -1 if not found.
|
|
||||||
*/
|
|
||||||
shaderuniform_t shaderGetUniform(shader_t *shader, char *name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of shaderuniform_t's into an array for a given string array.
|
|
||||||
*
|
|
||||||
* @param shader Shader to get the uniforms from.
|
|
||||||
* @param uniformSet Uniform array to get.
|
|
||||||
* @param uniforms Uniform strings to get.
|
|
||||||
* @param uniformCount Count of uniforms you're getting.
|
|
||||||
*/
|
|
||||||
void shaderGetUniformArray(
|
|
||||||
shader_t *shader, shaderuniform_t *uniformSet,
|
|
||||||
char **uniforms, int32_t uniformCount
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup and unload a previously loaded shader.
|
* Cleanup and unload a previously loaded shader.
|
||||||
* @param shader The shader to unload
|
* @param shader The shader to unload
|
||||||
@ -90,16 +72,20 @@ void shaderDispose(shader_t *shader);
|
|||||||
*/
|
*/
|
||||||
void shaderUse(shader_t *shader);
|
void shaderUse(shader_t *shader);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches a camera to the shader.
|
||||||
|
* @param shader Shader to attach to.
|
||||||
|
* @param camera Camera to attach.
|
||||||
|
*/
|
||||||
|
void shaderUseCamera(shader_t *shader, camera_t *camera);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches a texture to the shader.
|
* Attaches a texture to the shader.
|
||||||
*
|
|
||||||
* @param shader Shader to attach to.
|
* @param shader Shader to attach to.
|
||||||
* @param uniform Uniform on the shader to set.
|
|
||||||
* @param texture Texture to attach.
|
* @param texture Texture to attach.
|
||||||
*/
|
*/
|
||||||
void shaderUseTexture(
|
void shaderUseTexture(shader_t *shader, texture_t *texture);
|
||||||
shader_t *shader, shaderuniform_t uniform, texture_t *texture
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set's a specific shader uniform to a matrix.
|
* Set's a specific shader uniform to a matrix.
|
||||||
@ -108,25 +94,12 @@ void shaderUseTexture(
|
|||||||
* @param uniform Uniform on the shader to set.
|
* @param uniform Uniform on the shader to set.
|
||||||
* @param matrix Matrix to apply.
|
* @param matrix Matrix to apply.
|
||||||
*/
|
*/
|
||||||
void shaderUseMatrix(
|
void shaderUseMatrix(shader_t *shader,shaderuniform_t uniform,matrix_t *matrix);
|
||||||
shader_t *shader, shaderuniform_t uniform, matrix_t *matrix
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set's a specific shader uniform to a color.
|
|
||||||
*
|
|
||||||
* @param shader Shader to apply to.
|
|
||||||
* @param uniform Uniform on the shader to set.
|
|
||||||
* @param color Color to set on to the uniform.
|
|
||||||
*/
|
|
||||||
void shaderUseColor(shader_t *shader, shaderuniform_t uniform, pixel_t color);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set's the current translation matrix onto the shader for the next
|
* Set's the current translation matrix onto the shader for the next
|
||||||
* render to use. Rotation order is set to YZX.
|
* render to use. Rotation order is set to YZX.
|
||||||
*
|
|
||||||
* @param shader Shader to attach to.
|
* @param shader Shader to attach to.
|
||||||
* @param uniform Uniform on the shader to set.
|
|
||||||
* @param x X coordinate (world space).
|
* @param x X coordinate (world space).
|
||||||
* @param y Y coordinate (world space).
|
* @param y Y coordinate (world space).
|
||||||
* @param z Z coordinate (world space).
|
* @param z Z coordinate (world space).
|
||||||
@ -134,18 +107,17 @@ void shaderUseColor(shader_t *shader, shaderuniform_t uniform, pixel_t color);
|
|||||||
* @param yaw Yaw of the object (local space).
|
* @param yaw Yaw of the object (local space).
|
||||||
* @param roll Roll of the object (local space).
|
* @param roll Roll of the object (local space).
|
||||||
*/
|
*/
|
||||||
void shaderUsePosition(
|
void shaderUsePosition(shader_t *shader,
|
||||||
shader_t *shader, shaderuniform_t uniform,
|
|
||||||
float x, float y, float z,
|
float x, float y, float z,
|
||||||
float pitch, float yaw, float roll
|
float pitch, float yaw, float roll
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set's the current translation matrix onto the shader for the next
|
* Set's the current translation matrix onto the shader for the next
|
||||||
* render to use. Also provides scaling controls.
|
* render to use. Also provides scaling controls.
|
||||||
*
|
*
|
||||||
* @param shader Shader to attach to.
|
* @param shader Shader to attach to.
|
||||||
* @param uniform Uniform on the shader to set.
|
|
||||||
* @param x X coordinate (world space).
|
* @param x X coordinate (world space).
|
||||||
* @param y Y coordinate (world space).
|
* @param y Y coordinate (world space).
|
||||||
* @param z Z coordinate (world space).
|
* @param z Z coordinate (world space).
|
||||||
@ -156,23 +128,11 @@ void shaderUsePosition(
|
|||||||
* @param scaleY Y scale of model (1 being 100% scaled).
|
* @param scaleY Y scale of model (1 being 100% scaled).
|
||||||
* @param scaleZ Z scale of model (1 being 100% scaled).
|
* @param scaleZ Z scale of model (1 being 100% scaled).
|
||||||
*/
|
*/
|
||||||
void shaderUsePositionAndScale(
|
void shaderUsePositionAndScale(shader_t *shader,
|
||||||
shader_t *shader, shaderuniform_t uniform,
|
|
||||||
float x, float y, float z,
|
float x, float y, float z,
|
||||||
float pitch, float yaw, float roll,
|
float pitch, float yaw, float roll,
|
||||||
float scaleX, float scaleY, float scaleZ
|
float scaleX, float scaleY, float scaleZ
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Attaches a camera to the shader.
|
void shaderUseColor(shader_t *shader, pixel_t color);
|
||||||
*
|
|
||||||
* @param shader Shader to attach to.
|
|
||||||
* @param uniformView Shader Uniform for the view matrix.
|
|
||||||
* @param uniformProjection Shader Uniform for the view matrix.
|
|
||||||
* @param camera Camera to attach.
|
|
||||||
*/
|
|
||||||
void shaderUseCamera(
|
|
||||||
shader_t *shader,
|
|
||||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
|
|
||||||
camera_t *camera
|
|
||||||
);
|
|
@ -18,10 +18,11 @@ void engineInit(engine_t *engine) {
|
|||||||
|
|
||||||
clientInit(&engine->client);
|
clientInit(&engine->client);
|
||||||
epochInit(&engine->time);
|
epochInit(&engine->time);
|
||||||
renderInit();
|
saveManagerInit(&engine->save);
|
||||||
inputInit(&engine->input);
|
inputInit(&engine->input);
|
||||||
|
assetManagerInit(&engine->assetManager, &engine->save);
|
||||||
assetManagerInit(&engine->assetManager);
|
renderInit();
|
||||||
|
|
||||||
assetManagerStart(&engine->assetManager);
|
assetManagerStart(&engine->assetManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +13,7 @@
|
|||||||
#include "../epoch/epoch.h"
|
#include "../epoch/epoch.h"
|
||||||
#include "../display/render.h"
|
#include "../display/render.h"
|
||||||
#include "../file/assetmanager.h"
|
#include "../file/assetmanager.h"
|
||||||
|
#include "../save/save.h"
|
||||||
// #if !defined(GAME_NAME)
|
|
||||||
// #error You need to define the GAME_NAME string
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** Name of the game */
|
/** Name of the game */
|
||||||
@ -34,6 +31,9 @@ typedef struct {
|
|||||||
/** Input Manager for the game */
|
/** Input Manager for the game */
|
||||||
input_t input;
|
input_t input;
|
||||||
|
|
||||||
|
/** Save Manager for the game */
|
||||||
|
savemanager_t save;
|
||||||
|
|
||||||
/** Game client information */
|
/** Game client information */
|
||||||
client_t client;
|
client_t client;
|
||||||
} engine_t;
|
} engine_t;
|
||||||
|
@ -31,13 +31,14 @@ assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void assetManagerInit(assetmanager_t *manager) {
|
void assetManagerInit(assetmanager_t *manager, savemanager_t *save) {
|
||||||
threadInit(&manager->thread, &_assetManagerThread);
|
threadInit(&manager->thread, &_assetManagerThread);
|
||||||
manager->thread.user = manager;
|
manager->thread.user = manager;
|
||||||
manager->itemCount = 0;
|
manager->itemCount = 0;
|
||||||
manager->finished = false;
|
manager->finished = false;
|
||||||
manager->holderCount = 0;
|
manager->holderCount = 0;
|
||||||
manager->running = false;
|
manager->running = false;
|
||||||
|
manager->save = save;
|
||||||
}
|
}
|
||||||
|
|
||||||
float assetManagerProgressGet(assetmanager_t *manager) {
|
float assetManagerProgressGet(assetmanager_t *manager) {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "loaders/shader.h"
|
#include "loaders/shader.h"
|
||||||
#include "loaders/texture.h"
|
#include "loaders/texture.h"
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
#include "../save/save.h"
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[];
|
extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[];
|
||||||
@ -22,7 +23,7 @@ extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[];
|
|||||||
*
|
*
|
||||||
* @param manager Manager to initialize.
|
* @param manager Manager to initialize.
|
||||||
*/
|
*/
|
||||||
void assetManagerInit(assetmanager_t *manager);
|
void assetManagerInit(assetmanager_t *manager, savemanager_t *save);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the progress of the asset manager as a representation of 0-1 as a % that
|
* Gets the progress of the asset manager as a representation of 0-1 as a % that
|
||||||
|
@ -8,16 +8,21 @@
|
|||||||
#include "scaledtexture.h"
|
#include "scaledtexture.h"
|
||||||
|
|
||||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
assetmanager_t *manager, assetmanagerowner_t owner, char *path, char *file
|
||||||
char *path, char *file, uint8_t scale
|
|
||||||
) {
|
) {
|
||||||
assetmanageritem_t *item;
|
assetmanageritem_t *item;
|
||||||
texturescale_t *st;
|
texturescale_t *st;
|
||||||
|
uint8_t scale;
|
||||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||||
|
|
||||||
sprintf(buffer, "%s/%s_%u", path, file, scale);
|
// Get the scale
|
||||||
|
scale = saveManagerGetUint8(manager->save, SAVE_KEY_TEXTURE_SCALE);
|
||||||
|
|
||||||
|
// Generate a key
|
||||||
|
sprintf(buffer, "%s/%s", path, file);
|
||||||
item = assetManagerItemGet(manager, buffer);
|
item = assetManagerItemGet(manager, buffer);
|
||||||
|
|
||||||
|
// Already loaded?
|
||||||
if(item == NULL) {
|
if(item == NULL) {
|
||||||
item = assetManagerItemAdd(manager, buffer);
|
item = assetManagerItemAdd(manager, buffer);
|
||||||
item->type = ASSET_MANAGER_TYPE_SCALED_TEXTURE;
|
item->type = ASSET_MANAGER_TYPE_SCALED_TEXTURE;
|
||||||
@ -121,3 +126,51 @@ bool _assetManagerLoaderScaledTextureDispose(assetmanageritem_t *item) {
|
|||||||
textureDispose(&item->data.scaledTexture.texture);
|
textureDispose(&item->data.scaledTexture.texture);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _assetManagerLoaderScaledTextureResize(
|
||||||
|
assetmanager_t *manager, assetmanageritem_t *item, uint8_t scale
|
||||||
|
) {
|
||||||
|
// Check if we need to update
|
||||||
|
if(item->data.scaledTexture.scale == scale) return true;
|
||||||
|
|
||||||
|
// Are we in the middle of an async load? If so then we gotta do some jank
|
||||||
|
while(item->state == ASSET_MANAGER_STATE_ASYNC_LOADING) {
|
||||||
|
threadSleep(0.1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Are we async loaded but sync pending?
|
||||||
|
if(item->state == ASSET_MANAGER_STATE_ASYNC_DONE) {
|
||||||
|
// We are async done but pending sync loading. Free the texture data since
|
||||||
|
// it will be re-malloced later on.
|
||||||
|
free(item->data.scaledTexture.data);
|
||||||
|
} else if(item->state == ASSET_MANAGER_STATE_SYNC_DONE) {
|
||||||
|
// We are already loaded, free the texture
|
||||||
|
if(!_assetManagerLoaderScaledTextureDispose(item)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update scale.
|
||||||
|
item->data.scaledTexture.scale = scale;
|
||||||
|
|
||||||
|
// Immediately requeue a texture re-load
|
||||||
|
if(!_assetManagerLoaderScaledTextureAsync(item)) return false;
|
||||||
|
|
||||||
|
// And regenerate the texture synchronously.
|
||||||
|
if(!_assetManagerLoaderScaledTextureSync(item)) return false;
|
||||||
|
|
||||||
|
// Finally, mark texture as loaded (since it is)
|
||||||
|
item->state = ASSET_MANAGER_STATE_SYNC_DONE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void assetManagerScaledTextureRescaleAll(assetmanager_t *manager) {
|
||||||
|
uint8_t i, scale;
|
||||||
|
|
||||||
|
// Get the new scale
|
||||||
|
scale = saveManagerGetUint8(manager->save, SAVE_KEY_TEXTURE_SCALE);
|
||||||
|
|
||||||
|
// Rescale each texture. This is, unfortunately, blocking for now.
|
||||||
|
for(i = 0; i < manager->itemCount; i++) {
|
||||||
|
if(manager->items[i].type != ASSET_MANAGER_TYPE_SCALED_TEXTURE) continue;
|
||||||
|
_assetManagerLoaderScaledTextureResize(manager, manager->items + i, scale);
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "../xml.h"
|
#include "../xml.h"
|
||||||
#include "../asset.h"
|
#include "../asset.h"
|
||||||
|
#include "../../save/save.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the given texture scale for a scaled texture.
|
* Load the given texture scale for a scaled texture.
|
||||||
@ -17,14 +18,33 @@
|
|||||||
* @param owner Owner ID requesting to load this resource.
|
* @param owner Owner ID requesting to load this resource.
|
||||||
* @param path Path of the texture size sets
|
* @param path Path of the texture size sets
|
||||||
* @param file Name of the texture that was generated.
|
* @param file Name of the texture that was generated.
|
||||||
* @param scale Scale to load.
|
|
||||||
* @return A pointer to the asset manager item for tracking.
|
* @return A pointer to the asset manager item for tracking.
|
||||||
*/
|
*/
|
||||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
assetmanager_t *manager, assetmanagerowner_t owner, char *path, char *file
|
||||||
char *path, char *file, uint8_t scale
|
|
||||||
);
|
);
|
||||||
|
|
||||||
bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item);
|
bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item);
|
||||||
bool _assetManagerLoaderScaledTextureSync(assetmanageritem_t *item);
|
bool _assetManagerLoaderScaledTextureSync(assetmanageritem_t *item);
|
||||||
bool _assetManagerLoaderScaledTextureDispose(assetmanageritem_t *item);
|
bool _assetManagerLoaderScaledTextureDispose(assetmanageritem_t *item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private method to resize a texture after it has been loaded.
|
||||||
|
*
|
||||||
|
* @param manager
|
||||||
|
* @param item
|
||||||
|
* @param scale
|
||||||
|
* @return true
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
|
bool _assetManagerLoaderScaledTextureResize(
|
||||||
|
assetmanager_t *manager, assetmanageritem_t *item, uint8_t scale
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that when called will scan the asset manager and find any scaled
|
||||||
|
* textures that need resizing, and resize them.
|
||||||
|
*
|
||||||
|
* @param manager Manager to check against.
|
||||||
|
*/
|
||||||
|
void assetManagerScaledTextureRescaleAll(assetmanager_t *manager);
|
@ -8,11 +8,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
#include "../../engine/thread.h"
|
#include "../../engine/thread.h"
|
||||||
|
#include "../../save/save.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "scaledtexture.h"
|
#include "scaledtexture.h"
|
||||||
|
|
||||||
|
|
||||||
#define ASSET_MANAGER_ITEMS_MAX 64
|
#define ASSET_MANAGER_ITEMS_MAX 64
|
||||||
#define ASSET_MANAGER_ITEM_NAME_MAX 96
|
#define ASSET_MANAGER_ITEM_NAME_MAX 96
|
||||||
#define ASSET_MANAGER_HOLDERS_MAX 8
|
#define ASSET_MANAGER_HOLDERS_MAX 8
|
||||||
@ -69,6 +71,8 @@ typedef struct {
|
|||||||
// Manager
|
// Manager
|
||||||
typedef struct {
|
typedef struct {
|
||||||
thread_t thread;
|
thread_t thread;
|
||||||
|
savemanager_t *save;
|
||||||
|
|
||||||
bool finished;
|
bool finished;
|
||||||
bool running;
|
bool running;
|
||||||
|
|
||||||
|
@ -11,13 +11,44 @@ bool gameInit(game_t *game) {
|
|||||||
// Init the engine and the rendering pipeline
|
// Init the engine and the rendering pipeline
|
||||||
engineInit(&game->engine);
|
engineInit(&game->engine);
|
||||||
|
|
||||||
|
cameraLookAt(&game->camera, 3,3,3, 0,0,0);
|
||||||
|
cameraPerspective(&game->camera, 45.0f, 16.0f/9.0f, 0.001f, 1000.0f);
|
||||||
|
quadInit(&game->quad, 0.0f, 0.0f,0.0f,0.0f,0.0f, 1.0f,1.0f,1.0f,1.0f);
|
||||||
|
|
||||||
|
shaderInit(&game->shader,
|
||||||
|
assetStringLoad("shaders/textured.vert"),
|
||||||
|
assetStringLoad("shaders/textured.frag")
|
||||||
|
);
|
||||||
|
|
||||||
|
game->owner = assetManagerHolderCreate(&game->engine.assetManager);
|
||||||
|
game->item = assetManagerLoadScaledTexture(
|
||||||
|
&game->engine.assetManager, game->owner, "textures", "test_texture"
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool doneResize = false;
|
||||||
|
|
||||||
bool gameUpdate(game_t *game, float delta) {
|
bool gameUpdate(game_t *game, float delta) {
|
||||||
// Let the engine do its thing.
|
// Let the engine do its thing.
|
||||||
engineUpdateStart(&game->engine, delta);
|
engineUpdateStart(&game->engine, delta);
|
||||||
|
|
||||||
|
if(game->engine.time.current > 4.0f && !doneResize) {
|
||||||
|
printf("Resizing");
|
||||||
|
// saveManagerSetUint8(&game->engine.save, SAVE_KEY_TEXTURE_SCALE, 0x03);
|
||||||
|
// assetManagerScaledTextureRescaleAll(&game->engine.assetManager);
|
||||||
|
doneResize = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(game->item->state == ASSET_MANAGER_STATE_SYNC_DONE) {
|
||||||
|
shaderUse(&game->shader);
|
||||||
|
shaderUseCamera(&game->shader, &game->camera);
|
||||||
|
shaderUsePosition(&game->shader, 0,0,0, 0,0,0);
|
||||||
|
shaderUseTexture(&game->shader, &game->item->data.scaledTexture.texture);
|
||||||
|
primitiveDraw(&game->quad, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Hand back to the engine.
|
// Hand back to the engine.
|
||||||
return engineUpdateEnd(&game->engine);
|
return engineUpdateEnd(&game->engine);
|
||||||
|
@ -8,9 +8,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
#include "../../engine/engine.h"
|
#include "../../engine/engine.h"
|
||||||
|
#include "../../display/primitive/primitive.h"
|
||||||
|
#include "../../display/primitive/quad.h"
|
||||||
|
#include "../../display/primitive/cube.h"
|
||||||
|
#include "../../display/shader.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
engine_t engine;
|
engine_t engine;
|
||||||
|
camera_t camera;
|
||||||
|
shader_t shader;
|
||||||
|
primitive_t quad;
|
||||||
|
assetmanagerowner_t owner;
|
||||||
|
assetmanageritem_t *item;
|
||||||
} game_t;
|
} game_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,13 +9,15 @@
|
|||||||
|
|
||||||
void saveManagerInit(savemanager_t *man) {
|
void saveManagerInit(savemanager_t *man) {
|
||||||
man->count = 0;
|
man->count = 0;
|
||||||
|
|
||||||
|
// Set up defaults
|
||||||
|
saveManagerSetUint8(man, SAVE_KEY_TEXTURE_SCALE, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
savevalue_t * saveManagerAddOrGet(savemanager_t *man, char *key) {
|
savevalue_t * saveManagerAddOrGet(savemanager_t *man, char *key) {
|
||||||
uint8_t i, j;
|
uint8_t i, j;
|
||||||
|
|
||||||
j = saveManagerGetKey(man, key);
|
j = saveManagerGetKey(man, key);
|
||||||
|
|
||||||
if(j != 0xFF) return man->values + j;
|
if(j != 0xFF) return man->values + j;
|
||||||
|
|
||||||
// Find empty key
|
// Find empty key
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#define SAVE_VALUES_MAX 200
|
#define SAVE_VALUES_MAX 200
|
||||||
|
|
||||||
|
#define SAVE_KEY_TEXTURE_SCALE "TEXTURE_SCALE"
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
// char *s;
|
// char *s;
|
||||||
bool b;
|
bool b;
|
||||||
|
@ -14,13 +14,9 @@ void sceneInit(scene_t *scene, engine_t *engine, void *user) {
|
|||||||
scene->onLoaded = NULL;
|
scene->onLoaded = NULL;
|
||||||
scene->onRender = NULL;
|
scene->onRender = NULL;
|
||||||
scene->loaded = false;
|
scene->loaded = false;
|
||||||
renderListInit(&scene->renderList, (int32_t)1, (int32_t)1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float sceneUpdate(
|
float sceneUpdate(scene_t *scene) {
|
||||||
scene_t *scene, int32_t width, int32_t height, shader_t *shader,
|
|
||||||
shaderuniform_t *uniforms
|
|
||||||
) {
|
|
||||||
// First, lets check how loading has been going
|
// First, lets check how loading has been going
|
||||||
float n = assetManagerProgressGetForHolder(
|
float n = assetManagerProgressGetForHolder(
|
||||||
&scene->engine->assetManager, scene->assetOwner
|
&scene->engine->assetManager, scene->assetOwner
|
||||||
@ -35,38 +31,12 @@ float sceneUpdate(
|
|||||||
if(scene->onLoaded != NULL) scene->onLoaded(scene);
|
if(scene->onLoaded != NULL) scene->onLoaded(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize the render list
|
|
||||||
renderListResize(&scene->renderList, width, height);
|
|
||||||
|
|
||||||
// Fire callback
|
// Fire callback
|
||||||
if(scene->onRender != NULL) scene->onRender(scene);
|
if(scene->onRender != NULL) scene->onRender(scene);
|
||||||
|
|
||||||
// Render the render list itself.
|
|
||||||
renderListRender(&scene->renderList, shader, uniforms);
|
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sceneUpdateToBackbuffer(scene_t *scene,
|
|
||||||
shader_t *shaderRenderList, shaderuniform_t *listUniforms,
|
|
||||||
shader_t *shaderBackBuffer, shaderuniform_t *backUniforms
|
|
||||||
) {
|
|
||||||
float n = sceneUpdate(scene,
|
|
||||||
(int32_t)scene->engine->render.width, (int32_t)scene->engine->render.height,
|
|
||||||
shaderRenderList, listUniforms
|
|
||||||
);
|
|
||||||
if(n < 1.0f) return;
|
|
||||||
|
|
||||||
renderListAsBackbuffer(&scene->renderList, scene->engine, shaderBackBuffer,
|
|
||||||
backUniforms
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sceneDispose(scene_t *scene) {
|
void sceneDispose(scene_t *scene) {
|
||||||
assetManagerHolderRelease(&scene->engine->assetManager, scene->assetOwner);
|
assetManagerHolderRelease(&scene->engine->assetManager, scene->assetOwner);
|
||||||
renderListDispose(&scene->renderList);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderpass_t * sceneUsePass(scene_t *scene, uint8_t i) {
|
|
||||||
return renderListRenderPass(&scene->renderList, scene->engine, i);
|
|
||||||
}
|
}
|
@ -22,9 +22,9 @@ typedef void scenecallback_t(scene_t *scene);
|
|||||||
typedef struct _scene_t {
|
typedef struct _scene_t {
|
||||||
engine_t *engine;
|
engine_t *engine;
|
||||||
assetmanagerowner_t assetOwner;
|
assetmanagerowner_t assetOwner;
|
||||||
renderlist_t renderList;
|
|
||||||
void *user;
|
void *user;
|
||||||
|
|
||||||
|
/** Whether or not the assets that this scene depends upon have loaded */
|
||||||
bool loaded;
|
bool loaded;
|
||||||
|
|
||||||
/** Scene Callbacks */
|
/** Scene Callbacks */
|
||||||
@ -34,17 +34,6 @@ typedef struct _scene_t {
|
|||||||
|
|
||||||
void sceneInit(scene_t *scene, engine_t *engine, void *user);
|
void sceneInit(scene_t *scene, engine_t *engine, void *user);
|
||||||
|
|
||||||
|
float sceneUpdate(scene_t *scene);
|
||||||
|
|
||||||
float sceneUpdate(
|
void sceneDispose(scene_t *scene);
|
||||||
scene_t *scene, int32_t width, int32_t height, shader_t *shader,
|
|
||||||
shaderuniform_t *uniforms
|
|
||||||
);
|
|
||||||
|
|
||||||
void sceneUpdateToBackbuffer(scene_t *scene,
|
|
||||||
shader_t *shaderRenderList, shaderuniform_t *listUniforms,
|
|
||||||
shader_t *shaderBackBuffer, shaderuniform_t *backUniforms
|
|
||||||
);
|
|
||||||
|
|
||||||
void sceneDispose(scene_t *scene);
|
|
||||||
|
|
||||||
renderpass_t * sceneUsePass(scene_t *scene, uint8_t i);
|
|
@ -100,14 +100,10 @@ void frameSetInnerSize(frame_t *frame, float width, float height) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void frameRender(
|
void frameRender(frame_t *frame, shader_t *shader, float x, float y) {
|
||||||
frame_t *frame, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
) {
|
|
||||||
if(frame->texture == NULL) return;
|
if(frame->texture == NULL) return;
|
||||||
shaderUsePosition(shader, uniformModel, x, y, 0, 0, 0, 0);
|
shaderUsePosition(shader, x, y, 0, 0, 0, 0);
|
||||||
shaderUseTexture(shader, uniformTexture, frame->texture);
|
shaderUseTexture(shader, frame->texture);
|
||||||
primitiveDraw(&frame->primitive, 0, -1);
|
primitiveDraw(&frame->primitive, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,16 +54,10 @@ void frameSetInnerSize(frame_t *frame, float width, float height);
|
|||||||
*
|
*
|
||||||
* @param frame Frame to render.
|
* @param frame Frame to render.
|
||||||
* @param shader Shader to use while rendering.
|
* @param shader Shader to use while rendering.
|
||||||
* @param uniformModel Shader uniform for the model position.
|
|
||||||
* @param uniformTexture Shader uniform for the texture.
|
|
||||||
* @param x X position.
|
* @param x X position.
|
||||||
* @param y Y position.
|
* @param y Y position.
|
||||||
*/
|
*/
|
||||||
void frameRender(
|
void frameRender(frame_t *frame, shader_t *shader, float x, float y);
|
||||||
frame_t *frame, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup a previously initialized frame.
|
* Cleanup a previously initialized frame.
|
||||||
|
@ -30,12 +30,10 @@ void framedTextMenuUpdate(framedtextmenu_t *menu, engine_t *engine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void framedTextMenuRender(
|
void framedTextMenuRender(
|
||||||
framedtextmenu_t *menu, shader_t *shader,
|
framedtextmenu_t *menu, shader_t *shader, float x, float y
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
) {
|
) {
|
||||||
frameRender(&menu->frame, shader, uniformModel, uniformTexture, x, y);
|
frameRender(&menu->frame, shader, x, y);
|
||||||
textMenuRender(&menu->menu, shader, uniformModel, uniformTexture, x, y);
|
textMenuRender(&menu->menu, shader, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void framedTextMenuDispose(framedtextmenu_t *menu) {
|
void framedTextMenuDispose(framedtextmenu_t *menu) {
|
||||||
|
@ -52,15 +52,11 @@ void framedTextMenuUpdate(framedtextmenu_t *menu, engine_t *engine);
|
|||||||
*
|
*
|
||||||
* @param menu Menu to render.
|
* @param menu Menu to render.
|
||||||
* @param shader Shader to use.
|
* @param shader Shader to use.
|
||||||
* @param uniformModel Shader uniform for the model position.
|
|
||||||
* @param uniformTexture Shader uniform for the texture.
|
|
||||||
* @param x X Position.
|
* @param x X Position.
|
||||||
* @param y Y Position.
|
* @param y Y Position.
|
||||||
*/
|
*/
|
||||||
void framedTextMenuRender(
|
void framedTextMenuRender(
|
||||||
framedtextmenu_t *menu, shader_t *shader,
|
framedtextmenu_t *menu, shader_t *shader, float x, float y
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,18 +46,14 @@ void imageSetTextureAndCrop(image_t *image, texture_t *texture,
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void imageRender(
|
void imageRender(image_t *image, shader_t *shader, float x, float y) {
|
||||||
image_t *image, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
) {
|
|
||||||
if(image->texture == NULL) return;
|
if(image->texture == NULL) return;
|
||||||
shaderUsePositionAndScale(shader, uniformModel,
|
shaderUsePositionAndScale(shader,
|
||||||
x,y,0,
|
x,y,0,
|
||||||
0,0,0,
|
0,0,0,
|
||||||
image->width, image->height, 1
|
image->width, image->height, 1
|
||||||
);
|
);
|
||||||
shaderUseTexture(shader, uniformTexture, image->texture);
|
shaderUseTexture(shader, image->texture);
|
||||||
primitiveDraw(&image->quad, 0, -1);
|
primitiveDraw(&image->quad, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,16 +53,10 @@ void imageSetTextureAndCrop(image_t *image, texture_t *texture,
|
|||||||
*
|
*
|
||||||
* @param image Image to render.
|
* @param image Image to render.
|
||||||
* @param shader Shader to use while rendering.
|
* @param shader Shader to use while rendering.
|
||||||
* @param uniformModel Shader uniform for the model position.
|
|
||||||
* @param uniformTexture Shader uniform for the texture.
|
|
||||||
* @param x X position.
|
* @param x X position.
|
||||||
* @param y Y position.
|
* @param y Y position.
|
||||||
*/
|
*/
|
||||||
void imageRender(
|
void imageRender(image_t *image, shader_t *shader, float x, float y);
|
||||||
image_t *image, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup a previously initialized image.
|
* Cleanup a previously initialized image.
|
||||||
|
@ -27,14 +27,10 @@ void labelSetText(label_t *label, font_t *font, char *text) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void labelRender(
|
void labelRender(label_t *label, shader_t *shader, float x, float y) {
|
||||||
label_t *label, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
) {
|
|
||||||
if(label->primitive.verticeCount == 0) return;
|
if(label->primitive.verticeCount == 0) return;
|
||||||
shaderUsePosition(shader, uniformModel, x,y,0, 0,0,0);
|
shaderUsePosition(shader, x,y,0, 0,0,0);
|
||||||
shaderUseTexture(shader, uniformTexture, &label->font->texture);
|
shaderUseTexture(shader, &label->font->texture);
|
||||||
primitiveDraw(&label->primitive, 0, -1);
|
primitiveDraw(&label->primitive, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,16 +38,10 @@ void labelSetText(label_t *label, font_t *font, char *text);
|
|||||||
*
|
*
|
||||||
* @param label Label to render.
|
* @param label Label to render.
|
||||||
* @param shader Shader to use while rendering.
|
* @param shader Shader to use while rendering.
|
||||||
* @param uniformModel Shader uniform for the model position.
|
|
||||||
* @param uniformTexture Shader uniform for the texture.
|
|
||||||
* @param x X position.
|
* @param x X position.
|
||||||
* @param y Y position.
|
* @param y Y position.
|
||||||
*/
|
*/
|
||||||
void labelRender(
|
void labelRender(label_t *label, shader_t *shader, float x, float y);
|
||||||
label_t *label, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispose a previously created label.
|
* Dispose a previously created label.
|
||||||
|
@ -20,17 +20,13 @@ void rectangleSetColor(rectangle_t *rectangle, pixel_t color) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rectangleRender(
|
void rectangleRender(rectangle_t *rect, shader_t *shader, float x, float y) {
|
||||||
rectangle_t *rect, shader_t *shader,
|
shaderUsePositionAndScale(shader,
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
) {
|
|
||||||
shaderUsePositionAndScale(shader, uniformModel,
|
|
||||||
x, y, 0,
|
x, y, 0,
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
rect->width, rect->height, 1
|
rect->width, rect->height, 1
|
||||||
);
|
);
|
||||||
shaderUseTexture(shader, uniformTexture, &rect->texture);
|
shaderUseTexture(shader, &rect->texture);
|
||||||
primitiveDraw(&rect->quad, 0, -1);
|
primitiveDraw(&rect->quad, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ void rectangleSetColor(rectangle_t *rectangle, pixel_t color);
|
|||||||
|
|
||||||
void rectangleRender(
|
void rectangleRender(
|
||||||
rectangle_t *rect, shader_t *shader,
|
rectangle_t *rect, shader_t *shader,
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
float x, float y
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -35,11 +35,7 @@ menuitem_t * textMenuAdd(textmenu_t *menu, char *item) {
|
|||||||
return menuAdd(&menu->menu);
|
return menuAdd(&menu->menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void textMenuRender(
|
void textMenuRender(textmenu_t *menu, shader_t *shader, float x, float y) {
|
||||||
textmenu_t *menu, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
) {
|
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
label_t *label;
|
label_t *label;
|
||||||
menuitem_t *item;
|
menuitem_t *item;
|
||||||
@ -53,7 +49,7 @@ void textMenuRender(
|
|||||||
&gx, &gy, &menu->rectangle.width, &menu->rectangle.height
|
&gx, &gy, &menu->rectangle.width, &menu->rectangle.height
|
||||||
);
|
);
|
||||||
rectangleRender(
|
rectangleRender(
|
||||||
&menu->rectangle, shader, uniformModel, uniformTexture, x + gx, y + gy
|
&menu->rectangle, shader, x + gx, y + gy
|
||||||
);
|
);
|
||||||
|
|
||||||
// Render labels
|
// Render labels
|
||||||
@ -67,7 +63,7 @@ void textMenuRender(
|
|||||||
label->info.width, label->info.height
|
label->info.width, label->info.height
|
||||||
);
|
);
|
||||||
labelRender(
|
labelRender(
|
||||||
label, shader, uniformModel, uniformTexture, align.x + x, align.y + y
|
label, shader, align.x + x, align.y + y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,16 +56,10 @@ menuitem_t * textMenuAdd(textmenu_t *menu, char *item);
|
|||||||
*
|
*
|
||||||
* @param menu Menu to render.
|
* @param menu Menu to render.
|
||||||
* @param shader Shader to use.
|
* @param shader Shader to use.
|
||||||
* @param uniformModel Shader uniform for the model position.
|
|
||||||
* @param uniformTexture Shader uniform for the texture.
|
|
||||||
* @param x X position of the menu.
|
* @param x X position of the menu.
|
||||||
* @param y Y position of the menu.
|
* @param y Y position of the menu.
|
||||||
*/
|
*/
|
||||||
void textMenuRender(
|
void textMenuRender(textmenu_t *menu, shader_t *shader, float x, float y);
|
||||||
textmenu_t *menu, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispose/Cleanup a text menu.
|
* Dispose/Cleanup a text menu.
|
||||||
|
@ -33,11 +33,10 @@ void vnConversationUpdate(vnconversation_t *convo, engine_t *engine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void vnConversationRender(
|
void vnConversationRender(
|
||||||
vnconversation_t *convo, engine_t *engine, shader_t *shader,
|
vnconversation_t *convo, engine_t *engine, shader_t *shader
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
|
||||||
) {
|
) {
|
||||||
vnTextBoxRender(
|
vnTextBoxRender(
|
||||||
&convo->textbox, shader, uniformModel, uniformTexture,
|
&convo->textbox, shader,
|
||||||
0, engine->render.height - convo->textbox.height
|
0, engine->render.height - convo->textbox.height
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,7 @@ void vnConversationUpdate(vnconversation_t *convo, engine_t *engine);
|
|||||||
* @param shader Shader to use while rendering.
|
* @param shader Shader to use while rendering.
|
||||||
*/
|
*/
|
||||||
void vnConversationRender(
|
void vnConversationRender(
|
||||||
vnconversation_t *convo, engine_t *engine, shader_t *shader,
|
vnconversation_t *convo, engine_t *engine, shader_t *shader
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,17 +77,13 @@ void vnTextBoxUpdate(vntextbox_t *box, engine_t *engine) {
|
|||||||
box->lineCurrent += box->linesMax;
|
box->lineCurrent += box->linesMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnTextBoxRender(
|
void vnTextBoxRender(vntextbox_t *box, shader_t *shader, float x, float y) {
|
||||||
vntextbox_t *box, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
) {
|
|
||||||
int32_t charStart, charCount;
|
int32_t charStart, charCount;
|
||||||
float yOffset;
|
float yOffset;
|
||||||
if(box->text == NULL || box->state & VN_TEXTBOX_STATE_CLOSED) return;
|
if(box->text == NULL || box->state & VN_TEXTBOX_STATE_CLOSED) return;
|
||||||
|
|
||||||
// Render the debug box.
|
// Render the debug box.
|
||||||
frameRender(&box->frame, shader, uniformModel, uniformTexture, x, y);
|
frameRender(&box->frame, shader, x, y);
|
||||||
|
|
||||||
// Determine where we're rendering the indices up to.
|
// Determine where we're rendering the indices up to.
|
||||||
charCount = (int32_t)box->textScroll;
|
charCount = (int32_t)box->textScroll;
|
||||||
@ -116,11 +112,11 @@ void vnTextBoxRender(
|
|||||||
if(charCount < 1) return;
|
if(charCount < 1) return;
|
||||||
|
|
||||||
// Render the Text Box
|
// Render the Text Box
|
||||||
shaderUsePosition(shader, uniformModel,
|
shaderUsePosition(shader,
|
||||||
x + FRAME_BORDER_SIZE, y - yOffset + FRAME_BORDER_SIZE, 0,
|
x + FRAME_BORDER_SIZE, y - yOffset + FRAME_BORDER_SIZE, 0,
|
||||||
0,0,0
|
0,0,0
|
||||||
);
|
);
|
||||||
shaderUseTexture(shader, uniformTexture, &box->font->texture);
|
shaderUseTexture(shader, &box->font->texture);
|
||||||
primitiveDraw(&box->primitive, charStart, charCount);
|
primitiveDraw(&box->primitive, charStart, charCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,16 +94,10 @@ void vnTextBoxUpdate(vntextbox_t *box, engine_t *engine);
|
|||||||
* will not be ticked, use update to do this.
|
* will not be ticked, use update to do this.
|
||||||
* @param box Box to render.
|
* @param box Box to render.
|
||||||
* @param shader Shader to render to.
|
* @param shader Shader to render to.
|
||||||
* @param uniformModel Shader uniform for the model position.
|
|
||||||
* @param uniformTexture Shader uniform for the texture.
|
|
||||||
* @param x X position.
|
* @param x X position.
|
||||||
* @param y Y position.
|
* @param y Y position.
|
||||||
*/
|
*/
|
||||||
void vnTextBoxRender(
|
void vnTextBoxRender(vntextbox_t *box, shader_t *shader, float x, float y);
|
||||||
vntextbox_t *box, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
|
|
||||||
float x, float y
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes a previously created Visual Novel Text Box.
|
* Disposes a previously created Visual Novel Text Box.
|
||||||
|
@ -165,16 +165,13 @@ void vnCharacterLayerSetFrame(vncharacter_t *character, uint8_t l, uint8_t f) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnCharacterRender(
|
void vnCharacterRender(vncharacter_t *character, shader_t *shader) {
|
||||||
vncharacter_t *character, shader_t *shader,
|
shaderUsePositionAndScale(shader,
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
|
||||||
) {
|
|
||||||
shaderUsePositionAndScale(shader, uniformModel,
|
|
||||||
character->x, character->y, character->z,
|
character->x, character->y, character->z,
|
||||||
character->pitch, character->yaw, character->roll,
|
character->pitch, character->yaw, character->roll,
|
||||||
character->scaleX, character->scaleY, 1
|
character->scaleX, character->scaleY, 1
|
||||||
);
|
);
|
||||||
shaderUseTexture(shader, uniformTexture, character->texture);
|
shaderUseTexture(shader, character->texture);
|
||||||
primitiveDraw(
|
primitiveDraw(
|
||||||
&character->primitive, 0, character->layerCount * QUAD_INDICE_COUNT
|
&character->primitive, 0, character->layerCount * QUAD_INDICE_COUNT
|
||||||
);
|
);
|
||||||
|
@ -58,9 +58,6 @@ uint8_t vnCharacterLayerAdd(vncharacter_t *character,
|
|||||||
void vnCharacterLayerSetFrame(vncharacter_t *character, uint8_t l, uint8_t f);
|
void vnCharacterLayerSetFrame(vncharacter_t *character, uint8_t l, uint8_t f);
|
||||||
|
|
||||||
void vnCharacterUpdate(vncharacter_t *character, engine_t *engine);
|
void vnCharacterUpdate(vncharacter_t *character, engine_t *engine);
|
||||||
void vnCharacterRender(
|
void vnCharacterRender(vncharacter_t *character, shader_t *shader);
|
||||||
vncharacter_t *character, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
|
||||||
);
|
|
||||||
|
|
||||||
void vnCharacterDispose(vncharacter_t *character);
|
void vnCharacterDispose(vncharacter_t *character);
|
@ -47,10 +47,7 @@ void vnSceneDispose(vnscene_t *scene) {
|
|||||||
vnConversationDispose(&scene->conversation);
|
vnConversationDispose(&scene->conversation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnSceneRenderWorld(
|
void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) {
|
||||||
vnscene_t *scene, engine_t *engine, shader_t *shader,
|
|
||||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection
|
|
||||||
) {
|
|
||||||
// Adjust Camera Position.
|
// Adjust Camera Position.
|
||||||
cameraLookAtStruct(&scene->camera, scene->cameraLook);
|
cameraLookAtStruct(&scene->camera, scene->cameraLook);
|
||||||
|
|
||||||
@ -61,26 +58,19 @@ void vnSceneRenderWorld(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Update Shader
|
// Update Shader
|
||||||
shaderUseCamera(shader, uniformView, uniformProjection, &scene->camera);
|
shaderUseCamera(shader, &scene->camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnSceneRenderCharacters(
|
void vnSceneRenderCharacters(vnscene_t *scene, shader_t *shader) {
|
||||||
vnscene_t *scene, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
|
||||||
) {
|
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
// Render each character
|
// Render each character
|
||||||
for(i = 0; i < scene->characterCount; i++) {
|
for(i = 0; i < scene->characterCount; i++) {
|
||||||
vnCharacterRender(scene->characters+i,shader,uniformModel,uniformTexture);
|
vnCharacterRender(scene->characters+i, shader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnSceneRenderGui(
|
void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader) {
|
||||||
vnscene_t *scene, engine_t *engine, shader_t *shader,
|
|
||||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
|
||||||
) {
|
|
||||||
// Do we need to update the width of the GUI element(s) ?
|
// Do we need to update the width of the GUI element(s) ?
|
||||||
if(engine->render.width != scene->conversation.textbox.widthMax) {
|
if(engine->render.width != scene->conversation.textbox.widthMax) {
|
||||||
scene->conversation.textbox.widthMax = engine->render.width;
|
scene->conversation.textbox.widthMax = engine->render.width;
|
||||||
@ -101,12 +91,10 @@ void vnSceneRenderGui(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Update Shader
|
// Update Shader
|
||||||
shaderUseCamera(shader, uniformView, uniformProjection, &scene->camera);
|
shaderUseCamera(shader, &scene->camera);
|
||||||
|
|
||||||
// Render Conversation Element
|
// Render Conversation Element
|
||||||
vnConversationRender(
|
vnConversationRender(&scene->conversation, engine, shader);
|
||||||
&scene->conversation, engine, shader, uniformModel, uniformTexture
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnSceneLookAt(vnscene_t *scene,
|
void vnSceneLookAt(vnscene_t *scene,
|
||||||
|
@ -44,21 +44,11 @@ void vnSceneUpdate(vnscene_t *scene, engine_t *engine);
|
|||||||
|
|
||||||
void vnSceneDispose(vnscene_t *scene);
|
void vnSceneDispose(vnscene_t *scene);
|
||||||
|
|
||||||
void vnSceneRenderWorld(
|
void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader);
|
||||||
vnscene_t *scene, engine_t *engine, shader_t *shader,
|
|
||||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection
|
|
||||||
);
|
|
||||||
|
|
||||||
void vnSceneRenderCharacters(
|
void vnSceneRenderCharacters(vnscene_t *scene, shader_t *shader);
|
||||||
vnscene_t *scene, shader_t *shader,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
|
||||||
);
|
|
||||||
|
|
||||||
void vnSceneRenderGui(
|
void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader);
|
||||||
vnscene_t *scene, engine_t *engine, shader_t *shader,
|
|
||||||
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
|
|
||||||
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
|
|
||||||
);
|
|
||||||
|
|
||||||
void vnSceneLookAt(vnscene_t *scene,
|
void vnSceneLookAt(vnscene_t *scene,
|
||||||
float x, float y, float z, float lookX, float lookY, float lookZ
|
float x, float y, float z, float lookX, float lookY, float lookZ
|
||||||
|
Reference in New Issue
Block a user