|
|
|
|
@ -10,21 +10,25 @@
|
|
|
|
|
|
|
|
|
|
bool initGraphics(SDLHandles* handles); |
|
|
|
|
|
|
|
|
|
LightsBuffer initLights(MemoryArena* arena, GLContext* gl_ctx, u32 max_lights); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface
|
|
|
|
|
|
|
|
|
|
RenderState* |
|
|
|
|
initRenderState(u32 max_models, |
|
|
|
|
initRenderState(GLClearColor clear_col, |
|
|
|
|
u32 max_models, |
|
|
|
|
u32 max_textures, |
|
|
|
|
u32 max_shaders, |
|
|
|
|
u32 max_render_groups, |
|
|
|
|
u32 max_ubos) |
|
|
|
|
u32 max_ubos, |
|
|
|
|
u32 max_lights) |
|
|
|
|
{ |
|
|
|
|
LOGF(Info, "Initializing Renderer\n"); |
|
|
|
|
RenderState* rs = UTIL_ALLOC(1, RenderState); |
|
|
|
|
|
|
|
|
|
if (rs) { |
|
|
|
|
rs->clear_col = clear_col; |
|
|
|
|
rs->assets.arena = arenaInit(DEFAULT_ARENA_SIZE); |
|
|
|
|
rs->assets.max_models = max_models; |
|
|
|
|
rs->assets.models = ARENA_ALLOC(rs->assets.arena, Model, max_models); |
|
|
|
|
@ -48,10 +52,11 @@ initRenderState(u32 max_models,
|
|
|
|
|
max_ubos); |
|
|
|
|
|
|
|
|
|
rs->xforms = ARENA_ALLOC(rs->assets.arena, Transforms, 1); |
|
|
|
|
GLBuffer* xforms_ubo = getFreeUBO(rs->gl_ctx); |
|
|
|
|
assert(xforms_ubo); |
|
|
|
|
initTransforms(rs->assets.arena, rs->xforms, xforms_ubo, rs->gl_ctx); |
|
|
|
|
|
|
|
|
|
// FIXME: need to test this with another shader that has another UBO
|
|
|
|
|
GLBuffer& ubo = rs->gl_ctx->uniform_buffers[rs->gl_ctx->num_ubos++]; |
|
|
|
|
initTransforms(rs->assets.arena, rs->xforms, &ubo, rs->gl_ctx); |
|
|
|
|
rs->lights_buf = initLights(rs->rg_arena, rs->gl_ctx, max_lights); |
|
|
|
|
|
|
|
|
|
bool ret = loadDefaultShaders(rs); |
|
|
|
|
assert(ret); |
|
|
|
|
@ -285,3 +290,39 @@ initGraphics(SDLHandles* handles)
|
|
|
|
|
return handles->window != nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LightsBuffer |
|
|
|
|
initLights(MemoryArena* arena, GLContext* gl_ctx, u32 max_lights) |
|
|
|
|
{ |
|
|
|
|
// FIXME: revisit for 'Scene' abstraction
|
|
|
|
|
LightsBuffer lights_buf; |
|
|
|
|
lights_buf.max_p_lights = max_lights; |
|
|
|
|
lights_buf.max_d_lights = max_lights; |
|
|
|
|
lights_buf.p_lights = ARENA_ALLOC(arena, PointLight, max_lights); |
|
|
|
|
lights_buf.d_lights = ARENA_ALLOC(arena, PointLight, max_lights); |
|
|
|
|
|
|
|
|
|
GLBuffer* lights_ubo = getFreeUBO(gl_ctx); |
|
|
|
|
assert(lights_ubo); |
|
|
|
|
|
|
|
|
|
lights_ubo->target = GL_UNIFORM_BUFFER; |
|
|
|
|
lights_ubo->data_type = GL_BYTE; // NOTE: mixed types in structure
|
|
|
|
|
lights_ubo->name = arenaCopyCStr(arena, "lights"); |
|
|
|
|
assert((GLint) gl_ctx->binding_count < gl_ctx->max_binding_points); |
|
|
|
|
lights_ubo->binding_idx = gl_ctx->binding_count++; |
|
|
|
|
|
|
|
|
|
// FIXME: need to pad any vec3s to vec4 to match layout std140
|
|
|
|
|
u32 buf_size = sizeof(LightsBuffer) |
|
|
|
|
+ max_lights * sizeof(PointLight) |
|
|
|
|
+ max_lights * sizeof(PointLight); |
|
|
|
|
glGenBuffers(1, &lights_ubo->id); |
|
|
|
|
glBindBuffer(lights_ubo->target, lights_ubo->id); |
|
|
|
|
glBufferData(lights_ubo->target, |
|
|
|
|
buf_size, |
|
|
|
|
&lights_buf, |
|
|
|
|
GL_DYNAMIC_DRAW); |
|
|
|
|
glBindBufferBase(lights_ubo->target, |
|
|
|
|
lights_ubo->binding_idx, |
|
|
|
|
lights_ubo->id); |
|
|
|
|
|
|
|
|
|
return lights_buf; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|