diff --git a/src/display/renderlist.c b/src/display/renderlist.c index c52e09d6..984dd765 100644 --- a/src/display/renderlist.c +++ b/src/display/renderlist.c @@ -46,9 +46,7 @@ renderpass_t * renderListRenderPass( return renderPass; } -void renderListRender( - renderlist_t *list, shader_t *shader, shaderuniform_t *uniforms -) { +void renderListRender(renderlist_t *list, shader_t *shader) { camera_t camera; int32_t i; renderpass_t *pass; @@ -62,13 +60,13 @@ void renderListRender( // Set the shader shaderUse(shader); - shaderUseCamera(shader, uniforms[0], uniforms[1], &camera); - shaderUsePosition(shader, uniforms[2], 0,0,0, 0,0,0); + shaderUseCamera(shader, &camera); + shaderUsePosition(shader, 0,0,0, 0,0,0); // Render each pass. for(i = 0; i < list->passCount; i++) { pass = renderListGetPass(list, i); - shaderUseTexture(shader, uniforms[3+i], &pass->frame.texture); + shaderUseTexture(shader, &pass->frame.texture); primitiveDraw(&list->quad, 0, -1); } } @@ -88,9 +86,9 @@ void renderListAsBackbuffer( // Set up the shader. shaderUse(shader); - shaderUseCamera(shader, uniforms[0], uniforms[1], &camera); - shaderUsePosition(shader, uniforms[2], 0,0,0, 0,0,0); - shaderUseTexture(shader, uniforms[3], &list->frame.texture); + shaderUseCamera(shader, &camera); + shaderUsePosition(shader, 0,0,0, 0,0,0); + shaderUseTexture(shader, &list->frame.texture); // Render the quad to the back buffer. primitiveDraw(&list->quad, 0, -1); diff --git a/src/display/shader.c b/src/display/shader.c index e40ed043..24b65779 100644 --- a/src/display/shader.c +++ b/src/display/shader.c @@ -10,11 +10,9 @@ void shaderInit(shader_t *shader, char *vertexShaderSource, char* fragmentShaderSource ) { - int32_t isSuccess, maxLength, i, texture; + int isSuccess, maxLength; char *error; GLuint shaderVertex, shaderFragment, shaderProgram; - GLint size; // size of the variable - GLsizei length; // name length GLchar const* filesVertex[] = { vertexShaderSource }; GLchar const* filesFragment[] = { fragmentShaderSource }; @@ -68,49 +66,24 @@ void shaderInit(shader_t *shader, glDeleteShader(shaderFragment); return; } + // Everything is okay, let's create the encapsulated shader. shader->shaderVertex = shaderVertex; shader->shaderFrag = shaderFragment; shader->shaderProgram = shaderProgram; - // Extract uniforms - glGetProgramiv(shaderProgram, GL_ACTIVE_UNIFORMS, &shader->uniformCount); - - texture = 0; - for(i = 0; i < shader->uniformCount; i++) { - 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++; - } + shader->uniProj = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_PROJ); + shader->uniView = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_VIEW); + shader->uniText = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_TEXT); + shader->uniModl = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_MODL); + shader->uniColr = glGetUniformLocation(shader->shaderProgram,SHADER_UNI_COLR); // Bind the shader shaderUse(shader); -} -shaderuniform_t shaderGetUniform(shader_t *shader, char *name) { - int32_t i; - for(i = 0; i < shader->uniformCount; i++) { - 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]); - } + // Reset position + shaderUsePosition(shader, 0, 0, 0, 0, 0, 0); + shaderUseColor(shader, PIXEL_COLOR_WHITE); } void shaderDispose(shader_t *shader) { @@ -123,33 +96,23 @@ void shaderUse(shader_t *shader) { glUseProgram(shader->shaderProgram); } -void shaderUseTexture( - shader_t *shader, shaderuniform_t uniform, texture_t *texture -) { - 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 shaderUseCamera(shader_t *shader, camera_t *camera) { + shaderUseMatrix(shader, shader->uniView, &camera->view); + shaderUseMatrix(shader, shader->uniProj, &camera->projection); } -void shaderUseMatrix( - shader_t *shader, shaderuniform_t uniform, matrix_t *matrix -) { +void shaderUseTexture(shader_t *shader, texture_t *texture) { + // 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]); } -void shaderUseColor(shader_t *shader, shaderuniform_t uniform, pixel_t color) { - 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, +void shaderUsePosition(shader_t *shader, float x, float y, float z, float pitch, float yaw, float roll ) { @@ -162,11 +125,10 @@ void shaderUsePosition( matrixRotate(&matrix, yaw, 0, 1, 0); matrixRotate(&matrix, roll, 0, 0, 1); matrixRotate(&matrix, pitch, 1, 0, 0); - shaderUseMatrix(shader, uniform, &matrix); + shaderUseMatrix(shader, shader->uniModl, &matrix); } -void shaderUsePositionAndScale( - shader_t *shader, shaderuniform_t uniform, +void shaderUsePositionAndScale(shader_t *shader, float x, float y, float z, float pitch, float yaw, float roll, float scaleX, float scaleY, float scaleZ @@ -183,14 +145,14 @@ void shaderUsePositionAndScale( matrixScale(&matrix, scaleX, scaleY, scaleZ); - shaderUseMatrix(shader, uniform, &matrix); + shaderUseMatrix(shader, shader->uniModl, &matrix); } -void shaderUseCamera( - shader_t *shader, - shaderuniform_t uniformView, shaderuniform_t uniformProjection, - camera_t *camera -) { - shaderUseMatrix(shader, uniformView, &camera->view); - shaderUseMatrix(shader, uniformProjection, &camera->projection); -} +void shaderUseColor(shader_t *shader, pixel_t color) { + glUniform4f(shader->uniColr, + (float)color.r / 255.0f, + (float)color.g / 255.0f, + (float)color.b / 255.0f, + (float)color.a / 255.0f + ); +} \ No newline at end of file diff --git a/src/display/shader.h b/src/display/shader.h index 3c922fd4..db2ad9c1 100644 --- a/src/display/shader.h +++ b/src/display/shader.h @@ -10,10 +10,12 @@ #include "matrix.h" #include "camera.h" #include "texture.h" -#include "../util/array.h" -#define SHADER_UNIFORM_NAME_MAX 24 -#define SHADER_UNIFORM_COUNT 16 +#define SHADER_UNI_VIEW "u_View" +#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 */ typedef GLuint shaderuniform_t; @@ -24,26 +26,28 @@ typedef GLuint shaderuniform_t; */ typedef struct { /** Pointer to an uploaded vertex shader program */ - GLuint shaderVertex; + shaderuniform_t shaderVertex; /** Pointer to an uploaded fragment shader program */ - GLuint shaderFrag; + shaderuniform_t shaderFrag; /** Pointer to an uploaded shader program linked */ - GLuint shaderProgram; + shaderuniform_t shaderProgram; - /** Buffer of chars where we store the uniform names */ - char uniformBuffer[SHADER_UNIFORM_NAME_MAX * SHADER_UNIFORM_COUNT]; + /** Matrix for the view matrix */ + shaderuniform_t uniView; - /** Array of strings (pointers to the above buffer) of the uniform names */ - char *uniformNames[SHADER_UNIFORM_COUNT]; - int32_t uniformCount; + /** Matrix for the projection matrix */ + shaderuniform_t uniProj; - /** Type of each uniform */ - GLenum types[SHADER_UNIFORM_COUNT]; + /** Uniform for the current texture */ + shaderuniform_t uniText; - /** Texture Slots (which texture slot for GL to use for each uniform) */ - uint8_t textureSlots[SHADER_UNIFORM_COUNT]; + /** Uniform for the current model world position */ + shaderuniform_t uniModl; + + /** Uniform for the color multiplier */ + shaderuniform_t uniColr; } shader_t; /** @@ -56,28 +60,6 @@ void shaderInit(shader_t *shader, 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. * @param shader The shader to unload @@ -90,16 +72,20 @@ void shaderDispose(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. - * * @param shader Shader to attach to. - * @param uniform Uniform on the shader to set. * @param texture Texture to attach. */ -void shaderUseTexture( - shader_t *shader, shaderuniform_t uniform, texture_t *texture -); +void shaderUseTexture(shader_t *shader, texture_t *texture); /** * Set's a specific shader uniform to a matrix. @@ -108,25 +94,12 @@ void shaderUseTexture( * @param uniform Uniform on the shader to set. * @param matrix Matrix to apply. */ -void shaderUseMatrix( - 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); +void shaderUseMatrix(shader_t *shader,shaderuniform_t uniform,matrix_t *matrix); /** * Set's the current translation matrix onto the shader for the next * render to use. Rotation order is set to YZX. - * * @param shader Shader to attach to. - * @param uniform Uniform on the shader to set. * @param x X coordinate (world space). * @param y Y 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 roll Roll of the object (local space). */ -void shaderUsePosition( - shader_t *shader, shaderuniform_t uniform, +void shaderUsePosition(shader_t *shader, float x, float y, float z, float pitch, float yaw, float roll ); + /** * Set's the current translation matrix onto the shader for the next * render to use. Also provides scaling controls. * * @param shader Shader to attach to. - * @param uniform Uniform on the shader to set. * @param x X coordinate (world space). * @param y Y 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 scaleZ Z scale of model (1 being 100% scaled). */ -void shaderUsePositionAndScale( - shader_t *shader, shaderuniform_t uniform, +void shaderUsePositionAndScale(shader_t *shader, float x, float y, float z, float pitch, float yaw, float roll, float scaleX, float scaleY, float scaleZ ); -/** - * Attaches a camera to the shader. - * - * @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 -); \ No newline at end of file + +void shaderUseColor(shader_t *shader, pixel_t color); \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.c index df64f333..d9e30786 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -18,10 +18,11 @@ void engineInit(engine_t *engine) { clientInit(&engine->client); epochInit(&engine->time); - renderInit(); + saveManagerInit(&engine->save); inputInit(&engine->input); - - assetManagerInit(&engine->assetManager); + assetManagerInit(&engine->assetManager, &engine->save); + renderInit(); + assetManagerStart(&engine->assetManager); } diff --git a/src/engine/engine.h b/src/engine/engine.h index 62e726c0..e2c268bf 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -13,10 +13,7 @@ #include "../epoch/epoch.h" #include "../display/render.h" #include "../file/assetmanager.h" - -// #if !defined(GAME_NAME) -// #error You need to define the GAME_NAME string -// #endif +#include "../save/save.h" typedef struct { /** Name of the game */ @@ -34,6 +31,9 @@ typedef struct { /** Input Manager for the game */ input_t input; + /** Save Manager for the game */ + savemanager_t save; + /** Game client information */ client_t client; } engine_t; diff --git a/src/file/assetmanager.c b/src/file/assetmanager.c index 45d393df..ac4d05b6 100644 --- a/src/file/assetmanager.c +++ b/src/file/assetmanager.c @@ -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); manager->thread.user = manager; manager->itemCount = 0; manager->finished = false; manager->holderCount = 0; manager->running = false; + manager->save = save; } float assetManagerProgressGet(assetmanager_t *manager) { diff --git a/src/file/assetmanager.h b/src/file/assetmanager.h index d7dbcf85..f57e58c0 100644 --- a/src/file/assetmanager.h +++ b/src/file/assetmanager.h @@ -13,6 +13,7 @@ #include "loaders/shader.h" #include "loaders/texture.h" #include "asset.h" +#include "../save/save.h" // Constants extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[]; @@ -22,7 +23,7 @@ extern assetmanagerloaderdefinition_t ASSET_MANAGER_LOADERS[]; * * @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 diff --git a/src/file/loaders/scaledtexture.c b/src/file/loaders/scaledtexture.c index 206bb760..9749b321 100644 --- a/src/file/loaders/scaledtexture.c +++ b/src/file/loaders/scaledtexture.c @@ -8,16 +8,21 @@ #include "scaledtexture.h" assetmanageritem_t * assetManagerLoadScaledTexture( - assetmanager_t *manager, assetmanagerowner_t owner, - char *path, char *file, uint8_t scale + assetmanager_t *manager, assetmanagerowner_t owner, char *path, char *file ) { assetmanageritem_t *item; texturescale_t *st; + uint8_t scale; 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); - + + // Already loaded? if(item == NULL) { item = assetManagerItemAdd(manager, buffer); item->type = ASSET_MANAGER_TYPE_SCALED_TEXTURE; @@ -121,3 +126,51 @@ bool _assetManagerLoaderScaledTextureDispose(assetmanageritem_t *item) { textureDispose(&item->data.scaledTexture.texture); 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); + } +} \ No newline at end of file diff --git a/src/file/loaders/scaledtexture.h b/src/file/loaders/scaledtexture.h index a23c41f9..a92c4f88 100644 --- a/src/file/loaders/scaledtexture.h +++ b/src/file/loaders/scaledtexture.h @@ -9,6 +9,7 @@ #include "item.h" #include "../xml.h" #include "../asset.h" +#include "../../save/save.h" /** * Load the given texture scale for a scaled texture. @@ -17,14 +18,33 @@ * @param owner Owner ID requesting to load this resource. * @param path Path of the texture size sets * @param file Name of the texture that was generated. - * @param scale Scale to load. * @return A pointer to the asset manager item for tracking. */ assetmanageritem_t * assetManagerLoadScaledTexture( - assetmanager_t *manager, assetmanagerowner_t owner, - char *path, char *file, uint8_t scale + assetmanager_t *manager, assetmanagerowner_t owner, char *path, char *file ); bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item); bool _assetManagerLoaderScaledTextureSync(assetmanageritem_t *item); -bool _assetManagerLoaderScaledTextureDispose(assetmanageritem_t *item); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/file/types/common.h b/src/file/types/common.h index 9b22c66f..ca21e6a8 100644 --- a/src/file/types/common.h +++ b/src/file/types/common.h @@ -8,11 +8,13 @@ #pragma once #include "../../libs.h" #include "../../engine/thread.h" +#include "../../save/save.h" #include "texture.h" #include "font.h" #include "shader.h" #include "scaledtexture.h" + #define ASSET_MANAGER_ITEMS_MAX 64 #define ASSET_MANAGER_ITEM_NAME_MAX 96 #define ASSET_MANAGER_HOLDERS_MAX 8 @@ -69,6 +71,8 @@ typedef struct { // Manager typedef struct { thread_t thread; + savemanager_t *save; + bool finished; bool running; diff --git a/src/games/poker/game.c b/src/games/poker/game.c index c4b30f69..38fcb88a 100644 --- a/src/games/poker/game.c +++ b/src/games/poker/game.c @@ -11,13 +11,44 @@ bool gameInit(game_t *game) { // Init the engine and the rendering pipeline 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; } +bool doneResize = false; + bool gameUpdate(game_t *game, float delta) { // Let the engine do its thing. 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. return engineUpdateEnd(&game->engine); diff --git a/src/games/poker/game.h b/src/games/poker/game.h index e7faf878..99b63474 100644 --- a/src/games/poker/game.h +++ b/src/games/poker/game.h @@ -8,9 +8,18 @@ #pragma once #include "../../libs.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 { engine_t engine; + camera_t camera; + shader_t shader; + primitive_t quad; + assetmanagerowner_t owner; + assetmanageritem_t *item; } game_t; /** diff --git a/src/save/save.c b/src/save/save.c index fd1544a7..9fbd1f1b 100644 --- a/src/save/save.c +++ b/src/save/save.c @@ -9,13 +9,15 @@ void saveManagerInit(savemanager_t *man) { man->count = 0; + + // Set up defaults + saveManagerSetUint8(man, SAVE_KEY_TEXTURE_SCALE, 0x00); } savevalue_t * saveManagerAddOrGet(savemanager_t *man, char *key) { uint8_t i, j; j = saveManagerGetKey(man, key); - if(j != 0xFF) return man->values + j; // Find empty key diff --git a/src/save/save.h b/src/save/save.h index ffbd4976..d8e557d1 100644 --- a/src/save/save.h +++ b/src/save/save.h @@ -11,6 +11,8 @@ #define SAVE_VALUES_MAX 200 +#define SAVE_KEY_TEXTURE_SCALE "TEXTURE_SCALE" + typedef union { // char *s; bool b; diff --git a/src/scene/scene.c b/src/scene/scene.c index 1f9fc450..1e91b140 100644 --- a/src/scene/scene.c +++ b/src/scene/scene.c @@ -14,13 +14,9 @@ void sceneInit(scene_t *scene, engine_t *engine, void *user) { scene->onLoaded = NULL; scene->onRender = NULL; scene->loaded = false; - renderListInit(&scene->renderList, (int32_t)1, (int32_t)1); } -float sceneUpdate( - scene_t *scene, int32_t width, int32_t height, shader_t *shader, - shaderuniform_t *uniforms -) { +float sceneUpdate(scene_t *scene) { // First, lets check how loading has been going float n = assetManagerProgressGetForHolder( &scene->engine->assetManager, scene->assetOwner @@ -35,38 +31,12 @@ float sceneUpdate( if(scene->onLoaded != NULL) scene->onLoaded(scene); } - // Resize the render list - renderListResize(&scene->renderList, width, height); - // Fire callback if(scene->onRender != NULL) scene->onRender(scene); - // Render the render list itself. - renderListRender(&scene->renderList, shader, uniforms); - 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) { 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); } \ No newline at end of file diff --git a/src/scene/scene.h b/src/scene/scene.h index 872d3094..c0cddbd4 100644 --- a/src/scene/scene.h +++ b/src/scene/scene.h @@ -22,9 +22,9 @@ typedef void scenecallback_t(scene_t *scene); typedef struct _scene_t { engine_t *engine; assetmanagerowner_t assetOwner; - renderlist_t renderList; void *user; + /** Whether or not the assets that this scene depends upon have loaded */ bool loaded; /** Scene Callbacks */ @@ -34,17 +34,6 @@ typedef struct _scene_t { void sceneInit(scene_t *scene, engine_t *engine, void *user); +float sceneUpdate(scene_t *scene); -float sceneUpdate( - 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); \ No newline at end of file +void sceneDispose(scene_t *scene); \ No newline at end of file diff --git a/src/ui/frame.c b/src/ui/frame.c index 24ec029c..c5cacd28 100644 --- a/src/ui/frame.c +++ b/src/ui/frame.c @@ -100,14 +100,10 @@ void frameSetInnerSize(frame_t *frame, float width, float height) { ); } -void frameRender( - frame_t *frame, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -) { +void frameRender(frame_t *frame, shader_t *shader, float x, float y) { if(frame->texture == NULL) return; - shaderUsePosition(shader, uniformModel, x, y, 0, 0, 0, 0); - shaderUseTexture(shader, uniformTexture, frame->texture); + shaderUsePosition(shader, x, y, 0, 0, 0, 0); + shaderUseTexture(shader, frame->texture); primitiveDraw(&frame->primitive, 0, -1); } diff --git a/src/ui/frame.h b/src/ui/frame.h index 6ff7ce62..82676938 100644 --- a/src/ui/frame.h +++ b/src/ui/frame.h @@ -54,16 +54,10 @@ void frameSetInnerSize(frame_t *frame, float width, float height); * * @param frame Frame to render. * @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 y Y position. */ -void frameRender( - frame_t *frame, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -); +void frameRender(frame_t *frame, shader_t *shader, float x, float y); /** * Cleanup a previously initialized frame. diff --git a/src/ui/framedtextmenu.c b/src/ui/framedtextmenu.c index 84c5176f..e21810be 100644 --- a/src/ui/framedtextmenu.c +++ b/src/ui/framedtextmenu.c @@ -30,12 +30,10 @@ void framedTextMenuUpdate(framedtextmenu_t *menu, engine_t *engine) { } void framedTextMenuRender( - framedtextmenu_t *menu, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y + framedtextmenu_t *menu, shader_t *shader, float x, float y ) { - frameRender(&menu->frame, shader, uniformModel, uniformTexture, x, y); - textMenuRender(&menu->menu, shader, uniformModel, uniformTexture, x, y); + frameRender(&menu->frame, shader, x, y); + textMenuRender(&menu->menu, shader, x, y); } void framedTextMenuDispose(framedtextmenu_t *menu) { diff --git a/src/ui/framedtextmenu.h b/src/ui/framedtextmenu.h index 4fefdd32..0e62b8a9 100644 --- a/src/ui/framedtextmenu.h +++ b/src/ui/framedtextmenu.h @@ -52,15 +52,11 @@ void framedTextMenuUpdate(framedtextmenu_t *menu, engine_t *engine); * * @param menu Menu to render. * @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 y Y Position. */ void framedTextMenuRender( - framedtextmenu_t *menu, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y + framedtextmenu_t *menu, shader_t *shader, float x, float y ); /** diff --git a/src/ui/image.c b/src/ui/image.c index 651c6f52..014284ce 100644 --- a/src/ui/image.c +++ b/src/ui/image.c @@ -46,18 +46,14 @@ void imageSetTextureAndCrop(image_t *image, texture_t *texture, ); } -void imageRender( - image_t *image, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -) { +void imageRender(image_t *image, shader_t *shader, float x, float y) { if(image->texture == NULL) return; - shaderUsePositionAndScale(shader, uniformModel, + shaderUsePositionAndScale(shader, x,y,0, 0,0,0, image->width, image->height, 1 ); - shaderUseTexture(shader, uniformTexture, image->texture); + shaderUseTexture(shader, image->texture); primitiveDraw(&image->quad, 0, -1); } diff --git a/src/ui/image.h b/src/ui/image.h index 9ff5e9b3..4051b8ff 100644 --- a/src/ui/image.h +++ b/src/ui/image.h @@ -53,16 +53,10 @@ void imageSetTextureAndCrop(image_t *image, texture_t *texture, * * @param image Image to render. * @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 y Y position. */ -void imageRender( - image_t *image, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -); +void imageRender(image_t *image, shader_t *shader, float x, float y); /** * Cleanup a previously initialized image. diff --git a/src/ui/label.c b/src/ui/label.c index 612d86f0..06827a76 100644 --- a/src/ui/label.c +++ b/src/ui/label.c @@ -27,14 +27,10 @@ void labelSetText(label_t *label, font_t *font, char *text) { ); } -void labelRender( - label_t *label, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -) { +void labelRender(label_t *label, shader_t *shader, float x, float y) { if(label->primitive.verticeCount == 0) return; - shaderUsePosition(shader, uniformModel, x,y,0, 0,0,0); - shaderUseTexture(shader, uniformTexture, &label->font->texture); + shaderUsePosition(shader, x,y,0, 0,0,0); + shaderUseTexture(shader, &label->font->texture); primitiveDraw(&label->primitive, 0, -1); } diff --git a/src/ui/label.h b/src/ui/label.h index 565e53d5..4c50bdaa 100644 --- a/src/ui/label.h +++ b/src/ui/label.h @@ -38,16 +38,10 @@ void labelSetText(label_t *label, font_t *font, char *text); * * @param label Label to render. * @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 y Y position. */ -void labelRender( - label_t *label, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -); +void labelRender(label_t *label, shader_t *shader, float x, float y); /** * Dispose a previously created label. diff --git a/src/ui/rectangle.c b/src/ui/rectangle.c index c0e666b5..fff11d1d 100644 --- a/src/ui/rectangle.c +++ b/src/ui/rectangle.c @@ -20,17 +20,13 @@ void rectangleSetColor(rectangle_t *rectangle, pixel_t color) { ); } -void rectangleRender( - rectangle_t *rect, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -) { - shaderUsePositionAndScale(shader, uniformModel, +void rectangleRender(rectangle_t *rect, shader_t *shader, float x, float y) { + shaderUsePositionAndScale(shader, x, y, 0, 0, 0, 0, rect->width, rect->height, 1 ); - shaderUseTexture(shader, uniformTexture, &rect->texture); + shaderUseTexture(shader, &rect->texture); primitiveDraw(&rect->quad, 0, -1); } diff --git a/src/ui/rectangle.h b/src/ui/rectangle.h index 29ca7d45..518aaa09 100644 --- a/src/ui/rectangle.h +++ b/src/ui/rectangle.h @@ -24,7 +24,6 @@ void rectangleSetColor(rectangle_t *rectangle, pixel_t color); void rectangleRender( rectangle_t *rect, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, float x, float y ); diff --git a/src/ui/textmenu.c b/src/ui/textmenu.c index ebf99a39..8afc1763 100644 --- a/src/ui/textmenu.c +++ b/src/ui/textmenu.c @@ -35,11 +35,7 @@ menuitem_t * textMenuAdd(textmenu_t *menu, char *item) { return menuAdd(&menu->menu); } -void textMenuRender( - textmenu_t *menu, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -) { +void textMenuRender(textmenu_t *menu, shader_t *shader, float x, float y) { uint8_t i; label_t *label; menuitem_t *item; @@ -53,7 +49,7 @@ void textMenuRender( &gx, &gy, &menu->rectangle.width, &menu->rectangle.height ); rectangleRender( - &menu->rectangle, shader, uniformModel, uniformTexture, x + gx, y + gy + &menu->rectangle, shader, x + gx, y + gy ); // Render labels @@ -67,7 +63,7 @@ void textMenuRender( label->info.width, label->info.height ); labelRender( - label, shader, uniformModel, uniformTexture, align.x + x, align.y + y + label, shader, align.x + x, align.y + y ); } } diff --git a/src/ui/textmenu.h b/src/ui/textmenu.h index 537506a0..b9d2208a 100644 --- a/src/ui/textmenu.h +++ b/src/ui/textmenu.h @@ -56,16 +56,10 @@ menuitem_t * textMenuAdd(textmenu_t *menu, char *item); * * @param menu Menu to render. * @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 y Y position of the menu. */ -void textMenuRender( - textmenu_t *menu, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -); +void textMenuRender(textmenu_t *menu, shader_t *shader, float x, float y); /** * Dispose/Cleanup a text menu. diff --git a/src/vn/conversation/vnconversation.c b/src/vn/conversation/vnconversation.c index 8d6bfd0e..0a0f8d21 100644 --- a/src/vn/conversation/vnconversation.c +++ b/src/vn/conversation/vnconversation.c @@ -33,11 +33,10 @@ void vnConversationUpdate(vnconversation_t *convo, engine_t *engine) { } void vnConversationRender( - vnconversation_t *convo, engine_t *engine, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture + vnconversation_t *convo, engine_t *engine, shader_t *shader ) { vnTextBoxRender( - &convo->textbox, shader, uniformModel, uniformTexture, + &convo->textbox, shader, 0, engine->render.height - convo->textbox.height ); } diff --git a/src/vn/conversation/vnconversation.h b/src/vn/conversation/vnconversation.h index 0fb31b24..ef89950e 100644 --- a/src/vn/conversation/vnconversation.h +++ b/src/vn/conversation/vnconversation.h @@ -69,8 +69,7 @@ void vnConversationUpdate(vnconversation_t *convo, engine_t *engine); * @param shader Shader to use while rendering. */ void vnConversationRender( - vnconversation_t *convo, engine_t *engine, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture + vnconversation_t *convo, engine_t *engine, shader_t *shader ); /** diff --git a/src/vn/ui/vntextbox.c b/src/vn/ui/vntextbox.c index 839ef0e5..042cd7e7 100644 --- a/src/vn/ui/vntextbox.c +++ b/src/vn/ui/vntextbox.c @@ -77,17 +77,13 @@ void vnTextBoxUpdate(vntextbox_t *box, engine_t *engine) { box->lineCurrent += box->linesMax; } -void vnTextBoxRender( - vntextbox_t *box, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -) { +void vnTextBoxRender(vntextbox_t *box, shader_t *shader, float x, float y) { int32_t charStart, charCount; float yOffset; if(box->text == NULL || box->state & VN_TEXTBOX_STATE_CLOSED) return; // 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. charCount = (int32_t)box->textScroll; @@ -116,11 +112,11 @@ void vnTextBoxRender( if(charCount < 1) return; // Render the Text Box - shaderUsePosition(shader, uniformModel, + shaderUsePosition(shader, x + FRAME_BORDER_SIZE, y - yOffset + FRAME_BORDER_SIZE, 0, 0,0,0 ); - shaderUseTexture(shader, uniformTexture, &box->font->texture); + shaderUseTexture(shader, &box->font->texture); primitiveDraw(&box->primitive, charStart, charCount); } diff --git a/src/vn/ui/vntextbox.h b/src/vn/ui/vntextbox.h index 6ac5e0b8..e5879f3d 100644 --- a/src/vn/ui/vntextbox.h +++ b/src/vn/ui/vntextbox.h @@ -94,16 +94,10 @@ void vnTextBoxUpdate(vntextbox_t *box, engine_t *engine); * will not be ticked, use update to do this. * @param box Box to render. * @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 y Y position. */ -void vnTextBoxRender( - vntextbox_t *box, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture, - float x, float y -); +void vnTextBoxRender(vntextbox_t *box, shader_t *shader, float x, float y); /** * Disposes a previously created Visual Novel Text Box. diff --git a/src/vn/vncharacter.c b/src/vn/vncharacter.c index 258fbe2b..feca9670 100644 --- a/src/vn/vncharacter.c +++ b/src/vn/vncharacter.c @@ -165,16 +165,13 @@ void vnCharacterLayerSetFrame(vncharacter_t *character, uint8_t l, uint8_t f) { ); } -void vnCharacterRender( - vncharacter_t *character, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture -) { - shaderUsePositionAndScale(shader, uniformModel, +void vnCharacterRender(vncharacter_t *character, shader_t *shader) { + shaderUsePositionAndScale(shader, character->x, character->y, character->z, character->pitch, character->yaw, character->roll, character->scaleX, character->scaleY, 1 ); - shaderUseTexture(shader, uniformTexture, character->texture); + shaderUseTexture(shader, character->texture); primitiveDraw( &character->primitive, 0, character->layerCount * QUAD_INDICE_COUNT ); diff --git a/src/vn/vncharacter.h b/src/vn/vncharacter.h index 08fd550d..c18f8c08 100644 --- a/src/vn/vncharacter.h +++ b/src/vn/vncharacter.h @@ -58,9 +58,6 @@ uint8_t vnCharacterLayerAdd(vncharacter_t *character, void vnCharacterLayerSetFrame(vncharacter_t *character, uint8_t l, uint8_t f); void vnCharacterUpdate(vncharacter_t *character, engine_t *engine); -void vnCharacterRender( - vncharacter_t *character, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture -); +void vnCharacterRender(vncharacter_t *character, shader_t *shader); void vnCharacterDispose(vncharacter_t *character); \ No newline at end of file diff --git a/src/vn/vnscene.c b/src/vn/vnscene.c index a66b651e..9e36a9ed 100644 --- a/src/vn/vnscene.c +++ b/src/vn/vnscene.c @@ -47,10 +47,7 @@ void vnSceneDispose(vnscene_t *scene) { vnConversationDispose(&scene->conversation); } -void vnSceneRenderWorld( - vnscene_t *scene, engine_t *engine, shader_t *shader, - shaderuniform_t uniformView, shaderuniform_t uniformProjection -) { +void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) { // Adjust Camera Position. cameraLookAtStruct(&scene->camera, scene->cameraLook); @@ -61,26 +58,19 @@ void vnSceneRenderWorld( ); // Update Shader - shaderUseCamera(shader, uniformView, uniformProjection, &scene->camera); + shaderUseCamera(shader, &scene->camera); } -void vnSceneRenderCharacters( - vnscene_t *scene, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture -) { +void vnSceneRenderCharacters(vnscene_t *scene, shader_t *shader) { uint8_t i; // Render each character for(i = 0; i < scene->characterCount; i++) { - vnCharacterRender(scene->characters+i,shader,uniformModel,uniformTexture); + vnCharacterRender(scene->characters+i, shader); } } -void vnSceneRenderGui( - vnscene_t *scene, engine_t *engine, shader_t *shader, - shaderuniform_t uniformView, shaderuniform_t uniformProjection, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture -) { +void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader) { // Do we need to update the width of the GUI element(s) ? if(engine->render.width != scene->conversation.textbox.widthMax) { scene->conversation.textbox.widthMax = engine->render.width; @@ -101,12 +91,10 @@ void vnSceneRenderGui( ); // Update Shader - shaderUseCamera(shader, uniformView, uniformProjection, &scene->camera); + shaderUseCamera(shader, &scene->camera); // Render Conversation Element - vnConversationRender( - &scene->conversation, engine, shader, uniformModel, uniformTexture - ); + vnConversationRender(&scene->conversation, engine, shader); } void vnSceneLookAt(vnscene_t *scene, diff --git a/src/vn/vnscene.h b/src/vn/vnscene.h index b75e5c0e..4b2f1c21 100644 --- a/src/vn/vnscene.h +++ b/src/vn/vnscene.h @@ -44,21 +44,11 @@ void vnSceneUpdate(vnscene_t *scene, engine_t *engine); void vnSceneDispose(vnscene_t *scene); -void vnSceneRenderWorld( - vnscene_t *scene, engine_t *engine, shader_t *shader, - shaderuniform_t uniformView, shaderuniform_t uniformProjection -); +void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader); -void vnSceneRenderCharacters( - vnscene_t *scene, shader_t *shader, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture -); +void vnSceneRenderCharacters(vnscene_t *scene, shader_t *shader); -void vnSceneRenderGui( - vnscene_t *scene, engine_t *engine, shader_t *shader, - shaderuniform_t uniformView, shaderuniform_t uniformProjection, - shaderuniform_t uniformModel, shaderuniform_t uniformTexture -); +void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader); void vnSceneLookAt(vnscene_t *scene, float x, float y, float z, float lookX, float lookY, float lookZ