summaryrefslogtreecommitdiff
path: root/src/rendering.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rendering.c')
-rw-r--r--src/rendering.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/src/rendering.c b/src/rendering.c
index 02be7d1..0643c70 100644
--- a/src/rendering.c
+++ b/src/rendering.c
@@ -746,43 +746,44 @@ void r_create_textures(void* restrict ctx, u32* restrict texture_array,
ivec3* restrict texture_size, usize num_targets) {
const GladGLContext* gl = (GladGLContext*)ctx;
- u32 texture_dim = BUFFERPARAMETER_TEXTURE_GET_DIMENSION(texture_parameters[0]);
- u32 err;
+ i8 texture_dim = 2;
+ u32 err = 0;
+ ivec3 texture_sz;
+ ASSERT(texture_size != NULL);
+ glm_ivec3_copy(*texture_size, texture_sz);
- for (usize i = 1; i < num_targets; i++) {
- ASSERT(texture_dim == BUFFERPARAMETER_TEXTURE_GET_DIMENSION(texture_parameters[i]));
+ while (texture_dim > 0 && texture_sz[texture_dim] == 0) {
+ texture_dim--;
}
- // Convert the texturetype to GL texturetype
+ // Check that if texture_dim == 0 then texture_sz[0] > 0.
+ ASSERT(texture_sz[texture_dim] > 0);
+
switch (texture_dim) {
- case BUFFERPARAMETER_TEXTURE_1D:
+ case 0:
gl->CreateTextures(GL_TEXTURE_1D, num_targets, texture_array);
ASSERT(!gl->GetError());
for (usize i = 0; i < num_targets; i++) {
- gl->TextureStorage1D(texture_array[i], 1, gl_texture_format(BUFFERPARAMETER_TEXTURE_GET_FORMAT(texture_parameters[i])), (*texture_size)[0]);
+ gl->TextureStorage1D(texture_array[i], 1, gl_texture_format(BUFFERPARAMETER_FMT_GET(texture_parameters[i])), texture_sz[0]);
}
break;
- case BUFFERPARAMETER_TEXTURE_2D:
+ case 1:
gl->CreateTextures(GL_TEXTURE_2D, num_targets, texture_array);
ASSERT(!gl->GetError());
for (usize i = 0; i < num_targets; i++) {
- gl->TextureStorage2D(texture_array[i], 1, gl_texture_format(BUFFERPARAMETER_TEXTURE_GET_FORMAT(texture_parameters[i])), (*texture_size)[0], (*texture_size)[1]);
+ gl->TextureStorage2D(texture_array[i], 1, gl_texture_format(BUFFERPARAMETER_FMT_GET(texture_parameters[i])), texture_sz[0], texture_sz[1]);
}
break;
- case BUFFERPARAMETER_TEXTURE_3D:
+ case 2:
gl->CreateTextures(GL_TEXTURE_3D, num_targets, texture_array);
ASSERT(!gl->GetError());
for (usize i = 0; i < num_targets; i++) {
- gl->TextureStorage3D(texture_array[i], 1, gl_texture_format(BUFFERPARAMETER_TEXTURE_GET_FORMAT(texture_parameters[i])), (*texture_size)[0], (*texture_size)[1], (*texture_size)[2]);
+ gl->TextureStorage3D(texture_array[i], 1, gl_texture_format(BUFFERPARAMETER_FMT_GET(texture_parameters[i])), texture_sz[0], texture_sz[1], texture_sz[2]);
}
break;
- case BUFFERPARAMETER_TEXTURE_4D:
- ERROR("4D textures are unsupported!");
- exit(EXIT_FAILURE);
-
default:
ERROR("Failed to convert dimensionality to GL_TEXTURE_XD");
exit(EXIT_FAILURE);
@@ -833,7 +834,7 @@ void r_create_renderbuffers(void *restrict ctx, u32* restrict buffer_array, u32*
for (usize i = 0; i < num_buffers; i++) {
gl->NamedRenderbufferStorage(
buffer_array[i],
- gl_texture_format(BUFFERPARAMETER_RENDERBUFFER_GET_FORMAT(buffer_types[i])),
+ gl_texture_format(BUFFERPARAMETER_FMT_GET(buffer_types[i])),
buffer_sizes[i][0],
buffer_sizes[i][1]
);
@@ -845,18 +846,24 @@ void r_destroy_renderbuffers(void *restrict ctx, u32* buffers, usize num_buffers
((GladGLContext *restrict)ctx)->DeleteRenderbuffers(num_buffers, buffers);
}
-static u32 gl_renderbuffer_type(u32 buffer_param) {
- switch (BUFFERPARAMETER_RENDERBUFFER_GET_TYPE(buffer_param)) {
- case BUFFERPARAMETER_RENDERBUFFER_DEPTH:
+static u32 gl_format_attachment(u32 format) {
+ if ((format & BUFFERPARAMETER_FMT_COLOR_MASK) != 0) {
+ return GL_COLOR_ATTACHMENT0;
+ }
+ switch (format) {
+ case BUFFERPARAMETER_FMT_DEPTH24_STENCIL8:
+ return GL_DEPTH_STENCIL_ATTACHMENT;
+ case BUFFERPARAMETER_FMT_DEPTH16:
+ case BUFFERPARAMETER_FMT_DEPTH24:
+ case BUFFERPARAMETER_FMT_DEPTH32:
+ case BUFFERPARAMETER_FMT_DEPTH32F:
return GL_DEPTH_ATTACHMENT;
- case BUFFERPARAMETER_RENDERBUFFER_STENCIL:
+ case BUFFERPARAMETER_FMT_STENCIL8:
return GL_STENCIL_ATTACHMENT;
- case (BUFFERPARAMETER_RENDERBUFFER_DEPTH | BUFFERPARAMETER_RENDERBUFFER_STENCIL):
- return GL_DEPTH_STENCIL_ATTACHMENT;
default:
UNIMPLEMENTED;
+ return 0;
}
- return -1;
}
void r_attach_buffers(void *restrict ctx, u32 fbo, u32* buffers, u32* buffer_parameters, i32 num_buffers) {
@@ -866,31 +873,25 @@ void r_attach_buffers(void *restrict ctx, u32 fbo, u32* buffers, u32* buffer_par
u32 err;
+ u32 color_ofst = 0;
for (i32 i = 0; i < num_buffers; i++) {
+ u32 attachment = gl_format_attachment(BUFFERPARAMETER_GET_PARAMETER(buffer_parameters[i]));
+ ASSERT(attachment != 0);
+
switch (BUFFERPARAMETER_GET_TYPE(buffer_parameters[i])) {
case BufferType_frame:
UNIMPLEMENTED;
case BufferType_texture:
- switch (BUFFERPARAMETER_TEXTURE_GET_FORMAT(buffer_parameters[i])) {
- case BUFFERPARAMETER_FMT_DEPTH24_STENCIL8:
- gl->NamedFramebufferTexture(fbo, GL_DEPTH_STENCIL_ATTACHMENT, buffers[i], 0);
- break;
- case BUFFERPARAMETER_FMT_DEPTH16:
- case BUFFERPARAMETER_FMT_DEPTH24:
- case BUFFERPARAMETER_FMT_DEPTH32:
- case BUFFERPARAMETER_FMT_DEPTH32F:
- gl->NamedFramebufferTexture(fbo, GL_DEPTH_ATTACHMENT, buffers[i], 0);
- break;
- case BUFFERPARAMETER_FMT_STENCIL8:
- gl->NamedFramebufferTexture(fbo, GL_STENCIL_ATTACHMENT, buffers[i], 0);
- break;
- default:
- gl->NamedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0 + i, buffers[i], 0);
- break;
+ if (attachment == GL_COLOR_ATTACHMENT0) {
+ gl->NamedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0 + color_ofst, buffers[i], 0);
+ color_ofst++;
+ } else {
+ gl->NamedFramebufferTexture(fbo, attachment, buffers[i], 0);
}
+
break;
case BufferType_render:
- gl->NamedFramebufferRenderbuffer(fbo, gl_renderbuffer_type(buffer_parameters[i]), GL_RENDERBUFFER, buffers[i]);
+ gl->NamedFramebufferRenderbuffer(fbo, attachment, GL_RENDERBUFFER, buffers[i]);
break;
case BufferType_buffer:
UNIMPLEMENTED;