From ddb9b0598f182ad84ef3f5501ac3934eb7959578 Mon Sep 17 00:00:00 2001 From: Roz K Date: Mon, 19 Dec 2022 06:27:34 +0100 Subject: [PATCH] Cleanup: remove slot from texture. --- __init__.py | 9 +++++---- cpp/opengl/render_opengles.cpp | 11 +++++------ cpp/opengl/render_opengles.hpp | 1 - cpp/render.hpp | 3 ++- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/__init__.py b/__init__.py index 5be0188..46cbb34 100644 --- a/__init__.py +++ b/__init__.py @@ -254,7 +254,6 @@ resolve_param.argtypes = ( _create_texture = _lib.rk_create_texture _create_texture.restype = ctypes.c_void_p _create_texture.argtypes = ( - ctypes.c_uint, # slot ctypes.c_uint, # format ctypes.c_uint, # width ctypes.c_uint, # height @@ -262,10 +261,10 @@ _create_texture.argtypes = ( ctypes.c_uint, # flags ctypes.c_void_p) # pixels -def create_texture(slot, format, width, height, nlevels, flags, pixels): +def create_texture(format, width, height, nlevels, flags, pixels): assert pixels.typecode == TEXTURE_FORMAT_TYPECODE[format] assert len(pixels) == width * height * max(1, nlevels) * TEXTURE_FORMAT_NELEMS[format] - return _create_texture(slot, format, width, height, nlevels, flags, _voidp(pixels)) + return _create_texture(format, width, height, nlevels, flags, _voidp(pixels)) _create_triangles = _lib.rk_create_triangles _create_triangles.restype = ctypes.c_void_p @@ -345,6 +344,7 @@ def set_param_vec3(param, value): select_texture = _lib.rk_select_texture select_texture.argtypes = ( + ctypes.c_uint, # slot ctypes.c_void_p, # texture ctypes.c_void_p) # sampler @@ -375,7 +375,8 @@ unselect_vertices.argtypes = ( unselect_texture = _lib.rk_unselect_texture unselect_texture.argtypes = ( - ctypes.c_void_p,) # texture + ctypes.c_uint, # slot + ctypes.c_void_p) # texture unselect_shader = _lib.rk_unselect_shader unselect_shader.argtypes = ( diff --git a/cpp/opengl/render_opengles.cpp b/cpp/opengl/render_opengles.cpp index 7db4cea..ecbecd9 100644 --- a/cpp/opengl/render_opengles.cpp +++ b/cpp/opengl/render_opengles.cpp @@ -145,7 +145,6 @@ rk_param_t rk_resolve_param( } rk_texture_t rk_create_texture( - rk_uint slot, rk_texture_format format, rk_uint width, rk_uint height, @@ -184,7 +183,6 @@ rk_texture_t rk_create_texture( break; } rk_texture * const texture = new rk_texture; - glActiveTexture(GL_TEXTURE0 + slot); glGenTextures(1, &texture->texture); GLenum target; if (nlevels) { @@ -226,7 +224,6 @@ rk_texture_t rk_create_texture( if (flags & RK_TEXTURE_FLAG_MIPMAPS) { glGenerateMipmap(target); } - texture->slot = slot; texture->nlevels = nlevels; glBindTexture(target, 0); return texture; @@ -499,18 +496,19 @@ void rk_set_param_vec3( } void rk_select_texture( + rk_uint slot, rk_texture_t _texture, rk_input_t _sampler) { rk_texture const * const texture = reinterpret_cast(_texture); GLint const sampler = reinterpret_cast(_sampler) - 1; if (texture && sampler > -1 && rk_current_shader) { - glActiveTexture(GL_TEXTURE0 + texture->slot); + glActiveTexture(GL_TEXTURE0 + slot); if (texture->nlevels) { glBindTexture(GL_TEXTURE_2D_ARRAY, texture->texture); } else { glBindTexture(GL_TEXTURE_2D, texture->texture); } - glUniform1i(sampler, texture->slot); + glUniform1i(sampler, slot); } } @@ -651,10 +649,11 @@ void rk_unselect_vertices( } void rk_unselect_texture( + rk_uint slot, rk_texture_t _texture) { rk_texture const * const texture = reinterpret_cast(_texture); if (texture) { - glActiveTexture(GL_TEXTURE0 + texture->slot); + glActiveTexture(GL_TEXTURE0 + slot); if (texture->nlevels) { glBindTexture(GL_TEXTURE_2D, 0); } else { diff --git a/cpp/opengl/render_opengles.hpp b/cpp/opengl/render_opengles.hpp index 98f068d..24dac3c 100644 --- a/cpp/opengl/render_opengles.hpp +++ b/cpp/opengl/render_opengles.hpp @@ -34,7 +34,6 @@ struct rk_shader { }; struct rk_texture { - rk_uint slot; rk_uint nlevels; GLuint texture; }; diff --git a/cpp/render.hpp b/cpp/render.hpp index 3369800..885f2c8 100644 --- a/cpp/render.hpp +++ b/cpp/render.hpp @@ -101,7 +101,6 @@ RK_EXPORT rk_param_t rk_resolve_param( char const * name); RK_EXPORT rk_texture_t rk_create_texture( - rk_uint slot, rk_texture_format format, rk_uint width, rk_uint height, @@ -151,6 +150,7 @@ RK_EXPORT void rk_set_param_vec3( rk_vec3 const & value); RK_EXPORT void rk_select_texture( + rk_uint slot, rk_texture_t texture, rk_input_t sampler); @@ -171,6 +171,7 @@ RK_EXPORT void rk_unselect_vertices( rk_vertices_t vertices); RK_EXPORT void rk_unselect_texture( + rk_uint slot, rk_texture_t texture); RK_EXPORT void rk_unselect_shader(