Cleanup: remove slot from texture.

This commit is contained in:
Roz K 2022-12-19 06:27:34 +01:00
parent 028ba40148
commit ddb9b0598f
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
4 changed files with 12 additions and 12 deletions

View File

@ -254,7 +254,6 @@ resolve_param.argtypes = (
_create_texture = _lib.rk_create_texture _create_texture = _lib.rk_create_texture
_create_texture.restype = ctypes.c_void_p _create_texture.restype = ctypes.c_void_p
_create_texture.argtypes = ( _create_texture.argtypes = (
ctypes.c_uint, # slot
ctypes.c_uint, # format ctypes.c_uint, # format
ctypes.c_uint, # width ctypes.c_uint, # width
ctypes.c_uint, # height ctypes.c_uint, # height
@ -262,10 +261,10 @@ _create_texture.argtypes = (
ctypes.c_uint, # flags ctypes.c_uint, # flags
ctypes.c_void_p) # pixels 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 pixels.typecode == TEXTURE_FORMAT_TYPECODE[format]
assert len(pixels) == width * height * max(1, nlevels) * TEXTURE_FORMAT_NELEMS[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 = _lib.rk_create_triangles
_create_triangles.restype = ctypes.c_void_p _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 = _lib.rk_select_texture
select_texture.argtypes = ( select_texture.argtypes = (
ctypes.c_uint, # slot
ctypes.c_void_p, # texture ctypes.c_void_p, # texture
ctypes.c_void_p) # sampler ctypes.c_void_p) # sampler
@ -375,7 +375,8 @@ unselect_vertices.argtypes = (
unselect_texture = _lib.rk_unselect_texture unselect_texture = _lib.rk_unselect_texture
unselect_texture.argtypes = ( 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 = _lib.rk_unselect_shader
unselect_shader.argtypes = ( unselect_shader.argtypes = (

View File

@ -145,7 +145,6 @@ rk_param_t rk_resolve_param(
} }
rk_texture_t rk_create_texture( rk_texture_t rk_create_texture(
rk_uint slot,
rk_texture_format format, rk_texture_format format,
rk_uint width, rk_uint width,
rk_uint height, rk_uint height,
@ -184,7 +183,6 @@ rk_texture_t rk_create_texture(
break; break;
} }
rk_texture * const texture = new rk_texture; rk_texture * const texture = new rk_texture;
glActiveTexture(GL_TEXTURE0 + slot);
glGenTextures(1, &texture->texture); glGenTextures(1, &texture->texture);
GLenum target; GLenum target;
if (nlevels) { if (nlevels) {
@ -226,7 +224,6 @@ rk_texture_t rk_create_texture(
if (flags & RK_TEXTURE_FLAG_MIPMAPS) { if (flags & RK_TEXTURE_FLAG_MIPMAPS) {
glGenerateMipmap(target); glGenerateMipmap(target);
} }
texture->slot = slot;
texture->nlevels = nlevels; texture->nlevels = nlevels;
glBindTexture(target, 0); glBindTexture(target, 0);
return texture; return texture;
@ -499,18 +496,19 @@ void rk_set_param_vec3(
} }
void rk_select_texture( void rk_select_texture(
rk_uint slot,
rk_texture_t _texture, rk_texture_t _texture,
rk_input_t _sampler) { rk_input_t _sampler) {
rk_texture const * const texture = reinterpret_cast<rk_texture const *>(_texture); rk_texture const * const texture = reinterpret_cast<rk_texture const *>(_texture);
GLint const sampler = reinterpret_cast<intptr_t>(_sampler) - 1; GLint const sampler = reinterpret_cast<intptr_t>(_sampler) - 1;
if (texture && sampler > -1 && rk_current_shader) { if (texture && sampler > -1 && rk_current_shader) {
glActiveTexture(GL_TEXTURE0 + texture->slot); glActiveTexture(GL_TEXTURE0 + slot);
if (texture->nlevels) { if (texture->nlevels) {
glBindTexture(GL_TEXTURE_2D_ARRAY, texture->texture); glBindTexture(GL_TEXTURE_2D_ARRAY, texture->texture);
} else { } else {
glBindTexture(GL_TEXTURE_2D, texture->texture); 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( void rk_unselect_texture(
rk_uint slot,
rk_texture_t _texture) { rk_texture_t _texture) {
rk_texture const * const texture = reinterpret_cast<rk_texture const *>(_texture); rk_texture const * const texture = reinterpret_cast<rk_texture const *>(_texture);
if (texture) { if (texture) {
glActiveTexture(GL_TEXTURE0 + texture->slot); glActiveTexture(GL_TEXTURE0 + slot);
if (texture->nlevels) { if (texture->nlevels) {
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} else { } else {

View File

@ -34,7 +34,6 @@ struct rk_shader {
}; };
struct rk_texture { struct rk_texture {
rk_uint slot;
rk_uint nlevels; rk_uint nlevels;
GLuint texture; GLuint texture;
}; };

View File

@ -101,7 +101,6 @@ RK_EXPORT rk_param_t rk_resolve_param(
char const * name); char const * name);
RK_EXPORT rk_texture_t rk_create_texture( RK_EXPORT rk_texture_t rk_create_texture(
rk_uint slot,
rk_texture_format format, rk_texture_format format,
rk_uint width, rk_uint width,
rk_uint height, rk_uint height,
@ -151,6 +150,7 @@ RK_EXPORT void rk_set_param_vec3(
rk_vec3 const & value); rk_vec3 const & value);
RK_EXPORT void rk_select_texture( RK_EXPORT void rk_select_texture(
rk_uint slot,
rk_texture_t texture, rk_texture_t texture,
rk_input_t sampler); rk_input_t sampler);
@ -171,6 +171,7 @@ RK_EXPORT void rk_unselect_vertices(
rk_vertices_t vertices); rk_vertices_t vertices);
RK_EXPORT void rk_unselect_texture( RK_EXPORT void rk_unselect_texture(
rk_uint slot,
rk_texture_t texture); rk_texture_t texture);
RK_EXPORT void rk_unselect_shader( RK_EXPORT void rk_unselect_shader(