Working on the new refactor of primitive and shader

This commit is contained in:
2021-11-11 09:47:42 -08:00
parent ada6de9723
commit e4222866ef
49 changed files with 635 additions and 440 deletions

View File

@ -8,8 +8,8 @@
#pragma once
#include "../libs.h"
#include "texture.h"
#include "primitive.h"
#include "primitives/quad.h"
#include "primitive/primitive.h"
#include "primitive/quad.h"
#include "../util/mem.h"
#include "../util/math.h"

View File

@ -5,7 +5,7 @@
#pragma once
#include "../../libs.h"
#include "../primitive.h"
#include "primitive.h"
#define CUBE_VERTICE_COUNT 8
#define CUBE_INDICE_COUNT 36

View File

@ -6,7 +6,7 @@
*/
#pragma once
#include "../libs.h"
#include "../../libs.h"
#define PRIMITIVE_POSITIONS_PER_VERTICE 3
#define PRIMITIVE_COORDINATES_PER_VERTICE 2

View File

@ -5,7 +5,7 @@
#pragma once
#include "../../libs.h"
#include "../primitive.h"
#include "primitive.h"
#define QUAD_VERTICE_COUNT 4
#define QUAD_INDICE_COUNT 6

View File

@ -6,7 +6,7 @@
#pragma once
#include "../../libs.h"
#include "../../util/math.h"
#include "../primitive.h"
#include "primitive.h"
/** How many slices in each cylinder. */
#define SKYWALL_SLICE_COUNT 40

View File

