Browse Source

add GLTexture structure, and gl_ctx->textures

main
cinnaboot 5 years ago
parent
commit
65c12555b2
  1. 34
      src/main.cpp
  2. 13
      src/shader.h

34
src/main.cpp

@ -29,6 +29,7 @@ struct Entity
{ {
u32 num_meshes; u32 num_meshes;
GLmesh* meshes; GLmesh* meshes;
GLTexture* diffuse_texture; // NOTE: pointer into gl_ctx->textures array
glm::mat4* xform; glm::mat4* xform;
char* name; char* name;
}; };
@ -156,23 +157,6 @@ getFreeRenderGroup(RenderState* rs)
return nullptr; 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_MODEL_COUNT 256
#define DEFAULT_TEXTURE_COUNT 64 #define DEFAULT_TEXTURE_COUNT 64
Assets* Assets*
@ -188,6 +172,22 @@ initAssets(memory_arena* arena,
return assets; 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 #define DEFAULT_RENDER_GROUP_COUNT 256
RenderState* RenderState*
initRenderState() initRenderState()

13
src/shader.h

@ -72,6 +72,14 @@ struct gl_buffer
char* name; char* name;
}; };
struct GLTexture
{
GLuint id;
GLenum pixel_format; // NOTE: GL_RGB or GL_RGBA
u32 width;
u32 height;
};
struct GLContext struct GLContext
{ {
GLuint binding_count; GLuint binding_count;
@ -87,6 +95,10 @@ struct GLContext
u32 max_shaders; u32 max_shaders;
u32 num_shaders; u32 num_shaders;
shader_program* shaders; shader_program* shaders;
u32 max_textures;
u32 num_textures;
GLTexture* textures;
}; };
struct GLBufferToAttribMapping struct GLBufferToAttribMapping
@ -96,6 +108,7 @@ struct GLBufferToAttribMapping
void* mesh_buf; void* mesh_buf;
}; };
// TODO: rename to GLMesh
struct GLmesh struct GLmesh
{ {
u32 num_indices; u32 num_indices;

Loading…
Cancel
Save