Render pipeline working.

This commit is contained in:
2021-05-20 22:47:26 -07:00
parent 06facdbba6
commit 8f124b04bd
11 changed files with 53 additions and 41 deletions

View File

@ -19,6 +19,11 @@ typedef struct {
/** Engine for the game */
engine_t engine;
texture_t texture;
shader_t shader;
primitive_t primitive;
camera_t camera;
/** Poker Game State */
poker_t poker;
} game_t;

View File

@ -19,9 +19,9 @@ void renderInit() {
glDepthFunc(GL_LEQUAL);
}
void renderFrameStart() {
void renderFrameStart(render_t *render) {
// Clear the frame buffer.
frameBufferUse(NULL, true);
frameBufferUnbind(render, true);
}
void renderDispose() {

View File

@ -15,8 +15,9 @@ void renderInit();
/**
* Render a single frame of the render loop. The renderer is not (currently)
* responsible for render looping.
* @param render The render manager
*/
void renderFrameStart();
void renderFrameStart(render_t *render);
/**
* Cleanup a render context.

View File

@ -7,7 +7,7 @@
#include "shader.h"
void shaderCompile(shader_t *shader,
void shaderInit(shader_t *shader,
char *vertexShaderSource, char* fragmentShaderSource
) {
int isSuccess, maxLength;
@ -27,7 +27,7 @@ void shaderCompile(shader_t *shader,
glGetShaderInfoLog(shaderVertex, maxLength, &maxLength, error);
printf("Failed to compile vertex shader %s\n", error);
free(error);
return NULL;
return;
}
// Now load the Frag shader
@ -42,7 +42,7 @@ void shaderCompile(shader_t *shader,
printf("Failed to compile fragment shader %s\n", error);
free(error);
glDeleteShader(shaderVertex);
return NULL;
return;
}
// Now create the shader program.
@ -61,7 +61,7 @@ void shaderCompile(shader_t *shader,
free(error);
glDeleteShader(shaderVertex);
glDeleteShader(shaderFragment);
return NULL;
return;
}
// Everything is okay, let's create the encapsulated shader.
@ -79,9 +79,6 @@ void shaderCompile(shader_t *shader,
// Reset position
shaderUsePosition(shader, 0, 0, 0, 0, 0, 0);
// Fetch the uniforms.
return shader;
}
void shaderDispose(shader_t *shader) {

View File

@ -41,8 +41,6 @@ void textureInit(texture_t *texture, int32_t width, int32_t height,
}
glBindTexture(GL_TEXTURE_2D, 0);
return texture;
}
void textureBufferPixels(texture_t *texture,

View File

@ -45,8 +45,6 @@ void tilesetInit(tileset_t *tileset,
tileset->divisions[i].y1 = tileset->divisions[i].y0 + tdivY;
}
}
return tileset;
}
tilesetdiv_t tilesetGetDivision(tileset_t *tileset,int32_t column,int32_t row) {

View File

@ -16,7 +16,7 @@ void engineInit(engine_t *engine, game_t *game) {
void engineUpdateStart(engine_t *engine, game_t *game, float delta) {
epochUpdate(&engine->time, delta);
inputUpdate(&engine->input);
renderFrameStart();
renderFrameStart(&engine->render);
}
bool engineUpdateEnd(engine_t *engine, game_t *game) {

View File

@ -72,37 +72,34 @@ void assetBufferSkip(FILE *buffer, int32_t n) {
fseek(buffer, n, SEEK_CUR);
}
shader_t * assetShaderLoad(char *fileVertex, char *fileFragment) {
void assetShaderLoad(shader_t *shader, char *fileVertex, char *fileFragment) {
// Load the vertex shader into memory
char *vertexShader = assetStringLoad(fileVertex);
if(vertexShader == NULL) return NULL;
if(vertexShader == NULL) return;
// Load the fragment shader into memory
char *fragmentShader = assetStringLoad(fileFragment);
if(fragmentShader == NULL) {
free(vertexShader);
return NULL;
return;
}
// Now attempt to load the shader
shader_t *shader = shaderCompile(vertexShader, fragmentShader);
shaderInit(shader, vertexShader, fragmentShader);
//Cleanup
free(vertexShader);
free(fragmentShader);
return shader;//shader may be NULL if loading failed, but not our problem.
}
texture_t * assetTextureLoad(char *fileName) {
void assetTextureLoad(texture_t *texture, char *fileName) {
FILE *buffer;
texture_t *texture;
int channels, width, height;
pixel_t *data;
stbi_io_callbacks OPENGL_STBI_CALLBACKS;
buffer = assetBufferOpen(fileName);
if(buffer == NULL) return NULL;
if(buffer == NULL) return;
// Setup the interface for STBI
OPENGL_STBI_CALLBACKS.read = &assetBufferRead;
@ -119,10 +116,9 @@ texture_t * assetTextureLoad(char *fileName) {
// Close the buffer
assetBufferClose(buffer);
if(data == NULL) return NULL;
if(data == NULL) return;
// Turn into a texture.
texture = textureCreate(width, height, data);
textureInit(texture, width, height, data);
stbi_image_free(data);
return texture;
}

View File

@ -12,7 +12,6 @@
/**
* Method to load an asset into memory as a raw string.
*
* @param assetName Path leading to the asset within the root asset directory.
* @return Pointer to char array of data from asset, NULL if unsuccesful.
*/
@ -20,7 +19,6 @@ char * assetStringLoad(char *assetName);
/**
* Platform-centric method to open a file buffer to an asset.
*
* @param assetName The asset name to open a buffer for.
* @return Pointer to a buffer, NULL if unsuccessfuil.
*/
@ -28,7 +26,6 @@ FILE * assetBufferOpen(char *assetName);
/**
* Closes a previously opened asset buffer.
*
* @param buffer Buffer to close.
* @return True if successful, otherwise false.
*/
@ -36,7 +33,6 @@ bool assetBufferClose(FILE *buffer);
/**
* Read bytes from buffer.
*
* @param buffer The buffer pointing to an asset.
* @param data Pointer to a ubyte array to buffer data into.
* @param size Length of the data buffer. Represents how many bytes can be read.
@ -46,7 +42,6 @@ int32_t assetBufferRead(FILE *buffer, char *data, int32_t size);
/**
* Skip to the end of the buffer, useful to find the length of the buffer.
*
* @param Buffer The buffer pointing to an asset.
* @return How many bytes were skipped
*/
@ -54,7 +49,6 @@ int32_t assetBufferEnd(FILE *buffer);
/**
* Method to skip n bytes in the buffer
*
* @param buffer The buffer pointing to an asset.
* @param n Count of bytes to skip.
*/
@ -62,17 +56,15 @@ void assetBufferSkip(FILE *buffer, int32_t n);
/**
* Load a shader program from a vertex and fragment shader file.
*
* @param shader Shader to load into.
* @param fileVertex The file path of the vertex shader
* @param fileFragment The file path of the fragment shader
* @return The loaded shader_t instance (From shaderCompile)
*/
shader_t * assetShaderLoad(char *fileVertex, char *fileFragment);
void assetShaderLoad(shader_t *shader, char *fileVertex, char *fileFragment);
/**
* Load a texture from a PNG file.
*
* @param fileName The fike path of the PNG image.
* @return The loaded texture object.
* @param texture Texture to load the file into.
* @param fileName The file path of the PNG image.
*/
texture_t * assetTextureLoad(char *fileName);
void assetTextureLoad(texture_t *texture, char *fileName);

View File

@ -15,6 +15,10 @@ bool gameInit(game_t *game) {
engineInit(&game->engine, game);
assetShaderLoad(&game->shader,"shaders/textured.vert","shaders/textured.frag");
assetTextureLoad(&game->texture, "cards_normal.png");
cubeInit(&game->primitive, 1, 1, 1);
// Init
// gameTimeInit();
// renderInit();
@ -48,7 +52,18 @@ bool gameInit(game_t *game) {
bool gameUpdate(game_t *game, float platformDelta) {
engineUpdateStart(&game->engine, game, platformDelta);
engineUpdateEnd(&game->engine, game);
cameraPerspective(&game->camera, 75,
((float)game->engine.render.width)/((float)game->engine.render.height),
0.01, 1000
);
cameraLookAt(&game->camera, 3, 3, 3, 0, 0, 0);
shaderUse(&game->shader);
shaderUseTexture(&game->shader, &game->texture);
shaderUseCamera(&game->shader, &game->camera);
shaderUsePosition(&game->shader, 0, 0, 0, 0, game->engine.time.current, 0);
primitiveDraw(&game->primitive, 0, -1);
// shaderUse(GAME_STATE.shaderWorld);// TODO: remove
@ -62,6 +77,8 @@ bool gameUpdate(game_t *game, float platformDelta) {
// holdemRenderFrameUseRight();
// holdemRenderWorld();
// holdemRenderFrameBack();
return engineUpdateEnd(&game->engine, game);
}
void gameDispose(game_t *game) {

View File

@ -7,6 +7,14 @@
#include <dawn/dawn.h>
#include "../engine/engine.h"
#include "../file/asset.h"
#include "../display/render.h"
#include "../display/primitive.h"
#include "../display/primitives/cube.h"
#include "../display/texture.h"
#include "../display/shader.h"
#include "../display/camera.h"
/**
* Initialize the game context.
*