@ -13,26 +13,29 @@ void renderListInit(renderlist_t *list,int32_t width, int32_t height) {
list->passCount = 0;
}
renderpass_t * renderListGetPass(renderlist_t *list, int32_t pass) {
renderpass_t * renderListGetPass(renderlist_t *list, uint8_t pass) {
return list->passes + pass;
}
int32_t renderPassAdd(renderlist_t *list) {
int32_t i = list->passCount++;
renderpass_t *pass = renderListGetPass(list, i);
uint8_t renderPassAdd(renderlist_t *list, shader_t *shader) {
uint8_t i;
renderpass_t *pass;
i = list->passCount++;
pass = renderListGetPass(list, i);
pass->shader = shader;
frameBufferInit(&pass->frame,
list->frame.texture.width, list->frame.texture.height
);
return i;
}
void renderListRenderPass(
renderlist_t *list, engine_t *engine,
camera_t *camera, int32_t pass, renderitem_t *items, int32_t itemCount
renderpass_t * renderListRenderPass(
renderlist_t *list, engine_t *engine, uint8_t pass
) {
int32_t i;
renderpass_t *renderPass;
renderitem_t *item;
renderPass = renderListGetPass(list, pass);
@ -40,17 +43,14 @@ void renderListRenderPass(
frameBufferUse(&renderPass->frame, true);
shaderUse(renderPass->shader);
// "Uniforms"
shaderUseCamera(renderPass->shader, camera);
// Render list
for(i = 0; i < itemCount; i++) {
item = items + i;
item->onRender(list, renderPass, engine, i);
}
return renderPass;
}
void renderListRender(renderlist_t *list, shader_t *shader) {
void renderListRender(
renderlist_t *list, shader_t *shader,
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
shaderuniform_t uniformModel, shaderuniform_t uniformTextures[]
) {
camera_t camera;
int32_t i;
renderpass_t *pass;
@ -64,19 +64,21 @@ void renderListRender(renderlist_t *list, shader_t *shader) {
// Set the shader
shaderUse(shader);
shaderUsePosition(shader, 0,0,0, 0,0,0);
shaderUseCamera(shader, &camera);
shaderUsePosition(shader, uniformModel, 0,0,0, 0,0,0);
shaderUseCamera(shader, uniformView, uniformProjection, &camera);
// Render each pass.
for(i = 0; i < list->passCount; i++) {
pass = renderListGetPass(list, i);
shaderUseTexture(shader, &pass->frame.texture);
shaderUseTexture(shader, uniformTextures[i], &pass->frame.texture);
primitiveDraw(&list->quad, 0, -1);
}
}
void renderListAsBackbuffer(
renderlist_t *list, engine_t *engine, shader_t *shader
renderlist_t *list, engine_t *engine, shader_t *shader,
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
) {
camera_t camera;
@ -89,10 +91,38 @@ void renderListAsBackbuffer(
// Set up the shader.
shaderUse(shader);
shaderUseTexture(shader, &list->frame.texture);
shaderUseCamera(shader, &camera);
shaderUsePosition(shader, 0,0,0, 0,0,0);
shaderUseTexture(shader, uniformTexture, &list->frame.texture);
shaderUseCamera(shader, uniformView, uniformProjection, &camera);
shaderUsePosition(shader, uniformModel, 0,0,0, 0,0,0);
// Render the quad to the back buffer.
primitiveDraw(&list->quad, 0, -1);
}
void renderListResize(renderlist_t *list, int32_t width, int32_t height) {
uint8_t i;
if(
width == list->frame.texture.width &&
height == list->frame.texture.height
) return;
frameBufferDispose(&list->frame);
frameBufferInit(&list->frame, width, height);
for(i = 0; i < list->passCount; i++) {
frameBufferDispose(&list->passes[i].frame);
frameBufferInit(&list->passes[i].frame, width, height);
}
}
void renderListDispose(renderlist_t *list) {
uint8_t i;
for(i = 0; i < list->passCount; i++) {
frameBufferDispose(&list->passes[i].frame);
}
frameBufferDispose(&list->frame);
primitiveDispose(&list->quad);
}

View File

@ -8,11 +8,11 @@
#pragma once
#include "../libs.h"
#include "framebuffer.h"
#include "primitive.h"
#include "shader.h"
#include "primitive/primitive.h"
#include "shader/shader.h"
#include "camera.h"
#include "../engine/engine.h"
#include "primitives/quad.h"
#include "primitive/quad.h"
#include "../util/dynarray.h"
#include "render.h"
@ -28,28 +28,108 @@ typedef struct {
primitive_t quad;
renderpass_t passes[RENDER_PASSES_MAX];
int32_t passCount;
void *user;
uint8_t passCount;
} renderlist_t;
typedef void renderitemcallback_t(
renderlist_t *list, renderpass_t *pass, engine_t *engine, int32_t i
);
typedef struct {
renderitemcallback_t *onRender;
} renderitem_t;
shader_t shader;
shaderuniform_t uniformTexture;
shaderuniform_t uniformView;
shaderuniform_t uniformProjection;
} renderlistbackbuffershader_t;
/**
* Initialize a render pass list.
*
* @param list List to initialize.
* @param width Width of the frame buffer(s).
* @param height Height of the frame buffer(s).
*/
void renderListInit(renderlist_t *list, int32_t width, int32_t height);
renderpass_t * renderListGetPass(renderlist_t *list, int32_t pass);
int32_t renderPassAdd(renderlist_t *list);
void renderListRenderPass(
renderlist_t *list, engine_t *engine,
camera_t *camera, int32_t pass, renderitem_t *items, int32_t itemCount
/**
* Retrieve the render pass at the given index.
*
* @param list List to get the pass from.
* @param pass Render pass index to get.
* @return The render pass at the given index.
*/
renderpass_t * renderListGetPass(renderlist_t *list, uint8_t pass);
/**
* Adds a render pass to the render list.
*
* @param list Render list to add the pass to.
* @param shader Shader to use for the render pass.
* @return The render pass index.
*/
uint8_t renderPassAdd(renderlist_t *list, shader_t *shader);
/**
* Prepare the rendering for a specific render pass. This will set up the
* render pass framebuffer, shader and prepare it for rendering.
*
* @param list List to get the render pass from.
* @param engine Game engine for the render pass.
* @param pass Pass index to render.
* @return The pointer to the render pass that is now active.
*/
renderpass_t * renderListRenderPass(
renderlist_t *list, engine_t *engine, uint8_t pass
);
void renderListRender(renderlist_t *list, shader_t *shader);
/**
* Render a render list. The render list will provide the sum of the textures to
* the given shader as uniforms and then call a single render against a textured
* quad. The given shader will need to decide how to multiply the provided
* texture indexes.
*
* @param list List to render.
* @param shader Shader to use while rendering.
* @param uniformView Shader uniform to receive the view matrix.
* @param uniformProjection Shader uniform to receive the projection matirx.
* @param uniformModel Shader uniform to receive the model matrix.
* @param uniformTextures Array of uniforms for each rendered pass as textures.
*/
void renderListRender(
renderlist_t *list, shader_t *shader,
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
shaderuniform_t uniformModel, shaderuniform_t uniformTextures[]
);
/**
* Takes a previously rendered render list and renders it to the backbuffer.
* You could do this manually, but this method makes the assumption that the
* render list is the only thing to be rendered to the backbuffer (currently).
*
* @param list Render list to render to the backbuffer
* @param engine Engine to use when rendering.
* @param shader Shader to use to render to the backbuffer.
* @param uniformView Shader uniform to receive the view matrix.
* @param uniformProjection Shader uniform to receive the projection matirx.
* @param uniformModel Shader uniform to receive the model matrix.
* @param uniformTexture Shader uniform to receive the texture.
*/
void renderListAsBackbuffer(
renderlist_t *list, engine_t *engine, shader_t *shader
);
renderlist_t *list, engine_t *engine, shader_t *shader,
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
);
/**
* Resize an existing render list and all its render pass frame buffers. This
* will dispose (and clear) the existing frame buffers for both the list and
* each of the passes. Resizing to the same size won't cause an update to occur.
*
* @param list List to update.
* @param width New render list width.
* @param height New render list height.
*/
void renderListResize(renderlist_t *list, int32_t width, int32_t height);
/**
* Dispose a render list entirely.
*
* @param list Render list to dispose.
*/
void renderListDispose(renderlist_t *list);

View File

@ -0,0 +1,63 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "common.h"
void shaderCommonInit(shadercommon_t *shader, char *vert, char *frag) {
shaderInit(&shader->shader, vert, frag);
shader->uniformProjection = shaderGetUniform(
&shader->shader, SHADER_COMMON_UNIFORM_PROJECTION
);
shader->uniformView = shaderGetUniform(
&shader->shader, SHADER_COMMON_UNIFORM_VIEW
);
shader->uniformModel = shaderGetUniform(
&shader->shader, SHADER_COMMON_UNIFORM_MODEL
);
shader->uniformColor = shaderGetUniform(
&shader->shader, SHADER_COMMON_UNIFORM_COLOR
);
shader->uniformTexture = shaderGetUniform(
&shader->shader, SHADER_COMMON_UNIFORM_TEXTURE
);
}
void shaderCommonUseCamera(shadercommon_t *shader, camera_t *camera) {
shaderUseCamera(
&shader->shader, shader->uniformView, shader->uniformProjection, camera
);
}
void shaderCommonUseTexture(shadercommon_t *shader, texture_t *texture) {
shaderUseTexture(&shader->shader, shader->uniformTexture, texture);
}
void shaderCommonUseColor(shadercommon_t *shader, pixel_t color) {
shaderUseColor(&shader->shader, shader->uniformColor, color);
}
void shaderCommonUsePosition(shadercommon_t *shader,
float x, float y, float z,
float pitch, float yaw, float roll
) {
shaderUsePosition(
&shader->shader, shader->uniformModel, x, y, z, pitch, yaw, roll
);
}
void shaderCommonUsePositionAndScale(
shadercommon_t *shader,
float x, float y, float z,
float pitch, float yaw, float roll,
float scaleX, float scaleY, float scaleZ
) {
shaderUsePositionAndScale(
&shader->shader, shader->uniformView,
x, y, z, pitch, yaw, roll, scaleX, scaleY, scaleZ
);
}

View File

@ -0,0 +1,40 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "shader.h"
#include "../texture.h"
#define SHADER_COMMON_UNIFORM_PROJECTION "u_Proj"
#define SHADER_COMMON_UNIFORM_VIEW "u_View"
#define SHADER_COMMON_UNIFORM_MODEL "u_Modl"
#define SHADER_COMMON_UNIFORM_COLOR "u_Colr"
#define SHADER_COMMON_UNIFORM_TEXTURE "u_Text"
typedef struct {
shader_t shader;
shaderuniform_t uniformProjection;
shaderuniform_t uniformView;
shaderuniform_t uniformModel;
shaderuniform_t uniformColor;
shaderuniform_t uniformTexture;
} shadercommon_t;
void shaderCommonInit(shadercommon_t *shader, char *vert, char *frag);
void shaderCommonUseCamera(shadercommon_t *shader, camera_t *camera);
void shaderCommonUseTexture(shadercommon_t *shader, texture_t *texture);
void shaderCommonUseColor(shadercommon_t *shader, pixel_t color);
void shaderCommonUsePosition(shadercommon_t *shader,
float x, float y, float z,
float pitch, float yaw, float roll
);
void shaderCommonUsePositionAndScale(
shadercommon_t *shader,
float x, float y, float z,
float pitch, float yaw, float roll,
float scaleX, float scaleY, float scaleZ
);

View File

@ -83,21 +83,12 @@ void shaderInit(shader_t *shader,
shaderProgram, (GLuint)i, SHADER_UNIFORM_NAME_MAX,
&length, &size, &type, shader->uniforms[i]
);
// TODO: Reset uniforms to zero.
}
// Hold off on this for now
shader->uniProj = shaderGetUniform(shader, SHADER_UNI_PROJ);
shader->uniView = shaderGetUniform(shader, SHADER_UNI_VIEW);
shader->uniText = shaderGetUniform(shader, SHADER_UNI_TEXT);
shader->uniModl = shaderGetUniform(shader, SHADER_UNI_MODL);
shader->uniColr = shaderGetUniform(shader, SHADER_UNI_COLR);
// Bind the shader
shaderUse(shader);
// Reset position
shaderUsePosition(shader, 0, 0, 0, 0, 0, 0);
shaderUseColor(shader, PIXEL_COLOR_WHITE);
}
shaderuniform_t shaderGetUniform(shader_t *shader, char *name) {
@ -118,23 +109,33 @@ void shaderUse(shader_t *shader) {
glUseProgram(shader->shaderProgram);
}
void shaderUseCamera(shader_t *shader, camera_t *camera) {
shaderUseMatrix(shader, shader->uniView, &camera->view);
shaderUseMatrix(shader, shader->uniProj, &camera->projection);
}
void shaderUseTexture(shader_t *shader, texture_t *texture) {
// OpenGL requires us to set the active texure.
glActiveTexture(GL_TEXTURE0);
void shaderUseTexture(
shader_t *shader, shaderuniform_t uniform, texture_t *texture
) {
// TODO: I need to be able to get the texture ID
int32_t i = 0;
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, texture->id);
glUniform1i(shader->uniText, 0);
glUniform1i(uniform, i);
}
void shaderUseMatrix(shader_t *shader,shaderuniform_t uniform,matrix_t *matrix){
void shaderUseMatrix(
shader_t *shader, shaderuniform_t uniform, matrix_t *matrix
) {
glUniformMatrix4fv(uniform, 1, GL_FALSE, matrix->internalMatrix[0]);
}
void shaderUsePosition(shader_t *shader,
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,
float x, float y, float z,
float pitch, float yaw, float roll
) {
@ -147,10 +148,11 @@ void shaderUsePosition(shader_t *shader,
matrixRotate(&matrix, yaw, 0, 1, 0);
matrixRotate(&matrix, roll, 0, 0, 1);
matrixRotate(&matrix, pitch, 1, 0, 0);
shaderUseMatrix(shader, shader->uniModl, &matrix);
shaderUseMatrix(shader, uniform, &matrix);
}
void shaderUsePositionAndScale(shader_t *shader,
void shaderUsePositionAndScale(
shader_t *shader, shaderuniform_t uniform,
float x, float y, float z,
float pitch, float yaw, float roll,
float scaleX, float scaleY, float scaleZ
@ -167,14 +169,14 @@ void shaderUsePositionAndScale(shader_t *shader,
matrixScale(&matrix, scaleX, scaleY, scaleZ);
shaderUseMatrix(shader, shader->uniModl, &matrix);
shaderUseMatrix(shader, uniform, &matrix);
}
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
);
void shaderUseCamera(
shader_t *shader,
shaderuniform_t uniformView, shaderuniform_t uniformProjection,
camera_t *camera
) {
shaderUseMatrix(shader, uniformView, &camera->view);
shaderUseMatrix(shader, uniformProjection, &camera->projection);
}

View File

@ -6,17 +6,11 @@
*/
#pragma once
#include "../libs.h"
#include "matrix.h"
#include "camera.h"
#include "texture.h"
#include "../util/array.h"
#define SHADER_UNI_VIEW "u_View"
#define SHADER_UNI_PROJ "u_Proj"
#define SHADER_UNI_TEXT "u_Text"
#define SHADER_UNI_MODL "u_Modl"
#define SHADER_UNI_COLR "u_Colr"
#include "../../libs.h"
#include "../matrix.h"
#include "../camera.h"
#include "../texture.h"
#include "../../util/array.h"
#define SHADER_UNIFORM_NAME_MAX 24
#define SHADER_UNIFORM_COUNT 8
@ -38,21 +32,6 @@ typedef struct {
/** Pointer to an uploaded shader program linked */
shaderuniform_t shaderProgram;
/** Matrix for the view matrix */
shaderuniform_t uniView;
/** Matrix for the projection matrix */
shaderuniform_t uniProj;
/** Uniform for the current texture */
shaderuniform_t uniText;
/** Uniform for the current model world position */
shaderuniform_t uniModl;
/** Uniform for the color multiplier */
shaderuniform_t uniColr;
char uniformBuffer[SHADER_UNIFORM_NAME_MAX * SHADER_UNIFORM_COUNT];
char *uniforms[SHADER_UNIFORM_COUNT];
int32_t uniformCount;
@ -90,19 +69,17 @@ 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, texture_t *texture);
void shaderUseTexture(
shader_t *shader, shaderuniform_t uniform, texture_t *texture
);
/**
* Set's a specific shader uniform to a matrix.
@ -111,12 +88,25 @@ void shaderUseTexture(shader_t *shader, texture_t *texture);
* @param uniform Uniform on the shader to set.
* @param matrix Matrix to apply.
*/
void shaderUseMatrix(shader_t *shader,shaderuniform_t uniform,matrix_t *matrix);
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);
/**
* 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).
@ -124,17 +114,18 @@ void shaderUseMatrix(shader_t *shader,shaderuniform_t uniform,matrix_t *matrix);
* @param yaw Yaw of the object (local space).
* @param roll Roll of the object (local space).
*/
void shaderUsePosition(shader_t *shader,
void shaderUsePosition(
shader_t *shader, shaderuniform_t uniform,
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).
@ -145,11 +136,23 @@ void shaderUsePosition(shader_t *shader,
* @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,
void shaderUsePositionAndScale(
shader_t *shader, shaderuniform_t uniform,
float x, float y, float z,
float pitch, float yaw, float roll,
float scaleX, float scaleY, float scaleZ
);
void shaderUseColor(shader_t *shader, pixel_t color);
/**
* 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
);

View File

@ -6,8 +6,8 @@
#pragma once
#include "../libs.h"
#include "../util/math.h"
#include "primitive.h"
#include "primitives/quad.h"
#include "primitive/primitive.h"
#include "primitive/quad.h"
/** Definition of a Sprite Batch. */
typedef struct {

View File

@ -7,7 +7,7 @@
#pragma once
#include "../libs.h"
#include "../display/shader.h"
#include "../display/shader/shader.h"
#include "../display/texture.h"
#include "../display/font.h"

View File

@ -42,6 +42,7 @@ void assetManagerInit(assetmanager_t *manager) {
manager->itemCount = 0;
manager->finished = false;
manager->holderCount = 0;
manager->running = false;
}
float assetManagerProgressGet(assetmanager_t *manager) {
@ -127,6 +128,8 @@ void assetManagerDispose(assetmanager_t *man) {
// Thread Management
void assetManagerStart(assetmanager_t *manager) {
if(manager->running) return;
manager->running = true;
threadStart(&manager->thread);
}
@ -146,7 +149,7 @@ int32_t _assetManagerThread(thread_t *thread) {
// Only bother with ASYNC items
if(definition->loadAsync == NULL) continue;
// Are we already loading or already tried to load?
// Are we already loading, not ready, or already tried to load?
if(item->state != ASSET_MANAGER_STATE_PENDING) continue;
// Begin loading
@ -162,6 +165,7 @@ int32_t _assetManagerThread(thread_t *thread) {
}
manager->finished = assetManagerProgressGet(manager) >= 1.0f;
manager->running = false;
return 0;
}
@ -172,10 +176,21 @@ void assetManagerUpdate(assetmanager_t *manager) {
assetmanagerloaderdefinition_t *definition;
bool result;
// Autostart
if(assetManagerProgressGet(manager) < 1.0f && !manager->running) {
assetManagerStart(manager);
}
for(i = 0; i < manager->itemCount; i++) {
item = manager->items + i;
definition = ASSET_MANAGER_LOADERS + item->type;
// Update not ready state (Synchronously)
if(item->state == ASSET_MANAGER_STATE_NOT_READY) {
item->state = ASSET_MANAGER_STATE_PENDING;
continue;
}
// If requires ASYNC loading, then confirm it has finished loading.
if(definition->loadAsync != NULL) {
if(item->state != ASSET_MANAGER_STATE_ASYNC_DONE) continue;
@ -217,7 +232,7 @@ assetmanageritem_t * assetManagerItemGet(assetmanager_t *man, char *key) {
assetmanageritem_t * assetManagerItemAdd(assetmanager_t *manager, char *key) {
// Check if key already exists.
assetmanageritem_t *item = manager->items + manager->itemCount++;
item->state = ASSET_MANAGER_STATE_PENDING;
item->state = ASSET_MANAGER_STATE_NOT_READY;
memcpy(item->key, key, strlen(key) + 1);
item->holderCount = 0x00;
return item;

View File

@ -10,7 +10,7 @@
#include "../display/font.h"
#include "../display/texture.h"
#include "../display/scaledtexture.h"
#include "../display/shader.h"
#include "../display/shader/shader.h"
#include "../engine/thread.h"
#include "../util/array.h"
#include "asset.h"
@ -21,13 +21,14 @@
#define ASSET_MANAGER_HOLDERS_MAX 8
#define ASSET_MANAGER_STATE_PENDING 0x00
#define ASSET_MANAGER_STATE_ASYNC_LOADING 0x01
#define ASSET_MANAGER_STATE_ASYNC_ERROR 0x02
#define ASSET_MANAGER_STATE_ASYNC_DONE 0x03
#define ASSET_MANAGER_STATE_SYNC_LOADING 0x04
#define ASSET_MANAGER_STATE_SYNC_ERROR 0x05
#define ASSET_MANAGER_STATE_SYNC_DONE 0x06
#define ASSET_MANAGER_STATE_NOT_READY 0x00
#define ASSET_MANAGER_STATE_PENDING 0x01
#define ASSET_MANAGER_STATE_ASYNC_LOADING 0x02
#define ASSET_MANAGER_STATE_ASYNC_ERROR 0x03
#define ASSET_MANAGER_STATE_ASYNC_DONE 0x04
#define ASSET_MANAGER_STATE_SYNC_LOADING 0x05
#define ASSET_MANAGER_STATE_SYNC_ERROR 0x06
#define ASSET_MANAGER_STATE_SYNC_DONE 0x07
#define ASSET_MANAGER_TYPE_TEXTURE 0x00
#define ASSET_MANAGER_TYPE_FONT 0x01
@ -105,6 +106,7 @@ typedef struct {
uint8_t itemCount;
assetmanagerowner_t holders[ASSET_MANAGER_HOLDERS_MAX];
uint8_t holderCount;
bool running;
} assetmanager_t;
// Constants
@ -126,7 +128,7 @@ void assetManagerInit(assetmanager_t *manager);
*/
float assetManagerProgressGet(assetmanager_t *manager);
uint8_t assetManagerHolderCreate(assetmanager_t *man);
assetmanagerowner_t assetManagerHolderCreate(assetmanager_t *man);
void assetManagerHolderRelease(assetmanager_t *man, uint8_t hold);
void assetManagerDisposeReleased(assetmanager_t *man);
void assetManagerDispose(assetmanager_t *man);

View File

@ -12,7 +12,7 @@
#include "../../vn/vnscene.h"
#include "../../util/array.h"
#include "../../engine/thread.h"
#include "../../scenes/loadingscene.h"
#include "../../scene/loadingscene.h"
#include "pokergame.h"
#include "pokergameassets.h"
#include "pokerui.h"

View File

@ -11,7 +11,7 @@
#include "../../vn/conversation/talk.h"
#include "../../vn/vnscene.h"
#include "../../util/array.h"
#include "../../scenes/loadingscene.h"
#include "../../scene/loadingscene.h"
#include "pokergameassets.h"
#include "pokerui.h"
#include "pokerworld.h"

View File

@ -8,52 +8,67 @@
#include "game.h"
bool sandboxGameInit(sandboxgame_t *game) {
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);
uint8_t i;
game->assetOwner = assetManagerHolderCreate(&game->engine.assetManager);
// Initialize the scene.
sceneInit(&game->scene, &game->engine);
assetManagerLoadFont(
&game->engine.assetManager, game->assetOwner,
&game->font, "fonts/opensans/OpenSans-Regular.ttf"
);
assetManagerLoadShader(
&game->engine.assetManager, game->assetOwner,
// Load Shader
assetManagerLoadShader(&game->engine.assetManager, game->scene.assetOwner,
&game->shader, "shaders/textured.vert", "shaders/textured.frag"
);
// Load the texture
assetManagerLoadScaledTexture(
&game->engine.assetManager, game->assetOwner,
&game->engine.assetManager, game->scene.assetOwner,
&game->st, "poker/characters/sammy", "sprite"
);
assetManagerLoadTextureScale(
&game->engine.assetManager, game->assetOwner,
&game->engine.assetManager, game->scene.assetOwner,
&game->st, &game->texture, 0
);
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);
i = renderPassAdd(&game->scene.renderList, &game->shader);
return true;
}
void sandboxGameUpdate(sandboxgame_t *game) {
camera_t camera;
float n;
n = assetManagerProgressGet(&game->engine.assetManager);
if(n < 1.0f) return;
// First pass
sceneRenderStart(&game->scene);
renderListRenderPass(&game->scene.renderList, &game->engine, 0);
cameraOrtho(&camera,
0, game->engine.render.width,
game->engine.render.height, 0,
0.01f, 1000.0f
);
cameraLookAt(&camera, 0,0,10, 0,0,0);
uint8_t uniView = shaderGetUniform(&game->shader, "u_View");
uint8_t uniProj = shaderGetUniform(&game->shader, "u_Proj");
uint8_t uniModel = shaderGetUniform(&game->shader, "u_Modl");
uint8_t uniColor = shaderGetUniform(&game->shader, "u_Colr");
uint8_t uniTexture = shaderGetUniform(&game->shader, "u_Text");
shaderUse(&game->shader);
shaderUseCamera(&game->shader, &camera);
shaderUseTexture(&game->shader, &game->texture);
shaderUsePosition(&game->shader, 0,0,0, 0,0,0);
shaderUseCamera(&game->shader, uniView, uniProj, &camera);
shaderUseColor(&game->shader, uniColor, PIXEL_COLOR_WHITE);
shaderUseTexture(&game->shader, uniTexture, &game->texture);
shaderUsePosition(&game->shader, uniModel, 0,0,0, 0,0,0);
primitiveDraw(&game->quad, 0, -1);
// sceneRenderEnd(&game->scene);
}
void sandboxGameDispose(sandboxgame_t *game) {
assetManagerHolderRelease(&game->engine.assetManager, game->assetOwner);
primitiveDispose(&game->quad);
sceneDispose(&game->scene);
// assetManagerHolderRelease(&game->engine.assetManager, game->assetOwner);
// primitiveDispose(&game->quad);
}

View File

@ -9,9 +9,9 @@
#include "../../libs.h"
#include "../../display/camera.h"
#include "../../display/font.h"
#include "../../display/shader.h"
#include "../../display/primitive.h"
#include "../../display/primitives/quad.h"
#include "../../display/shader/shader.h"
#include "../../display/primitive/primitive.h"
#include "../../display/primitive/quad.h"
#include "../../display/scaledtexture.h"
#include "../../file/asset.h"
#include "../../ui/label.h"
@ -19,16 +19,16 @@
#include "../../file/assetmanager.h"
#include "../../file/xml.h"
#include "../../engine/engine.h"
#include "../../display/renderlist.h"
#include "../scene/scene.h"
typedef struct {
engine_t engine;
uint8_t assetOwner;
engine_t engine;
scene_t scene;
shader_t shader;
font_t font;
texture_t texture;
primitive_t quad;
scaledtexture_t st;
} sandboxgame_t;

35
src/scene/scene.c Normal file
View File

@ -0,0 +1,35 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "scene.h"
void sceneInit(scene_t *scene, engine_t *engine) {
scene->engine = engine;
scene->assetOwner = assetManagerHolderCreate(&engine->assetManager);
renderListInit(&scene->renderList,
(int32_t)engine->render.width, (int32_t)engine->render.height
);
}
void sceneRenderStart(scene_t *scene) {
renderListResize(&scene->renderList,
(int32_t)scene->engine->render.width, (int32_t)scene->engine->render.height
);
}
void sceneRenderEnd(
scene_t *scene, shader_t *shaderRenderList, shader_t *shaderBackBuffer
) {
if(shaderRenderList == NULL || shaderBackBuffer == NULL) return;
// renderListRender(&scene->renderList, shaderRenderList);
// renderListAsBackbuffer(&scene->renderList, scene->engine, shaderBackBuffer);
}
void sceneDispose(scene_t *scene) {
assetManagerHolderRelease(&scene->engine->assetManager, scene->assetOwner);
renderListDispose(&scene->renderList);
}

24
src/scene/scene.h Normal file
View File

@ -0,0 +1,24 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "../file/assetmanager.h"
#include "../engine/engine.h"
#include "../display/renderlist.h"
#include "../display/shader/shader.h"
typedef struct {
engine_t *engine;
assetmanagerowner_t assetOwner;
renderlist_t renderList;
} scene_t;
void sceneInit(scene_t *scene, engine_t *engine);
void sceneRenderStart(scene_t *scene);
void sceneRenderEnd(scene_t *scene);
void sceneDispose(scene_t *scene);

View File

@ -7,217 +7,5 @@
#include "display.h"
scripterreturn_t _scriptPrimitiveCreate(scriptercontext_t *ctx) {
primitive_t *primitive = malloc(sizeof(primitive_t));
duk_push_pointer(ctx, primitive);
return 1;
}
scripterreturn_t _scriptPrimitiveInit(scriptercontext_t *ctx) {
primitive_t *primitive = duk_to_pointer(ctx, 0);
int32_t verticeCount = duk_to_int32(ctx, 1);
int32_t indiceCount = duk_to_int32(ctx, 2);
primitiveInit(primitive, verticeCount, indiceCount);
return 0;
}
scripterreturn_t _scriptPrimitiveDraw(scriptercontext_t *context) {
primitive_t *primitive = duk_to_pointer(context, 0);
int32_t start = duk_to_int32(context, 1);
int32_t count = duk_to_int32(context, 2);
primitiveDraw(primitive, start, count);
return 0;
}
scripterreturn_t _scriptPrimitiveDispose(scriptercontext_t *context) {
primitive_t *primitive = duk_to_pointer(context, 0);
primitiveDispose(primitive);
free(primitive);
return 0;
}
scripterreturn_t _scriptQuadInit(scriptercontext_t *ctx) {
quadInit(duk_to_pointer(ctx, 0), (float)duk_to_number(ctx, 1),
(float)duk_to_number(ctx, 2), (float)duk_to_number(ctx, 3),
(float)duk_to_number(ctx, 4), (float)duk_to_number(ctx, 5),
(float)duk_to_number(ctx, 6), (float)duk_to_number(ctx, 7),
(float)duk_to_number(ctx, 8), (float)duk_to_number(ctx, 9)
);
return 0;
}
scripterreturn_t _scriptCameraCreate(scriptercontext_t *ctx) {
camera_t *camera = malloc(sizeof(camera_t));
duk_push_pointer(ctx, camera);
return 1;
}
scripterreturn_t _scriptCameraLookAt(scriptercontext_t *ctx) {
cameraLookAt(duk_to_pointer(ctx, 0),
(float)duk_to_number(ctx, 1),
(float)duk_to_number(ctx, 2),
(float)duk_to_number(ctx, 3),
(float)duk_to_number(ctx, 4),
(float)duk_to_number(ctx, 5),
(float)duk_to_number(ctx, 6)
);
return 0;
}
scripterreturn_t _scriptCameraLook(scriptercontext_t *ctx) {
cameraLook(
duk_to_pointer(ctx, 0),
(float)duk_to_number(ctx, 1),
(float)duk_to_number(ctx, 2),
(float)duk_to_number(ctx, 3),
(float)duk_to_number(ctx, 4),
(float)duk_to_number(ctx, 5),
(float)duk_to_number(ctx, 6)
);
return 0;
}
scripterreturn_t _scriptCameraPerspective(scriptercontext_t *ctx) {
cameraPerspective(
duk_to_pointer(ctx, 0),
(float)duk_to_number(ctx, 1),
(float)duk_to_number(ctx, 2),
(float)duk_to_number(ctx, 3),
(float)duk_to_number(ctx, 4)
);
return 0;
}
scripterreturn_t _scriptCameraOrtho(scriptercontext_t *ctx) {
cameraOrtho(
duk_to_pointer(ctx, 0),
(float)duk_to_number(ctx, 1),
(float)duk_to_number(ctx, 2),
(float)duk_to_number(ctx, 3),
(float)duk_to_number(ctx, 4),
(float)duk_to_number(ctx, 5),
(float)duk_to_number(ctx, 6)
);
return 0;
}
scripterreturn_t _scriptCameraDispose(scriptercontext_t *ctx) {
camera_t *camera = duk_to_pointer(ctx, 0);
free(camera);
return 0;
}
scripterreturn_t _scriptShaderCreate(scriptercontext_t *ctx) {
shader_t *shader = malloc(sizeof(shader_t));
duk_push_pointer(ctx, shader);
return 1;
}
scripterreturn_t _scriptShaderInit(scriptercontext_t *ctx) {
shader_t *shader = duk_to_pointer(ctx, 0);
char *vertex = duk_to_string(ctx, 1);
char *frag = duk_to_string(ctx, 2);
shaderInit(shader, vertex, frag);
return 0;
}
scripterreturn_t _scriptShaderDispose(scriptercontext_t *ctx) {
shader_t *shader = duk_to_pointer(ctx, 0);
shaderDispose(shader);
free(shader);
return 0;
}
scripterreturn_t _scriptShaderUse(scriptercontext_t *ctx) {
shaderUse(duk_to_pointer(ctx, 0));
return 0;
}
scripterreturn_t _scriptShaderUseCamera(scriptercontext_t *ctx) {
shaderUseCamera(duk_to_pointer(ctx, 0), duk_to_pointer(ctx, 1));
return 0;
}
scripterreturn_t _scriptShaderUseTexture(scriptercontext_t *ctx) {
shaderUseTexture(duk_to_pointer(ctx, 0), duk_to_pointer(ctx, 1));
return 0;
}
scripterreturn_t _scriptShaderUsePosition(scriptercontext_t *ctx) {
shaderUsePosition(
duk_to_pointer(ctx, 0),
(float)duk_to_number(ctx, 1),
(float)duk_to_number(ctx, 2),
(float)duk_to_number(ctx, 3),
(float)duk_to_number(ctx, 4),
(float)duk_to_number(ctx, 5),
(float)duk_to_number(ctx, 6)
);
return 0;
}
scripterreturn_t _scriptShaderUsePositionAndScale(scriptercontext_t *ctx) {
shaderUsePositionAndScale(
duk_to_pointer(ctx, 0),
(float)duk_to_number(ctx, 1),
(float)duk_to_number(ctx, 2),
(float)duk_to_number(ctx, 3),
(float)duk_to_number(ctx, 4),
(float)duk_to_number(ctx, 5),
(float)duk_to_number(ctx, 6),
(float)duk_to_number(ctx, 7),
(float)duk_to_number(ctx, 8),
(float)duk_to_number(ctx, 9)
);
return 0;
}
scripterreturn_t _scriptTextureCreate(scriptercontext_t *ctx) {
texture_t *texture = malloc(sizeof(texture_t));
duk_push_pointer(ctx, texture);
return 1;
}
scripterreturn_t _scriptTextureDispose(scriptercontext_t *ctx) {
texture_t *texture = duk_to_pointer(ctx, 0);
textureDispose(texture);
free(texture);
return 0;
}
void scriptsApiDisplay(scripter_t *s) {
scripterDefineMethod(s, "primitiveCreate", 0, &_scriptPrimitiveCreate);
scripterDefineMethod(s, "primitiveInit", 3, &_scriptPrimitiveInit);
scripterDefineMethod(s, "primitiveDraw", 3, &_scriptPrimitiveDraw);
scripterDefineMethod(s, "primitiveDispose",1,&_scriptPrimitiveDispose);
scripterDefineMethod(s, "quadInit", 10, &_scriptQuadInit);
scripterDefineMethod(s, "cameraCreate", 0, &_scriptCameraCreate);
scripterDefineMethod(s, "cameraLookAt", 7, &_scriptCameraLookAt);
scripterDefineMethod(s, "cameraLook", 7, &_scriptCameraLook);
scripterDefineMethod(s, "cameraPerspective", 5, &_scriptCameraPerspective);
scripterDefineMethod(s, "cameraOrtho", 7, &_scriptCameraOrtho);
scripterDefineMethod(s, "cameraDispose", 1, &_scriptCameraDispose);
scripterDefineMethod(s, "shaderCreate", 0, &_scriptShaderCreate);
scripterDefineMethod(s, "shaderInit", 3, &_scriptShaderInit);
scripterDefineMethod(s, "shaderDispose", 1, &_scriptShaderDispose);
scripterDefineMethod(s, "shaderUse", 1, &_scriptShaderUse);
scripterDefineMethod(s, "shaderUseTexture", 2, &_scriptShaderUseTexture);
scripterDefineMethod(s, "shaderUseCamera", 2, &_scriptShaderUseCamera);
scripterDefineMethod(s, "shaderUsePosition", 7, &_scriptShaderUsePosition);
scripterDefineMethod(
s, "shaderUsePositionAndScale", 10, &_scriptShaderUsePositionAndScale
);
scripterDefineMethod(s, "textureCreate", 0, &_scriptTextureCreate);
scripterDefineMethod(s, "textureDispose", 1, &_scriptTextureDispose);
}

View File

@ -8,9 +8,8 @@
#pragma once
#include "../../libs.h"
#include "../scripter.h"
#include "../../display/primitives/cube.h"
#include "../../display/primitives/quad.h"
#include "../../display/primitive/cube.h"
#include "../../display/primitive/quad.h"
#include "../../display/camera.h"
#include "../../display/shader.h"
void scriptsApiDisplay(scripter_t *scripter);

View File

@ -100,10 +100,14 @@ void frameSetInnerSize(frame_t *frame, float width, float height) {
);
}
void frameRender(frame_t *frame, shader_t *shader, float x, float y) {
void frameRender(
frame_t *frame, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
) {
if(frame->texture == NULL) return;
shaderUsePosition(shader, x, y, 0, 0, 0, 0);
shaderUseTexture(shader, frame->texture);
shaderUsePosition(shader, uniformModel, x, y, 0, 0, 0, 0);
shaderUseTexture(shader, uniformTexture, frame->texture);
primitiveDraw(&frame->primitive, 0, -1);
}

View File

@ -7,9 +7,9 @@
#pragma once
#include "../libs.h"
#include "../display/shader.h"
#include "../display/primitive.h"
#include "../display/primitives/quad.h"
#include "../display/shader/shader.h"
#include "../display/primitive/primitive.h"
#include "../display/primitive/quad.h"
#include "../display/font.h"
/** Size of the border (in pixels) on each edge */
@ -54,10 +54,16 @@ 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, float x, float y);
void frameRender(
frame_t *frame, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
);
/**
* Cleanup a previously initialized frame.

View File

@ -30,10 +30,12 @@ void framedTextMenuUpdate(framedtextmenu_t *menu, engine_t *engine) {
}
void framedTextMenuRender(
framedtextmenu_t *menu, shader_t *shader, float x, float y
framedtextmenu_t *menu, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
) {
frameRender(&menu->frame, shader, x, y);
textMenuRender(&menu->menu, shader, x, y);
frameRender(&menu->frame, shader, uniformModel, uniformTexture, x, y);
textMenuRender(&menu->menu, shader, uniformModel, uniformTexture, x, y);
}
void framedTextMenuDispose(framedtextmenu_t *menu) {

View File

@ -52,11 +52,15 @@ 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, float x, float y
framedtextmenu_t *menu, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
);
/**

View File

@ -46,14 +46,18 @@ void imageSetTextureAndCrop(image_t *image, texture_t *texture,
);
}
void imageRender(image_t *image, shader_t *shader, float x, float y) {
void imageRender(
image_t *image, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
) {
if(image->texture == NULL) return;
shaderUsePositionAndScale(shader,
shaderUsePositionAndScale(shader, uniformModel,
x,y,0,
0,0,0,
image->width, image->height, 1
);
shaderUseTexture(shader, image->texture);
shaderUseTexture(shader, uniformTexture, image->texture);
primitiveDraw(&image->quad, 0, -1);
}

View File

@ -7,9 +7,9 @@
#pragma once
#include "../libs.h"
#include "../display/primitive.h"
#include "../display/primitives/quad.h"
#include "../display/shader.h"
#include "../display/primitive/primitive.h"
#include "../display/primitive/quad.h"
#include "../display/shader/common.h"
typedef struct {
texture_t *texture;
@ -52,10 +52,16 @@ 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, float x, float y);
void imageRender(
image_t *image, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
);
/**
* Cleanup a previously initialized image.

View File

@ -27,10 +27,14 @@ void labelSetText(label_t *label, font_t *font, char *text) {
);
}
void labelRender(label_t *label, shader_t *shader, float x, float y) {
void labelRender(
label_t *label, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
) {
if(label->primitive.verticeCount == 0) return;
shaderUsePosition(shader, x,y,0, 0,0,0);
shaderUseTexture(shader, &label->font->texture);
shaderUsePosition(shader, uniformModel, x,y,0, 0,0,0);
shaderUseTexture(shader, uniformTexture, &label->font->texture);
primitiveDraw(&label->primitive, 0, -1);
}

View File

@ -5,8 +5,8 @@
#pragma once
#include "../libs.h"
#include "../display/shader.h"
#include "../display/primitive.h"
#include "../display/shader/shader.h"
#include "../display/primitive/primitive.h"
#include "../display/font.h"
/** Representation of a Label UI Element */
@ -38,10 +38,16 @@ 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, float x, float y);
void labelRender(
label_t *label, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
);
/**
* Dispose a previously created label.

View File

@ -20,13 +20,17 @@ void rectangleSetColor(rectangle_t *rectangle, pixel_t color) {
);
}
void rectangleRender(rectangle_t *rect, shader_t *shader, float x, float y) {
shaderUsePositionAndScale(shader,
void rectangleRender(
rectangle_t *rect, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
) {
shaderUsePositionAndScale(shader, uniformModel,
x, y, 0,
0, 0, 0,
rect->width, rect->height, 1
);
shaderUseTexture(shader, &rect->texture);
shaderUseTexture(shader, uniformTexture, &rect->texture);
primitiveDraw(&rect->quad, 0, -1);
}

View File

@ -8,9 +8,9 @@
#pragma once
#include "../libs.h"
#include "../display/texture.h"
#include "../display/shader.h"
#include "../display/primitive.h"
#include "../display/primitives/quad.h"
#include "../display/shader/shader.h"
#include "../display/primitive/primitive.h"
#include "../display/primitive/quad.h"
typedef struct {
float width, height;
@ -22,6 +22,10 @@ void rectangleInit(rectangle_t *rectangle);
void rectangleSetColor(rectangle_t *rectangle, pixel_t color);
void rectangleRender(rectangle_t *rect, shader_t *shader, float x, float y);
void rectangleRender(
rectangle_t *rect, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
);
void rectangleDispose(rectangle_t *rectangle);

View File

@ -35,7 +35,11 @@ menuitem_t * textMenuAdd(textmenu_t *menu, char *item) {
return menuAdd(&menu->menu);
}
void textMenuRender(textmenu_t *menu, shader_t *shader, float x, float y) {
void textMenuRender(
textmenu_t *menu, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
) {
uint8_t i;
label_t *label;
menuitem_t *item;
@ -48,7 +52,9 @@ void textMenuRender(textmenu_t *menu, shader_t *shader, float x, float y) {
&menu->grid, item->x, item->y, item->width, item->height,
&gx, &gy, &menu->rectangle.width, &menu->rectangle.height
);
rectangleRender(&menu->rectangle, shader, x + gx, y + gy);
rectangleRender(
&menu->rectangle, shader, uniformModel, uniformTexture, x + gx, y + gy
);
// Render labels
for(i = 0; i < menu->menu.itemCount; i++) {
@ -60,7 +66,9 @@ void textMenuRender(textmenu_t *menu, shader_t *shader, float x, float y) {
ALIGN_POS_START | ALIGN_SIZE_ORIGINAL,
label->info.width, label->info.height
);
labelRender(label, shader, align.x + x, align.y + y);
labelRender(
label, shader, uniformModel, uniformTexture, align.x + x, align.y + y
);
}
}

View File

@ -56,10 +56,16 @@ 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, float x, float y);
void textMenuRender(
textmenu_t *menu, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
);
/**
* Dispose/Cleanup a text menu.

View File

@ -33,9 +33,11 @@ void vnConversationUpdate(vnconversation_t *convo, engine_t *engine) {
}
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(&convo->textbox, shader,
vnTextBoxRender(
&convo->textbox, shader, uniformModel, uniformTexture,
0, engine->render.height - convo->textbox.height
);
}

View File

@ -69,7 +69,8 @@ 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
vnconversation_t *convo, engine_t *engine, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
);
/**

View File

@ -77,13 +77,17 @@ void vnTextBoxUpdate(vntextbox_t *box, engine_t *engine) {
box->lineCurrent += box->linesMax;
}
void vnTextBoxRender(vntextbox_t *box, shader_t *shader, float x, float y) {
void vnTextBoxRender(
vntextbox_t *box, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
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, x, y);
frameRender(&box->frame, shader, uniformModel, uniformTexture, x, y);
// Determine where we're rendering the indices up to.
charCount = (int32_t)box->textScroll;
@ -112,11 +116,11 @@ void vnTextBoxRender(vntextbox_t *box, shader_t *shader, float x, float y) {
if(charCount < 1) return;
// Render the Text Box
shaderUsePosition(shader,
shaderUsePosition(shader, uniformModel,
x + FRAME_BORDER_SIZE, y - yOffset + FRAME_BORDER_SIZE, 0,
0,0,0
);
shaderUseTexture(shader, &box->font->texture);
shaderUseTexture(shader, uniformTexture, &box->font->texture);
primitiveDraw(&box->primitive, charStart, charCount);
}

View File

@ -7,11 +7,11 @@
#pragma once
#include "../../libs.h"
#include "../../display/primitive.h"
#include "../../display/shader.h"
#include "../../display/primitive/primitive.h"
#include "../../display/shader/shader.h"
#include "../../display/animation/timeline.h"
#include "../../display/font.h"
#include "../../display/primitives/quad.h"
#include "../../display/primitive/quad.h"
#include "../../input/input.h"
#include "../../ui/frame.h"
#include "../../engine/engine.h"
@ -94,10 +94,16 @@ 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, float x, float y);
void vnTextBoxRender(
vntextbox_t *box, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture,
float x, float y
);
/**
* Disposes a previously created Visual Novel Text Box.

View File

@ -165,13 +165,16 @@ void vnCharacterLayerSetFrame(vncharacter_t *character, uint8_t l, uint8_t f) {
);
}
void vnCharacterRender(vncharacter_t *character, shader_t *shader) {
shaderUsePositionAndScale(shader,
void vnCharacterRender(
vncharacter_t *character, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
) {
shaderUsePositionAndScale(shader, uniformModel,
character->x, character->y, character->z,
character->pitch, character->yaw, character->roll,
character->scaleX, character->scaleY, 1
);
shaderUseTexture(shader, character->texture);
shaderUseTexture(shader, uniformTexture, character->texture);
primitiveDraw(
&character->primitive, 0, character->layerCount * QUAD_INDICE_COUNT
);

View File

@ -9,9 +9,9 @@
#include "../libs.h"
#include "../display/texture.h"
#include "../display/tileset.h"
#include "../display/primitive.h"
#include "../display/shader.h"
#include "../display/primitives/quad.h"
#include "../display/primitive/primitive.h"
#include "../display/shader/shader.h"
#include "../display/primitive/quad.h"
#include "../display/animation/animation.h"
#include "../engine/engine.h"
#include "../display/animation/easing.h"
@ -58,6 +58,9 @@ 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);
void vnCharacterRender(
vncharacter_t *character, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
);
void vnCharacterDispose(vncharacter_t *character);

View File

@ -47,7 +47,10 @@ void vnSceneDispose(vnscene_t *scene) {
vnConversationDispose(&scene->conversation);
}
void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) {
void vnSceneRenderWorld(
vnscene_t *scene, engine_t *engine, shader_t *shader,
shaderuniform_t uniformView, shaderuniform_t uniformProjection
) {
// Adjust Camera Position.
cameraLookAtStruct(&scene->camera, scene->cameraLook);
@ -58,19 +61,26 @@ void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) {
);
// Update Shader
shaderUseCamera(shader, &scene->camera);
shaderUseCamera(shader, uniformView, uniformProjection, &scene->camera);
}
void vnSceneRenderCharacters(vnscene_t *scene, shader_t *shader) {
void vnSceneRenderCharacters(
vnscene_t *scene, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
) {
uint8_t i;
// Render each character
for(i = 0; i < scene->characterCount; i++) {
vnCharacterRender(scene->characters + i, shader);
vnCharacterRender(scene->characters+i,shader,uniformModel,uniformTexture);
}
}
void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, 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
) {
// 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;
@ -91,10 +101,12 @@ void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader) {
);
// Update Shader
shaderUseCamera(shader, &scene->camera);
shaderUseCamera(shader, uniformView, uniformProjection, &scene->camera);
// Render Conversation Element
vnConversationRender(&scene->conversation, engine, shader);
vnConversationRender(
&scene->conversation, engine, shader, uniformModel, uniformTexture
);
}
void vnSceneLookAt(vnscene_t *scene,

View File

@ -11,7 +11,7 @@
#include "conversation/vnconversation.h"
#include "ui/vntextbox.h"
#include "../display/camera.h"
#include "../display/shader.h"
#include "../display/shader/shader.h"
#include "../display/animation/timeline.h"
#include "../display/animation/easing.h"
#include "../util/math.h"
@ -44,11 +44,21 @@ void vnSceneUpdate(vnscene_t *scene, engine_t *engine);
void vnSceneDispose(vnscene_t *scene);
void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader);
void vnSceneRenderWorld(
vnscene_t *scene, engine_t *engine, shader_t *shader,
shaderuniform_t uniformView, shaderuniform_t uniformProjection
);
void vnSceneRenderCharacters(vnscene_t *scene, shader_t *shader);
void vnSceneRenderCharacters(
vnscene_t *scene, shader_t *shader,
shaderuniform_t uniformModel, shaderuniform_t uniformTexture
);
void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, 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 vnSceneLookAt(vnscene_t *scene,
float x, float y, float z, float lookX, float lookY, float lookZ