diff --git a/src/CRE/Glitter/file_reader.cpp b/src/CRE/Glitter/file_reader.cpp index d254f88b..4e583e7c 100644 --- a/src/CRE/Glitter/file_reader.cpp +++ b/src/CRE/Glitter/file_reader.cpp @@ -160,10 +160,10 @@ namespace Glitter { k->buffer = buffer; glGenVertexArrays(1, &k->vao); - gl_state_bind_vertex_array(k->vao, true); - gl_state_bind_array_buffer(vbo, true); + glBindVertexArray(k->vao); + glBindBuffer(GL_ARRAY_BUFFER, vbo); if (k->data.type == PARTICLE_QUAD) - gl_state_bind_element_array_buffer(ebo, true); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, buffer_size, @@ -183,9 +183,11 @@ namespace Glitter { } } - gl_state_bind_array_buffer(0); - gl_state_bind_vertex_array(0); - gl_state_bind_element_array_buffer(0); + if (offset) { + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } } else { free_def(effect_group->buffer); diff --git a/src/CRE/effect.cpp b/src/CRE/effect.cpp index 143bbcf5..8ed6dad1 100644 --- a/src/CRE/effect.cpp +++ b/src/CRE/effect.cpp @@ -4874,10 +4874,6 @@ void star_catalog_milky_way::create_buffers(int32_t subdivs, float_t uv_rec_scal const int32_t vtx_count = (subdivs - 1) * sectors_count + 2; restart_index = (uint16_t)0xFFFFFFFF; - gl_state_bind_vertex_array(0); - gl_state_bind_array_buffer(0); - gl_state_bind_element_array_buffer(0); - const float_t rec_longitude_degs_10 = 1.0f / (float_t)longitude_degs_10; const float_t rec_latitude_degs_10 = 1.0f / (float_t)latitude_degs_10; @@ -4947,9 +4943,9 @@ void star_catalog_milky_way::create_buffers(int32_t subdivs, float_t uv_rec_scal glGenVertexArrays(1, &vao); vbo.Create((size_t)buffer_size * vtx_count, vtx_data); - vbo.Bind(); + glBindBuffer(GL_ARRAY_BUFFER, vbo); - gl_state_bind_vertex_array(vao); + glBindVertexArray(vao); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, buffer_size, (void*)offsetof(star_catalog_vertex, position)); @@ -4958,11 +4954,11 @@ void star_catalog_milky_way::create_buffers(int32_t subdivs, float_t uv_rec_scal (void*)offsetof(star_catalog_vertex, texcoord)); ebo.Create(sizeof(uint16_t) * ebo_count, ebo_data); - ebo.Bind(); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - gl_state_bind_vertex_array(0); - gl_state_bind_array_buffer(0); - gl_state_bind_element_array_buffer(0); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); free_def(vtx_data); free_def(ebo_data); @@ -5696,9 +5692,9 @@ static void leaf_particle_init(bool change_stage) { glGenVertexArrays(1, &leaf_ptcl_vao); leaf_ptcl_vbo.Create(buffer_size * leaf_ptcl_vtx_count); - leaf_ptcl_vbo.Bind(); + glBindBuffer(GL_ARRAY_BUFFER, leaf_ptcl_vbo); - gl_state_bind_vertex_array(leaf_ptcl_vao); + glBindVertexArray(leaf_ptcl_vao); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, buffer_size, (void*)offsetof(leaf_particle_vertex_data, position)); @@ -5710,11 +5706,11 @@ static void leaf_particle_init(bool change_stage) { (void*)offsetof(leaf_particle_vertex_data, normal)); leaf_ptcl_ebo.Create(sizeof(uint32_t) * ebo_count, ebo_data); - leaf_ptcl_ebo.Bind(); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, leaf_ptcl_ebo); - gl_state_bind_vertex_array(0); - gl_state_bind_array_buffer(0); - gl_state_bind_element_array_buffer(0); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); free_def(ebo_data); leaf_particle_scene_ubo.Create(sizeof(leaf_particle_scene_shader_data)); @@ -5929,9 +5925,9 @@ static void particle_init(vec3* offset) { glGenVertexArrays(1, &ptcl_vao); ptcl_vbo.Create(buffer_size * ptcl_vtx_count); - ptcl_vbo.Bind(); + glBindBuffer(GL_ARRAY_BUFFER, ptcl_vbo); - gl_state_bind_vertex_array(ptcl_vao); + glBindVertexArray(ptcl_vao); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, buffer_size, (void*)offsetof(particle_vertex_data, position)); @@ -5945,8 +5941,8 @@ static void particle_init(vec3* offset) { glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, buffer_size, (void*)offsetof(particle_vertex_data, normal)); - gl_state_bind_vertex_array(0); - gl_state_bind_array_buffer(0); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); particle_scene_ubo.Create(sizeof(particle_scene_shader_data)); } diff --git a/src/CRE/gl_state.cpp b/src/CRE/gl_state.cpp index d82cce76..fd907a02 100644 --- a/src/CRE/gl_state.cpp +++ b/src/CRE/gl_state.cpp @@ -10,11 +10,7 @@ gl_state_struct gl_state; void gl_state_active_bind_texture_2d(int32_t index, GLuint texture, bool force) { if (force || gl_state.texture_binding_2d[index] != texture) { if (force || gl_state.active_texture_index != index) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glActiveTexture((GLenum)(GL_TEXTURE0 + index)); -#endif - gl_state.active_texture = (GLenum)(GL_TEXTURE0 + index); + glActiveTexture((GLenum)(GL_TEXTURE0 + index)); gl_state.active_texture_index = (GLuint)index; } glBindTexture(GL_TEXTURE_2D, texture); @@ -25,11 +21,7 @@ void gl_state_active_bind_texture_2d(int32_t index, GLuint texture, bool force) void gl_state_active_bind_texture_cube_map(int32_t index, GLuint texture, bool force) { if (force || gl_state.texture_binding_cube_map[index] != texture) { if (force || gl_state.active_texture_index != index) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glActiveTexture((GLenum)(GL_TEXTURE0 + index)); -#endif - gl_state.active_texture = (GLenum)(GL_TEXTURE0 + index); + glActiveTexture((GLenum)(GL_TEXTURE0 + index)); gl_state.active_texture_index = (GLuint)index; } glBindTexture(GL_TEXTURE_CUBE_MAP, texture); @@ -39,24 +31,15 @@ void gl_state_active_bind_texture_cube_map(int32_t index, GLuint texture, bool f void gl_state_active_texture(size_t index, bool force) { if (force || gl_state.active_texture_index != index) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glActiveTexture((GLenum)(GL_TEXTURE0 + index)); -#endif - gl_state.active_texture = (GLenum)(GL_TEXTURE0 + index); + glActiveTexture((GLenum)(GL_TEXTURE0 + index)); gl_state.active_texture_index = (GLuint)index; } } void gl_state_bind_framebuffer(GLuint framebuffer, bool force) { - if (force || gl_state.framebuffer_binding != framebuffer - || gl_state.read_framebuffer_binding != framebuffer + if (force || gl_state.read_framebuffer_binding != framebuffer || gl_state.draw_framebuffer_binding != framebuffer) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); -#endif - gl_state.framebuffer_binding = framebuffer; + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); gl_state.read_framebuffer_binding = framebuffer; gl_state.draw_framebuffer_binding = framebuffer; } @@ -64,30 +47,21 @@ void gl_state_bind_framebuffer(GLuint framebuffer, bool force) { void gl_state_bind_read_framebuffer(GLuint framebuffer, bool force) { if (force || gl_state.read_framebuffer_binding != framebuffer) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer); -#endif + glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer); gl_state.read_framebuffer_binding = framebuffer; } } void gl_state_bind_draw_framebuffer(GLuint framebuffer, bool force) { if (force || gl_state.draw_framebuffer_binding != framebuffer) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); -#endif + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); gl_state.draw_framebuffer_binding = framebuffer; } } void gl_state_bind_vertex_array(GLuint array, bool force) { if (force || gl_state.vertex_array_binding != array) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindVertexArray(array); -#endif + glBindVertexArray(array); gl_state.vertex_array_binding = array; } } @@ -115,10 +89,7 @@ void gl_state_bind_uniform_buffer(GLuint buffer, bool force) { void gl_state_bind_uniform_buffer_base(GLuint index, GLuint buffer, bool force) { if (force || gl_state.uniform_buffer_bindings[index] != buffer) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindBufferBase(GL_UNIFORM_BUFFER, index, buffer); -#endif + glBindBufferBase(GL_UNIFORM_BUFFER, index, buffer); gl_state.uniform_buffer_binding = buffer; gl_state.uniform_buffer_bindings[index] = buffer; gl_state.uniform_buffer_offsets[index] = 0; @@ -131,10 +102,7 @@ void gl_state_bind_uniform_buffer_range(GLuint index, if (force || gl_state.uniform_buffer_bindings[index] != buffer || gl_state.uniform_buffer_offsets[index] != offset || gl_state.uniform_buffer_sizes[index] != size) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindBufferRange(GL_UNIFORM_BUFFER, index, buffer, offset, size); -#endif + glBindBufferRange(GL_UNIFORM_BUFFER, index, buffer, offset, size); gl_state.uniform_buffer_binding = buffer; gl_state.uniform_buffer_bindings[index] = buffer; gl_state.uniform_buffer_offsets[index] = offset; @@ -151,10 +119,7 @@ void gl_state_bind_shader_storage_buffer(GLuint buffer, bool force) { void gl_state_bind_shader_storage_buffer_base(GLuint index, GLuint buffer, bool force) { if (force || gl_state.shader_storage_buffer_bindings[index] != buffer) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, buffer); -#endif + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, buffer); gl_state.shader_storage_buffer_binding = buffer; gl_state.shader_storage_buffer_bindings[index] = buffer; gl_state.shader_storage_buffer_offsets[index] = 0; @@ -167,10 +132,7 @@ void gl_state_bind_shader_storage_buffer_range(GLuint index, if (force || gl_state.shader_storage_buffer_bindings[index] != buffer || gl_state.shader_storage_buffer_offsets[index] != offset || gl_state.shader_storage_buffer_sizes[index] != size) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindBufferRange(GL_SHADER_STORAGE_BUFFER, index, buffer, offset, size); -#endif + glBindBufferRange(GL_SHADER_STORAGE_BUFFER, index, buffer, offset, size); gl_state.shader_storage_buffer_binding = buffer; gl_state.shader_storage_buffer_bindings[index] = buffer; gl_state.shader_storage_buffer_offsets[index] = offset; @@ -194,10 +156,7 @@ void gl_state_bind_texture_cube_map(GLuint texture, bool force) { void gl_state_bind_sampler(int32_t index, GLuint sampler, bool force) { if (force || gl_state.sampler_binding[index] != sampler) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBindSampler(index, sampler); -#endif + glBindSampler(index, sampler); gl_state.sampler_binding[index] = sampler; } } @@ -232,168 +191,123 @@ bool gl_state_check_sampler_binding(int32_t index, GLuint sampler) { void gl_state_disable_blend(bool force) { if (force || gl_state.blend) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDisable(GL_BLEND); -#endif + glDisable(GL_BLEND); gl_state.blend = GL_FALSE; } } void gl_state_disable_cull_face(bool force) { if (force || gl_state.cull_face) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDisable(GL_CULL_FACE); -#endif + glDisable(GL_CULL_FACE); gl_state.cull_face = GL_FALSE; } } void gl_state_disable_depth_test(bool force) { if (force || gl_state.depth_test) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDisable(GL_DEPTH_TEST); -#endif + glDisable(GL_DEPTH_TEST); gl_state.depth_test = GL_FALSE; } } void gl_state_disable_multisample(bool force) { if (force || gl_state.multisample) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDisable(GL_MULTISAMPLE); -#endif + glDisable(GL_MULTISAMPLE); gl_state.multisample = GL_FALSE; } } void gl_state_disable_primitive_restart(bool force) { if (force || gl_state.primitive_restart) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDisable(GL_PRIMITIVE_RESTART); -#endif + glDisable(GL_PRIMITIVE_RESTART); gl_state.primitive_restart = GL_FALSE; } } void gl_state_disable_scissor_test(bool force) { if (force || gl_state.scissor_test) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDisable(GL_SCISSOR_TEST); -#endif + glDisable(GL_SCISSOR_TEST); gl_state.scissor_test = GL_FALSE; } } void gl_state_disable_stencil_test(bool force) { if (force || gl_state.stencil_test) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDisable(GL_STENCIL_TEST); -#endif + glDisable(GL_STENCIL_TEST); gl_state.stencil_test = GL_FALSE; } } void gl_state_enable_blend(bool force) { if (force || !gl_state.blend) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glEnable(GL_BLEND); -#endif + glEnable(GL_BLEND); gl_state.blend = GL_TRUE; } } void gl_state_enable_cull_face(bool force) { if (force || !gl_state.cull_face) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glEnable(GL_CULL_FACE); -#endif + glEnable(GL_CULL_FACE); gl_state.cull_face = GL_TRUE; } } void gl_state_enable_depth_test(bool force) { if (force || !gl_state.depth_test) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glEnable(GL_DEPTH_TEST); -#endif + glEnable(GL_DEPTH_TEST); gl_state.depth_test = GL_TRUE; } } void gl_state_enable_multisample(bool force) { if (force || !gl_state.multisample) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glEnable(GL_MULTISAMPLE); -#endif + glEnable(GL_MULTISAMPLE); gl_state.multisample = GL_TRUE; } } void gl_state_enable_primitive_restart(bool force) { if (force || !gl_state.primitive_restart) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glEnable(GL_PRIMITIVE_RESTART); -#endif + glEnable(GL_PRIMITIVE_RESTART); gl_state.primitive_restart = GL_TRUE; } } void gl_state_enable_scissor_test(bool force) { if (force || !gl_state.scissor_test) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glEnable(GL_SCISSOR_TEST); -#endif + glEnable(GL_SCISSOR_TEST); gl_state.scissor_test = GL_TRUE; } } void gl_state_enable_stencil_test(bool force) { if (force || !gl_state.stencil_test) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glEnable(GL_STENCIL_TEST); -#endif + glEnable(GL_STENCIL_TEST); gl_state.stencil_test = GL_TRUE; } } void gl_state_get() { -#ifdef USE_OPENGL - if (Vulkan::use) - return; - - glGetIntegerv(GL_CURRENT_PROGRAM, &gl_state.program); - glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&gl_state.active_texture); - gl_state.active_texture_index = gl_state.active_texture - GL_TEXTURE0; + glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&gl_state.program); + GLenum active_texture = GL_TEXTURE0; + glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&active_texture); + gl_state.active_texture_index = active_texture - GL_TEXTURE0; if (GLAD_GL_VERSION_4_5) { for (GLuint i = 0; i < 32; i++) { - glGetIntegeri_v(GL_TEXTURE_BINDING_2D, i, &gl_state.texture_binding_2d[i]); - glGetIntegeri_v(GL_TEXTURE_BINDING_CUBE_MAP, i, &gl_state.texture_binding_cube_map[i]); - glGetIntegeri_v(GL_SAMPLER_BINDING, i, &gl_state.sampler_binding[i]); + glGetIntegeri_v(GL_TEXTURE_BINDING_2D, i, (GLint*)&gl_state.texture_binding_2d[i]); + glGetIntegeri_v(GL_TEXTURE_BINDING_CUBE_MAP, i, (GLint*)&gl_state.texture_binding_cube_map[i]); + glGetIntegeri_v(GL_SAMPLER_BINDING, i, (GLint*)&gl_state.sampler_binding[i]); } } else { for (GLuint i = 0; i < 32; i++) { glActiveTexture((GLenum)(GL_TEXTURE0 + i)); - glGetIntegerv(GL_TEXTURE_BINDING_2D, &gl_state.texture_binding_2d[i]); - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &gl_state.texture_binding_cube_map[i]); - glGetIntegerv(GL_SAMPLER_BINDING, &gl_state.sampler_binding[i]); + glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&gl_state.texture_binding_2d[i]); + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, (GLint*)&gl_state.texture_binding_cube_map[i]); + glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&gl_state.sampler_binding[i]); } - glActiveTexture(gl_state.active_texture); + glActiveTexture(active_texture); } glGetBooleanv(GL_BLEND, &gl_state.blend); @@ -404,7 +318,6 @@ void gl_state_get() { glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&gl_state.blend_mode_rgb); glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&gl_state.blend_mode_alpha); - glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&gl_state.framebuffer_binding); glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, (GLint*)&gl_state.read_framebuffer_binding); glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, (GLint*)&gl_state.draw_framebuffer_binding); glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&gl_state.vertex_array_binding); @@ -449,7 +362,6 @@ void gl_state_get() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); gl_state.polygon_mode = GL_FILL; -#endif } void gl_state_get_all_gl_errors() { @@ -494,10 +406,7 @@ void gl_state_get_viewport(GLint& x, GLint& y, GLsizei& width, GLsizei& height) void gl_state_set_blend_func(GLenum src, GLenum dst, bool force) { if (force || gl_state.blend_src_rgb != src || gl_state.blend_dst_rgb != dst || gl_state.blend_src_alpha != GL_ONE || gl_state.blend_dst_alpha != GL_ONE_MINUS_SRC_ALPHA) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); -#endif + glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); gl_state.blend_src_rgb = src; gl_state.blend_dst_rgb = dst; gl_state.blend_src_alpha = GL_ONE; @@ -509,10 +418,7 @@ void gl_state_set_blend_func_separate(GLenum src_rgb, GLenum dst_rgb, GLenum src_alpha, GLenum dst_alpha, bool force) { if (force || gl_state.blend_src_rgb != src_rgb || gl_state.blend_dst_rgb != dst_rgb || gl_state.blend_src_alpha != src_alpha || gl_state.blend_dst_alpha != dst_alpha) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBlendFuncSeparate(src_rgb, dst_rgb, src_alpha, dst_alpha); -#endif + glBlendFuncSeparate(src_rgb, dst_rgb, src_alpha, dst_alpha); gl_state.blend_src_rgb = src_rgb; gl_state.blend_dst_rgb = dst_rgb; gl_state.blend_src_alpha = src_alpha; @@ -522,10 +428,7 @@ void gl_state_set_blend_func_separate(GLenum src_rgb, GLenum dst_rgb, void gl_state_set_blend_equation(GLenum mode, bool force) { if (force || gl_state.blend_mode_rgb != mode || gl_state.blend_mode_alpha != mode) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBlendEquationSeparate(mode, mode); -#endif + glBlendEquationSeparate(mode, mode); gl_state.blend_mode_rgb = mode; gl_state.blend_mode_alpha = mode; } @@ -533,10 +436,7 @@ void gl_state_set_blend_equation(GLenum mode, bool force) { void gl_state_set_blend_equation_separate(GLenum mode_rgb, GLenum mode_alpha, bool force) { if (force || gl_state.blend_mode_rgb != mode_rgb || gl_state.blend_mode_alpha != mode_alpha) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glBlendEquationSeparate(mode_rgb, mode_alpha); -#endif + glBlendEquationSeparate(mode_rgb, mode_alpha); gl_state.blend_mode_rgb = mode_rgb; gl_state.blend_mode_alpha = mode_alpha; } @@ -546,10 +446,7 @@ void gl_state_set_color_mask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha, bool force) { if (force || gl_state.color_mask[0] != red || gl_state.color_mask[1] != green || gl_state.color_mask[2] != blue || gl_state.color_mask[3] != alpha) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glColorMask(red, green, blue, alpha); -#endif + glColorMask(red, green, blue, alpha); gl_state.color_mask[0] = red; gl_state.color_mask[1] = green; gl_state.color_mask[2] = blue; @@ -559,40 +456,28 @@ void gl_state_set_color_mask(GLboolean red, GLboolean green, void gl_state_set_cull_face_mode(GLenum mode, bool force) { if (force || gl_state.cull_face_mode != mode) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glCullFace(mode); -#endif + glCullFace(mode); gl_state.cull_face_mode = mode; } } void gl_state_set_depth_func(GLenum func, bool force) { if (force || gl_state.depth_func != func) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDepthFunc(func); -#endif + glDepthFunc(func); gl_state.depth_func = func; } } void gl_state_set_depth_mask(GLboolean flag, bool force) { if (force || gl_state.depth_mask != flag) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glDepthMask(flag); -#endif + glDepthMask(flag); gl_state.depth_mask = flag; } } void gl_state_set_line_width(GLfloat width, bool force) { if (force || gl_state.line_width != width) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glLineWidth(width); -#endif + glLineWidth(width); gl_state.line_width = width; } } @@ -601,28 +486,19 @@ void gl_state_set_polygon_mode(GLenum face, GLenum mode, bool force) { switch (face) { case GL_FRONT: if (force || gl_state.polygon_mode != mode) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glPolygonMode(GL_FRONT, mode); -#endif + glPolygonMode(GL_FRONT, mode); gl_state.polygon_mode = mode; } break; case GL_BACK: if (force || gl_state.polygon_mode != mode) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glPolygonMode(GL_BACK, mode); -#endif + glPolygonMode(GL_BACK, mode); gl_state.polygon_mode = mode; } break; case GL_FRONT_AND_BACK: if (force || gl_state.polygon_mode != mode) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glPolygonMode(GL_FRONT_AND_BACK, mode); -#endif + glPolygonMode(GL_FRONT_AND_BACK, mode); gl_state.polygon_mode = mode; } break; @@ -631,10 +507,7 @@ void gl_state_set_polygon_mode(GLenum face, GLenum mode, bool force) { void gl_state_set_primitive_restart_index(GLuint index, bool force) { if (force || gl_state.primitive_restart_index != index) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glPrimitiveRestartIndex(index); -#endif + glPrimitiveRestartIndex(index); gl_state.primitive_restart_index = index; } } @@ -642,10 +515,7 @@ void gl_state_set_primitive_restart_index(GLuint index, bool force) { void gl_state_set_scissor(const gl_state_rect& rect, bool force) { if (force || gl_state.scissor_box.x != rect.x || gl_state.scissor_box.y != rect.y || gl_state.scissor_box.width != rect.width || gl_state.scissor_box.height != rect.height) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glScissor(rect.x, rect.y, rect.width, rect.height); -#endif + glScissor(rect.x, rect.y, rect.width, rect.height); gl_state.scissor_box = rect; } } @@ -653,10 +523,7 @@ void gl_state_set_scissor(const gl_state_rect& rect, bool force) { void gl_state_set_scissor(GLint x, GLint y, GLsizei width, GLsizei height, bool force) { if (force || gl_state.scissor_box.x != x || gl_state.scissor_box.y != y || gl_state.scissor_box.width != width || gl_state.scissor_box.height != height) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glScissor(x, y, width, height); -#endif + glScissor(x, y, width, height); gl_state.scissor_box.x = x; gl_state.scissor_box.y = y; gl_state.scissor_box.width = width; @@ -667,10 +534,7 @@ void gl_state_set_scissor(GLint x, GLint y, GLsizei width, GLsizei height, bool void gl_state_set_stencil_func(GLenum func, GLint ref, GLuint mask, bool force) { if (force || gl_state.stencil_func != func || gl_state.stencil_ref != ref || gl_state.stencil_value_mask != mask) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glStencilFunc(func, ref, mask); -#endif + glStencilFunc(func, ref, mask); gl_state.stencil_func = func; gl_state.stencil_ref = ref; gl_state.stencil_value_mask = mask; @@ -679,10 +543,7 @@ void gl_state_set_stencil_func(GLenum func, GLint ref, GLuint mask, bool force) void gl_state_set_stencil_mask(GLuint mask, bool force) { if (force || gl_state.stencil_mask != mask) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glStencilMask(mask); -#endif + glStencilMask(mask); gl_state.stencil_mask = mask; } } @@ -690,10 +551,7 @@ void gl_state_set_stencil_mask(GLuint mask, bool force) { void gl_state_set_stencil_op(GLenum sfail, GLenum dpfail, GLenum dppass, bool force) { if (force || gl_state.stencil_fail != sfail || gl_state.stencil_dpfail != dpfail || gl_state.stencil_dppass != dppass) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glStencilOp(sfail, dpfail, dppass); -#endif + glStencilOp(sfail, dpfail, dppass); gl_state.stencil_fail = sfail; gl_state.stencil_dpfail = dpfail; gl_state.stencil_dppass = dppass; @@ -703,10 +561,7 @@ void gl_state_set_stencil_op(GLenum sfail, GLenum dpfail, GLenum dppass, bool fo void gl_state_set_viewport(const gl_state_rect& rect, bool force) { if (force || gl_state.viewport.x != rect.x || gl_state.viewport.y != rect.y || gl_state.viewport.width != rect.width || gl_state.viewport.height != rect.height) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glViewport(rect.x, rect.y, rect.width, rect.height); -#endif + glViewport(rect.x, rect.y, rect.width, rect.height); gl_state.viewport = rect; } } @@ -714,10 +569,7 @@ void gl_state_set_viewport(const gl_state_rect& rect, bool force) { void gl_state_set_viewport(GLint x, GLint y, GLsizei width, GLsizei height, bool force) { if (force || gl_state.viewport.x != x || gl_state.viewport.y != y || gl_state.viewport.width != width || gl_state.viewport.height != height) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glViewport(x, y, width, height); -#endif + glViewport(x, y, width, height); gl_state.viewport.x = x; gl_state.viewport.y = y; gl_state.viewport.width = width; @@ -727,10 +579,7 @@ void gl_state_set_viewport(GLint x, GLint y, GLsizei width, GLsizei height, bool void gl_state_use_program(GLuint program, bool force) { if (force || gl_state.program != program) { -#ifdef USE_OPENGL - if (!Vulkan::use) - glUseProgram(program); -#endif + glUseProgram(program); gl_state.program = program; } } diff --git a/src/CRE/gl_state.hpp b/src/CRE/gl_state.hpp index 0bccb359..9b3aa843 100644 --- a/src/CRE/gl_state.hpp +++ b/src/CRE/gl_state.hpp @@ -16,12 +16,11 @@ struct gl_state_rect { }; struct gl_state_struct { - GLint program; - GLenum active_texture; + GLuint program; GLuint active_texture_index; - GLint texture_binding_2d[32]; - GLint texture_binding_cube_map[32]; - GLint sampler_binding[32]; + GLuint texture_binding_2d[32]; + GLuint texture_binding_cube_map[32]; + GLuint sampler_binding[32]; GLboolean blend; GLenum blend_src_rgb; GLenum blend_src_alpha; @@ -29,7 +28,6 @@ struct gl_state_struct { GLenum blend_dst_alpha; GLenum blend_mode_rgb; GLenum blend_mode_alpha; - GLuint framebuffer_binding; GLuint read_framebuffer_binding; GLuint draw_framebuffer_binding; GLuint vertex_array_binding; diff --git a/src/CRE/light_param.cpp b/src/CRE/light_param.cpp index 2e12716d..ec8e74df 100644 --- a/src/CRE/light_param.cpp +++ b/src/CRE/light_param.cpp @@ -509,7 +509,7 @@ void light_param_data::set_ibl(const light_param_ibl* ibl, const light_param_dat return; for (int32_t i = 0, j = -1; i < 5; i++, j++) { - gl_state_bind_texture_cube_map(storage->textures[i]); + glBindTexture(GL_TEXTURE_CUBE_MAP, storage->textures[i]); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); @@ -528,7 +528,7 @@ void light_param_data::set_ibl(const light_param_ibl* ibl, const light_param_dat light_param_data::set_ibl_specular(&ibl->specular[j]); } } - gl_state_bind_texture_cube_map(0); + glBindTexture(GL_TEXTURE_CUBE_MAP, 0); ::light_set* set = &rctx_ptr->light_set[LIGHT_SET_MAIN]; set->set_irradiance(ibl->diff_coef[1][0], ibl->diff_coef[1][1], ibl->diff_coef[1][2]); diff --git a/src/CRE/mdl/disp_manager.cpp b/src/CRE/mdl/disp_manager.cpp index 63ca8813..64a6e58d 100644 --- a/src/CRE/mdl/disp_manager.cpp +++ b/src/CRE/mdl/disp_manager.cpp @@ -301,15 +301,15 @@ namespace mdl { morph_vertex_buffer = 0; morph_vertex_buffer_offset = 0; - gl_state_bind_vertex_array(vertex_array); + glBindVertexArray(vertex_array); for (int32_t i = 0; i < 16; i++) if (vertex_attrib_array[i]) { glDisableVertexAttribArray(i); vertex_attrib_array[i] = false; } - gl_state_bind_array_buffer(0, true); - gl_state_bind_element_array_buffer(0, true); - gl_state_bind_vertex_array(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindVertexArray(0); } DispManager::DispManager() : obj_flags(), shadow_type(), field_8(), field_C(), @@ -414,10 +414,11 @@ namespace mdl { vertex_array = &vertex_array_cache.back(); } + bool new_vertex_array = false; if (!vertex_array->vertex_array) { glGenVertexArrays(1, &vertex_array->vertex_array); - gl_state_bind_vertex_array(vertex_array->vertex_array); + glBindVertexArray(vertex_array->vertex_array); glVertexAttrib4f( POSITION_INDEX, 0.0f, 0.0f, 0.0f, 1.0f); glVertexAttrib4f( BONE_WEIGHT_INDEX, 0.0f, 0.0f, 0.0f, 0.0f); glVertexAttrib4f( NORMAL_INDEX, 0.0f, 0.0f, 0.0f, 1.0f); @@ -434,6 +435,7 @@ namespace mdl { glVertexAttrib4f(MORPH_TEXCOORD0_INDEX, 0.0f, 0.0f, 0.0f, 1.0f); glVertexAttrib4f(MORPH_TEXCOORD1_INDEX, 0.0f, 0.0f, 0.0f, 1.0f); glVertexAttrib4f( BONE_INDEX_INDEX, 0.0f, 0.0f, 0.0f, 0.0f); + new_vertex_array = true; } vertex_array->vertex_buffer = vertex_buffer; @@ -449,10 +451,11 @@ namespace mdl { memcpy(&vertex_array->vertex_attrib_buffer_binding, vertex_attrib_buffer_binding, sizeof(vertex_attrib_buffer_binding)); - gl_state_bind_vertex_array(vertex_array->vertex_array); - gl_state_bind_array_buffer(vertex_buffer, true); + if (!new_vertex_array) + glBindVertexArray(vertex_array->vertex_array); + glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); if (index_buffer) - gl_state_bind_element_array_buffer(index_buffer, true); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer); size_t offset = vertex_buffer_offset; if (vertex_format & OBJ_VERTEX_POSITION) { @@ -691,7 +694,7 @@ namespace mdl { } if (morph_vertex_buffer) { - gl_state_bind_array_buffer(morph_vertex_buffer, true); + glBindBuffer(GL_ARRAY_BUFFER, morph_vertex_buffer); size_t offset = morph_vertex_buffer_offset; if (vertex_format & OBJ_VERTEX_POSITION) { @@ -923,10 +926,10 @@ namespace mdl { } } - gl_state_bind_array_buffer(0); - gl_state_bind_vertex_array(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); if (index_buffer) - gl_state_bind_element_array_buffer(0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } static size_t gen_grid_vertices(std::vector>& data, @@ -1687,10 +1690,11 @@ namespace mdl { etc_vertex_array = &etc_vertex_array_cache.back(); } + bool new_vertex_array = false; if (!etc_vertex_array->vertex_array) { glGenVertexArrays(1, &etc_vertex_array->vertex_array); - gl_state_bind_vertex_array(etc_vertex_array->vertex_array); + glBindVertexArray(etc_vertex_array->vertex_array); glVertexAttrib4f( POSITION_INDEX, 0.0f, 0.0f, 0.0f, 1.0f); glVertexAttrib4f( BONE_WEIGHT_INDEX, 0.0f, 0.0f, 0.0f, 0.0f); glVertexAttrib4f( NORMAL_INDEX, 0.0f, 0.0f, 0.0f, 1.0f); @@ -1707,11 +1711,13 @@ namespace mdl { glVertexAttrib4f(MORPH_TEXCOORD0_INDEX, 0.0f, 0.0f, 0.0f, 1.0f); glVertexAttrib4f(MORPH_TEXCOORD1_INDEX, 0.0f, 0.0f, 0.0f, 1.0f); glVertexAttrib4f( BONE_INDEX_INDEX, 0.0f, 0.0f, 0.0f, 0.0f); + new_vertex_array = true; } etc_vertex_array->alive_time = 2; etc_vertex_array->data = etc->data; etc_vertex_array->type = type; + etc_vertex_array->indexed = indexed; std::vector> vtx_data; std::vector vtx_indices; @@ -1827,12 +1833,13 @@ namespace mdl { GLsizei size_vertex = sizeof(vec3) * 2; - gl_state_bind_vertex_array(etc_vertex_array->vertex_array); + if (!new_vertex_array) + glBindVertexArray(etc_vertex_array->vertex_array); if (etc_vertex_array->vertex_buffer.IsNull()) etc_vertex_array->vertex_buffer.Create(sizeof(vec3) * 2 * vtx_data.size()); - etc_vertex_array->vertex_buffer.Bind(true); + glBindBuffer(GL_ARRAY_BUFFER, etc_vertex_array->vertex_buffer); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec3) * 2 * vtx_data.size(), vtx_data.data()); @@ -1840,7 +1847,7 @@ namespace mdl { if (etc_vertex_array->index_buffer.IsNull()) etc_vertex_array->index_buffer.Create(sizeof(uint32_t) * vtx_indices.size()); - etc_vertex_array->index_buffer.Bind(true); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, etc_vertex_array->index_buffer); glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(uint32_t) * vtx_indices.size(), vtx_indices.data()); } @@ -1853,10 +1860,10 @@ namespace mdl { glVertexAttribPointer(NORMAL_INDEX, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)sizeof(vec3)); - gl_state_bind_array_buffer(0); - gl_state_bind_vertex_array(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); if (indexed) - gl_state_bind_element_array_buffer(0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void* DispManager::alloc_data(int32_t size) { @@ -2068,12 +2075,13 @@ namespace mdl { for (DispManager::etc_vertex_array& i : etc_vertex_array_cache) if (i.alive_time > 0 && --i.alive_time <= 0) { - gl_state_bind_vertex_array(i.vertex_array); + glBindVertexArray(i.vertex_array); glDisableVertexAttribArray(POSITION_INDEX); glDisableVertexAttribArray( NORMAL_INDEX); - gl_state_bind_array_buffer(0, true); - gl_state_bind_element_array_buffer(0, true); - gl_state_bind_vertex_array(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + if (i.indexed) + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindVertexArray(0); } } diff --git a/src/CRE/mdl/disp_manager.hpp b/src/CRE/mdl/disp_manager.hpp index 3e0fbb0d..bfc0611d 100644 --- a/src/CRE/mdl/disp_manager.hpp +++ b/src/CRE/mdl/disp_manager.hpp @@ -407,6 +407,7 @@ namespace mdl { GLuint vertex_array; EtcObj::Data data; EtcObjType type; + bool indexed; GLsizei count; size_t offset; GLsizei wire_count; diff --git a/src/CRE/object.cpp b/src/CRE/object.cpp index 2272cefc..018973f0 100644 --- a/src/CRE/object.cpp +++ b/src/CRE/object.cpp @@ -2407,12 +2407,12 @@ inline void objset_info_storage_free() { static GLuint create_index_buffer(size_t size, const void* data) { GLuint buffer = 0; glGenBuffers(1, &buffer); - gl_state_bind_element_array_buffer(buffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); if (GLAD_GL_VERSION_4_4) glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data, 0); else glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data, GL_STATIC_DRAW); - gl_state_bind_element_array_buffer(0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); if (glGetError()) { glDeleteBuffers(1, &buffer); @@ -2424,14 +2424,14 @@ static GLuint create_index_buffer(size_t size, const void* data) { static GLuint create_vertex_buffer(size_t size, const void* data, bool dynamic) { GLuint buffer = 0; glGenBuffers(1, &buffer); - gl_state_bind_array_buffer(buffer); + glBindBuffer(GL_ARRAY_BUFFER, buffer); if (GLAD_GL_VERSION_4_4) glBufferStorage(GL_ARRAY_BUFFER, (GLsizeiptr)size, data, dynamic ? GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT : 0); else glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)size, data, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); - gl_state_bind_array_buffer(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); if (glGetError()) { glDeleteBuffers(1, &buffer); diff --git a/src/CRE/render.cpp b/src/CRE/render.cpp index 562689e7..05e81703 100644 --- a/src/CRE/render.cpp +++ b/src/CRE/render.cpp @@ -919,12 +919,13 @@ namespace rndr { rend_texture[0].Init(render_post_width[0], render_post_height[0], 0, GL_RGBA16F, GL_DEPTH_COMPONENT24); - gl_state_bind_texture_2d(rend_texture[0].GetColorTex()); + glBindTexture(GL_TEXTURE_2D, rend_texture[0].GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - gl_state_bind_texture_2d(rend_texture[0].GetDepthTex()); + glBindTexture(GL_TEXTURE_2D, rend_texture[0].GetDepthTex()); GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); + glBindTexture(GL_TEXTURE_2D, 0); for (int32_t i = 0; i < 3; i++) { taa_tex[i] = texture_load_tex_2d(texture_id(0x25, texture_counter++), @@ -940,24 +941,26 @@ namespace rndr { temp_buffer.Init(render_post_width[0], render_post_height[0], 0, GL_RGBA8, GL_ZERO); sss_contour_texture = &mlaa_buffer; - gl_state_bind_texture_2d(mlaa_buffer.GetDepthTex()); + glBindTexture(GL_TEXTURE_2D, mlaa_buffer.GetDepthTex()); glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); + glBindTexture(GL_TEXTURE_2D, 0); for (int32_t i = 1; i < downsample_count; i++) { rend_texture[i].Init(render_post_width[i], render_post_height[i], 0, GL_RGBA16F, GL_ZERO); - gl_state_bind_texture_2d(rend_texture[i].GetColorTex()); + glBindTexture(GL_TEXTURE_2D, rend_texture[i].GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, 0); } downsample_texture.Init(reduce_width[0], reduce_height[0], 0, GL_RGBA16F, GL_ZERO); - gl_state_bind_texture_2d(downsample_texture.GetColorTex()); - + glBindTexture(GL_TEXTURE_2D, downsample_texture.GetColorTex()); const vec4 border_color = 0.0f; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glBindTexture(GL_TEXTURE_2D, 0); field_3E8.Init(512, 256, 0, GL_RGBA8, GL_ZERO); @@ -975,13 +978,14 @@ namespace rndr { for (int32_t i = 0; i < 5; i++) { reduce_tex[i] = texture_load_tex_2d(texture_id(0x25, texture_counter++), GL_RGBA16F, reduce_width[i], reduce_height[i], 0, 0, 0); - gl_state_bind_texture_2d(reduce_tex[i]->glid); + glBindTexture(GL_TEXTURE_2D, reduce_tex[i]->glid); const vec4 border_color = 0.0f; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); } + glBindTexture(GL_TEXTURE_2D, 0); reduce_texture[0].SetColorDepthTextures(reduce_tex[0]->glid); @@ -989,18 +993,18 @@ namespace rndr { GL_RGBA16F, 32, 2, 0, 0, 0); glGenTextures(1, &exposure_tex); - gl_state_bind_texture_2d(exposure_tex); + glBindTexture(GL_TEXTURE_2D, exposure_tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 2, 2, 0, GL_RGBA, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - gl_state_bind_texture_2d(0); + glBindTexture(GL_TEXTURE_2D, 0); exposure_texture.SetColorDepthTextures(exposure_tex); glGenTextures(1, &tonemap_lut_texture); - gl_state_bind_texture_2d(tonemap_lut_texture); + glBindTexture(GL_TEXTURE_2D, tonemap_lut_texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, 16 * TONE_MAP_SAT_GAMMA_SAMPLES, 1, 0, GL_RG, GL_HALF_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -1008,7 +1012,7 @@ namespace rndr { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); const GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_GREEN }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); - gl_state_bind_texture_2d(0); + glBindTexture(GL_TEXTURE_2D, 0); generate_mlaa_area_texture(); @@ -1191,12 +1195,13 @@ namespace rndr { rend_texture[0].Init(render_post_width[0], render_post_height[0], 0, GL_RGBA16F, GL_DEPTH_COMPONENT24); - gl_state_bind_texture_2d(rend_texture[0].GetColorTex()); + glBindTexture(GL_TEXTURE_2D, rend_texture[0].GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - gl_state_bind_texture_2d(rend_texture[0].GetDepthTex()); + glBindTexture(GL_TEXTURE_2D, rend_texture[0].GetDepthTex()); GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); + glBindTexture(GL_TEXTURE_2D, 0); for (int32_t i = 0; i < 3; i++) { texture_id id = taa_tex[i]->id; @@ -1216,16 +1221,18 @@ namespace rndr { temp_buffer.Init(render_post_width[0], render_post_height[0], 0, GL_RGBA8, GL_ZERO); sss_contour_texture = &mlaa_buffer; - gl_state_bind_texture_2d(mlaa_buffer.GetDepthTex()); + glBindTexture(GL_TEXTURE_2D, mlaa_buffer.GetDepthTex()); glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); for (int32_t i = 1; i < downsample_count; i++) { rend_texture[i].Init(render_post_width[i], render_post_height[i], 0, GL_RGBA16F, GL_ZERO); - gl_state_bind_texture_2d(rend_texture[i].GetColorTex()); + glBindTexture(GL_TEXTURE_2D, rend_texture[i].GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } + glBindTexture(GL_TEXTURE_2D, 0); + dof->resize(render_post_width[0], render_post_height[0]); for (int32_t i = 0; i < 1; i++) { @@ -2074,10 +2081,10 @@ namespace rndr { calculate_mlaa_area_texture_data(data, cross1, cross2); glGenTextures(1, &mlaa_area_texture); - gl_state_bind_texture_2d(mlaa_area_texture); + glBindTexture(GL_TEXTURE_2D, mlaa_area_texture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, MLAA_SIDE_LEN, MLAA_SIDE_LEN, 0, GL_RG, GL_UNSIGNED_BYTE, data); - gl_state_bind_texture_2d(0); + glBindTexture(GL_TEXTURE_2D, 0); free_def(data); } diff --git a/src/CRE/render_context.cpp b/src/CRE/render_context.cpp index 9a290191..bdcf7973 100644 --- a/src/CRE/render_context.cpp +++ b/src/CRE/render_context.cpp @@ -620,10 +620,10 @@ sprite_width(), sprite_height(), screen_x_offset(), screen_y_offset(), screen_wi }; glGenVertexArrays(1, &box_vao); - gl_state_bind_vertex_array(box_vao); + glBindVertexArray(box_vao); box_vbo.Create(sizeof(box_texcoords), box_texcoords); - box_vbo.Bind(); + glBindBuffer(GL_ARRAY_BUFFER, box_vbo); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(float_t) * 16, (void*)0); @@ -635,17 +635,17 @@ sprite_width(), sprite_height(), screen_x_offset(), screen_y_offset(), screen_wi glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(float_t) * 16, (void*)(sizeof(float_t) * 12)); glGenVertexArrays(1, &lens_ghost_vao); - gl_state_bind_vertex_array(lens_ghost_vao); + glBindVertexArray(lens_ghost_vao); lens_ghost_vbo.Create(sizeof(float_t) * 5 * (6 * 16)); - lens_ghost_vbo.Bind(); + glBindBuffer(GL_ARRAY_BUFFER, lens_ghost_vbo); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float_t) * 5, (void*)0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float_t) * 5, (void*)(sizeof(float_t) * 2)); - gl_state_bind_array_buffer(0); - gl_state_bind_vertex_array(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); glGenVertexArrays(1, &common_vao); diff --git a/src/CRE/render_manager.cpp b/src/CRE/render_manager.cpp index cd7c9afe..72090516 100644 --- a/src/CRE/render_manager.cpp +++ b/src/CRE/render_manager.cpp @@ -1379,17 +1379,14 @@ void render_manager_free_data() { static void draw_pass_shadow_begin_make_shadowmap(Shadow* shad, int32_t index, int32_t a3) { render_context* rctx = rctx_ptr; shad->curr_render_textures[0]->Bind(); - shad->curr_render_textures[0]->SetViewport(); texture* tex = shad->curr_render_textures[0]->color_texture; - gl_state_set_scissor(0, 0, tex->width, tex->height); + gl_state_set_viewport(1, 1, tex->width - 2, tex->width - 2); gl_state_enable_depth_test(); - gl_state_enable_scissor_test(); glClearColor(1.0, 1.0, 1.0, 1.0); if (!a3) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); else if (shad->separate) glClear(GL_COLOR_BUFFER_BIT); - gl_state_set_scissor(1, 1, tex->width - 2, tex->height - 2); float_t shadow_range = shad->get_shadow_range(); float_t offset; @@ -1406,8 +1403,10 @@ static void draw_pass_shadow_begin_make_shadowmap(Shadow* shad, int32_t index, i view_point = &shad->view_point_shared; } + const float_t scale = (float_t)(tex->width / 2) / (float_t)((tex->width - 2) / 2); mat4 temp; mat4_translate(offset, 0.0f, 0.0f, &temp); + mat4_scale_rot(&temp, scale, scale, 1.0f, &temp); mat4 proj; mat4_ortho(-shadow_range, shadow_range, @@ -1424,7 +1423,6 @@ static void draw_pass_shadow_begin_make_shadowmap(Shadow* shad, int32_t index, i static void draw_pass_shadow_end_make_shadowmap(Shadow* shad, int32_t index, int32_t a3) { render_context* rctx = rctx_ptr; gl_state_disable_depth_test(); - gl_state_disable_scissor_test(); rctx->draw_state->shader_index = -1; if (a3 == shad->num_shadow - 1) { @@ -1499,14 +1497,6 @@ static void draw_pass_shadow_filter(RenderTexture* a1, RenderTexture* a2, rctx->esm_filter_batch_ubo.WriteMemory(esm_filter_batch); gl_state_active_bind_texture_2d(0, v11->glid); - if (a3) { - GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); - } - else { - GLint swizzle[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); - } gl_state_bind_sampler(0, rctx->render_samplers[0]); gl_state_bind_vertex_array(rctx->common_vao); shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4); @@ -1878,7 +1868,6 @@ static void draw_pass_3d_shadow_set(Shadow* shad, render_context* rctx) { for (int32_t i = 0; i < 2; i++) if (shad->shadow_enable[i]) { gl_state_active_bind_texture_2d(6 + j, shad->curr_render_textures[1 + i]->GetColorTex()); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); j++; } diff --git a/src/CRE/render_texture.cpp b/src/CRE/render_texture.cpp index 06b6bced..bac121f2 100644 --- a/src/CRE/render_texture.cpp +++ b/src/CRE/render_texture.cpp @@ -84,12 +84,12 @@ int32_t RenderTexture::Init(int32_t width, int32_t height, render_texture_counter++; color_texture = GetColorTex(); - gl_state_bind_texture_2d(GetColorTex()); if (color_format == GL_RGBA32F) { + glBindTexture(GL_TEXTURE_2D, color_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glBindTexture(GL_TEXTURE_2D, 0); } - gl_state_bind_texture_2d(0); } else { this->color_texture = 0; diff --git a/src/CRE/renderer/dof.cpp b/src/CRE/renderer/dof.cpp index 41d2ffec..300353f5 100644 --- a/src/CRE/renderer/dof.cpp +++ b/src/CRE/renderer/dof.cpp @@ -316,25 +316,27 @@ namespace renderer { int32_t h2 = max_def(height / 2, 1); glGenTextures(6, textures); - gl_state_bind_texture_2d(textures[0]); + glBindTexture(GL_TEXTURE_2D, textures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, w20, h20, 0, GL_RG, GL_HALF_FLOAT, 0); fbo[0].init(w20, h20, &textures[0], 1, 0); - gl_state_bind_texture_2d(textures[1]); + glBindTexture(GL_TEXTURE_2D, textures[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, w20, h20, 0, GL_RG, GL_HALF_FLOAT, 0); fbo[1].init(w20, h20, &textures[1], 1, 0); - gl_state_bind_texture_2d(textures[2]); + glBindTexture(GL_TEXTURE_2D, textures[2]); glTexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F, w2, h2, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 0); - gl_state_bind_texture_2d(textures[3]); + glBindTexture(GL_TEXTURE_2D, textures[3]); glTexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F, w2, h2, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 0); fbo[2].init(w2, h2, &textures[2], 2, 0); - gl_state_bind_texture_2d(textures[4]); + glBindTexture(GL_TEXTURE_2D, textures[4]); glTexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F, w2, h2, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 0); - gl_state_bind_texture_2d(textures[5]); + glBindTexture(GL_TEXTURE_2D, textures[5]); glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w2, h2, 0, GL_RED, GL_UNSIGNED_BYTE, 0); fbo[3].init(w2, h2, &textures[4], 2, 0); + + glBindTexture(GL_TEXTURE_2D, 0); } void DOF3::update_data(float_t min_dist, float_t max_dist, float_t fov, float_t dist, float_t focal_length, diff --git a/src/CRE/shadow.cpp b/src/CRE/shadow.cpp index 502d6b1e..78ff71de 100644 --- a/src/CRE/shadow.cpp +++ b/src/CRE/shadow.cpp @@ -101,13 +101,18 @@ int32_t Shadow::init() { return -1; for (int32_t i = 0; i < 3; i++) { - gl_state_bind_texture_2d(render_textures[i].GetColorTex()); + glBindTexture(GL_TEXTURE_2D, render_textures[i].GetColorTex()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f); static const vec4 border_color = 1.0f; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); } - gl_state_bind_texture_2d(0); + + glBindTexture(GL_TEXTURE_2D, render_textures[0].GetDepthTex()); + GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); + glBindTexture(GL_TEXTURE_2D, 0); gl_state_get_error(); return 0; } diff --git a/src/CRE/texture.cpp b/src/CRE/texture.cpp index fd9785b8..9185c8c4 100644 --- a/src/CRE/texture.cpp +++ b/src/CRE/texture.cpp @@ -581,14 +581,7 @@ inline void texture_manager_free() { } inline static void texture_bind(GLenum target, GLuint texture) { - switch (target) { - case GL_TEXTURE_2D: - gl_state_bind_texture_2d(texture); - break; - case GL_TEXTURE_CUBE_MAP: - gl_state_bind_texture_cube_map(texture); - break; - } + glBindTexture(target, texture); } inline static GLuint texture_get_working_internal_format(GLuint internal_format) {