diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gl.c | 10 | ||||
| -rw-r--r-- | src/rendering.c | 54 |
2 files changed, 46 insertions, 18 deletions
@@ -191,7 +191,7 @@ void shaders_delete(Shader* shader, usize shader_len) { GLenum ShaderBuffer_get_gl_access(u64 flags) { const ShaderBufferFlag access = ShaderBuffer_get_access_type(flags); - switch(flags & 0b111) { + switch(flags & 7) { // Stored in the first 3 bits case ShaderBuffer_AccessFrequency_stream: switch(access) { case ShaderBuffer_AccessType_draw: return GL_STREAM_DRAW; @@ -225,18 +225,16 @@ RenderObject RenderObject_new( GladGLContext *gl = GLOBAL_PLATFORM->window->context; RenderObject o; - gl->GenVertexArrays(1, &(o.vao)); + gl->CreateVertexArrays(1, &(o.vao)); gl->BindVertexArray(o.vao); /* For each buffer in the shader, */ /* The shader should be generalied, */ for (usize i = 0; i < num_buffers; i++) { const usize sz = buffers[i].size_elem * buffers[i].count; - const u32 b_gl_type = ShaderBuffer_get_gl_type(buffers[i].buffertype); - gl->GenBuffers(1, &(buffers[i].buffername)); - gl->BindBuffer(b_gl_type, buffers[i].buffername); - gl->BufferData(b_gl_type, (isize)sz, buffers[i].data, ShaderBuffer_get_gl_accesstype(buffers[i].buffertype)); + gl->CreateBuffers(1, &(buffers[i].buffername)); + gl->NamedBufferData(buffers[i].buffername, (isize)sz, buffers[i].data, ShaderBuffer_get_gl_accesstype(buffers[i].buffertype)); } o.shader = *shader; diff --git a/src/rendering.c b/src/rendering.c index 4db3308..a37de58 100644 --- a/src/rendering.c +++ b/src/rendering.c @@ -476,8 +476,7 @@ void render_present(Window* w) { gl->UseProgram(o->shader.program); // TODO: Use texture atlas - gl->ActiveTexture(GL_TEXTURE0); - gl->BindTexture(GL_TEXTURE_2D, o->texture); + gl->BindTextureUnit(0, o->texture); { mat4 model = GLM_MAT4_IDENTITY_INIT; @@ -671,12 +670,23 @@ Texture createTextureFromImageData(unsigned char* image_data, i32 width, i32 hei } const GladGLContext* gl = w->context; - - gl->GenTextures(1, &t.id); - gl->BindTexture(GL_TEXTURE_2D, t.id); u32 err = gl->GetError(); if (err) { - ERROR("Failed to bind texture from image data!"); + ERROR("There's already something wrong!"); + } + + gl->CreateTextures(GL_TEXTURE_2D, 1, &t.id); + err = gl->GetError(); + if (err) { + if (err == GL_INVALID_ENUM) { + ERROR("Failed to create texture! GL_INVALID_ENUM"); + } + else if (err == GL_INVALID_VALUE) { + ERROR("Failed to create texture! GL_INVALID_VALUE"); + } + else { + ERROR("Failed to create texture!"); + } } /* TODO: Support more formats than rgb and rgba, such as gray, gray/alpha, etc.*/ @@ -685,13 +695,33 @@ Texture createTextureFromImageData(unsigned char* image_data, i32 width, i32 hei /* TODO: Don't force internal format to RGB */ - gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, format, - GL_UNSIGNED_BYTE, image_data); - - gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gl->TextureStorage2D(t.id, 1, GL_RGB8, width, height); + err = gl->GetError(); + if (err) { + char* errstr = NULL; + switch (err) { + case GL_INVALID_ENUM: + errstr = "GL_INVALID_ENUM"; break; + case GL_INVALID_VALUE: + errstr = "GL_INVALID_VALUE"; break; + case GL_INVALID_OPERATION: + errstr = "GL_INVALID_OPERATION"; break; + default: + errstr = "unknown"; break; + } + ERROR("Failed to allocate memory for texture! %dx%d size (%s)", width, height, errstr); + } + gl->TextureSubImage2D(t.id, 0, + // offset, size + 0, 0, width, height, + format, GL_UNSIGNED_BYTE, image_data); + err = gl->GetError(); + if (err) { + ERROR("Failed to copy image data!"); + } - gl->BindTexture(GL_TEXTURE_2D, 0); + gl->TextureParameteri(t.id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gl->TextureParameteri(t.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); return t; } |
