From 65c12555b2999a0e327e04fc49d623de8c04bac6 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Fri, 31 Dec 2021 11:16:27 -0500 Subject: [PATCH] add GLTexture structure, and gl_ctx->textures --- src/main.cpp | 34 +++++++++++++++++----------------- src/shader.h | 13 +++++++++++++ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b63e2c6..939a2a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,7 @@ struct Entity { u32 num_meshes; GLmesh* meshes; + GLTexture* diffuse_texture; // NOTE: pointer into gl_ctx->textures array glm::mat4* xform; char* name; }; @@ -156,23 +157,6 @@ getFreeRenderGroup(RenderState* rs) return nullptr; } -#define DEFAULT_SHADER_COUNT 64 -#define DEFAULT_UBO_COUNT 32 -GLContext* -initGLContext(memory_arena* arena) -{ - GLContext* gl_ctx = ARENA_ALLOC(arena, GLContext, 1); - gl_ctx->max_shaders = DEFAULT_SHADER_COUNT; - gl_ctx->num_shaders = 0; - gl_ctx->shaders = ARENA_ALLOC(arena, shader_program, DEFAULT_SHADER_COUNT); - gl_ctx->max_ubos = DEFAULT_UBO_COUNT; - gl_ctx->num_ubos = 0; - gl_ctx->uniform_buffers = ARENA_ALLOC(arena, gl_buffer, gl_ctx->max_ubos); - gl_ctx->binding_count = 0; - - return gl_ctx; -} - #define DEFAULT_MODEL_COUNT 256 #define DEFAULT_TEXTURE_COUNT 64 Assets* @@ -188,6 +172,22 @@ initAssets(memory_arena* arena, return assets; } +#define DEFAULT_SHADER_COUNT 64 +#define DEFAULT_UBO_COUNT 32 +GLContext* +initGLContext(memory_arena* arena) +{ + GLContext* gl_ctx = ARENA_ALLOC(arena, GLContext, 1); + gl_ctx->max_shaders = DEFAULT_SHADER_COUNT; + gl_ctx->shaders = ARENA_ALLOC(arena, shader_program, DEFAULT_SHADER_COUNT); + gl_ctx->max_ubos = DEFAULT_UBO_COUNT; + gl_ctx->uniform_buffers = ARENA_ALLOC(arena, gl_buffer, gl_ctx->max_ubos); + gl_ctx->max_textures = DEFAULT_TEXTURE_COUNT; + gl_ctx->textures = ARENA_ALLOC(arena, GLTexture, gl_ctx->max_textures); + + return gl_ctx; +} + #define DEFAULT_RENDER_GROUP_COUNT 256 RenderState* initRenderState() diff --git a/src/shader.h b/src/shader.h index e511ed4..f058ec9 100644 --- a/src/shader.h +++ b/src/shader.h @@ -72,6 +72,14 @@ struct gl_buffer char* name; }; +struct GLTexture +{ + GLuint id; + GLenum pixel_format; // NOTE: GL_RGB or GL_RGBA + u32 width; + u32 height; +}; + struct GLContext { GLuint binding_count; @@ -87,6 +95,10 @@ struct GLContext u32 max_shaders; u32 num_shaders; shader_program* shaders; + + u32 max_textures; + u32 num_textures; + GLTexture* textures; }; struct GLBufferToAttribMapping @@ -96,6 +108,7 @@ struct GLBufferToAttribMapping void* mesh_buf; }; +// TODO: rename to GLMesh struct GLmesh { u32 num_indices;