promote texture_unit()
parent
4fdc043677
commit
311e5894a7
|
@ -1101,6 +1101,7 @@ typedef struct texture_t {
|
|||
texture_t texture_create(unsigned w, unsigned h, unsigned n, const void *pixels, int flags);
|
||||
texture_t texture_checker();
|
||||
void texture_destroy(texture_t *t);
|
||||
int texture_unit();
|
||||
unsigned texture_update(texture_t *t, unsigned w, unsigned h, unsigned n, const void *pixels, int flags);
|
||||
bool texture_rec_begin(texture_t *t, unsigned w, unsigned h);
|
||||
void texture_rec_end(texture_t *t);
|
||||
|
|
|
@ -17158,6 +17158,7 @@ API texture_t texture_from_mem(const void* ptr, int len, int flags);
|
|||
API texture_t texture_create(unsigned w, unsigned h, unsigned n, const void *pixels, int flags);
|
||||
API texture_t texture_checker();
|
||||
API void texture_destroy(texture_t *t);
|
||||
API int texture_unit(); // returns rolling counter
|
||||
// textureLod(filename, dir, lod);
|
||||
// void texture_add_loader( int(*loader)(const char *filename, int *w, int *h, int *bpp, int reqbpp, int flags) );
|
||||
API unsigned texture_update(texture_t *t, unsigned w, unsigned h, unsigned n, const void *pixels, int flags);
|
||||
|
@ -370072,7 +370073,7 @@ void glDebugEnable() {
|
|||
|
||||
static
|
||||
void glCopyBackbufferToTexture( texture_t *tex ) { // unused
|
||||
glActiveTexture( GL_TEXTURE0 + allocate_texture_unit() );
|
||||
glActiveTexture( GL_TEXTURE0 + texture_unit() );
|
||||
glBindTexture( GL_TEXTURE_2D, tex->id );
|
||||
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, window_width(), window_height(), 0 );
|
||||
}
|
||||
|
@ -370582,7 +370583,7 @@ void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_unif
|
|||
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }
|
||||
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
||||
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, allocate_texture_unit()); }
|
||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
||||
void shader_texture_unit(const char *sampler, unsigned id, unsigned unit) {
|
||||
// @todo. if tex.h == 1 ? GL_TEXTURE_1D : GL_TEXTURE_2D
|
||||
glUniform1i(shader_uniform(sampler), unit);
|
||||
|
@ -370723,8 +370724,7 @@ vec3 bilinear(image_t in, vec2 uv) { // image_bilinear_pixel() ?
|
|||
// -----------------------------------------------------------------------------
|
||||
// textures
|
||||
|
||||
static
|
||||
int allocate_texture_unit() {
|
||||
int texture_unit() {
|
||||
static int textureUnit = 0, totalTextureUnits = 0;
|
||||
do_once glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &totalTextureUnits);
|
||||
// ASSERT(textureUnit < totalTextureUnits, "%d texture units exceeded", totalTextureUnits);
|
||||
|
@ -373784,7 +373784,7 @@ void model_draw_call(model_t m, int shader) {
|
|||
struct iqmmesh *im = &q->meshes[i];
|
||||
|
||||
if (m.shading != SHADING_PBR) {
|
||||
shader_texture_unit("u_texture2d", q->textures[i], allocate_texture_unit());
|
||||
shader_texture_unit("u_texture2d", q->textures[i], texture_unit());
|
||||
shader_texture("u_lightmap", m.lightmap);
|
||||
|
||||
int loc;
|
||||
|
|
|
@ -45,7 +45,7 @@ void glDebugEnable() {
|
|||
|
||||
static
|
||||
void glCopyBackbufferToTexture( texture_t *tex ) { // unused
|
||||
glActiveTexture( GL_TEXTURE0 + allocate_texture_unit() );
|
||||
glActiveTexture( GL_TEXTURE0 + texture_unit() );
|
||||
glBindTexture( GL_TEXTURE_2D, tex->id );
|
||||
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, window_width(), window_height(), 0 );
|
||||
}
|
||||
|
@ -555,7 +555,7 @@ void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_unif
|
|||
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }
|
||||
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
||||
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, allocate_texture_unit()); }
|
||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
||||
void shader_texture_unit(const char *sampler, unsigned id, unsigned unit) {
|
||||
// @todo. if tex.h == 1 ? GL_TEXTURE_1D : GL_TEXTURE_2D
|
||||
glUniform1i(shader_uniform(sampler), unit);
|
||||
|
@ -696,8 +696,7 @@ vec3 bilinear(image_t in, vec2 uv) { // image_bilinear_pixel() ?
|
|||
// -----------------------------------------------------------------------------
|
||||
// textures
|
||||
|
||||
static
|
||||
int allocate_texture_unit() {
|
||||
int texture_unit() {
|
||||
static int textureUnit = 0, totalTextureUnits = 0;
|
||||
do_once glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &totalTextureUnits);
|
||||
// ASSERT(textureUnit < totalTextureUnits, "%d texture units exceeded", totalTextureUnits);
|
||||
|
@ -3757,7 +3756,7 @@ void model_draw_call(model_t m, int shader) {
|
|||
struct iqmmesh *im = &q->meshes[i];
|
||||
|
||||
if (m.shading != SHADING_PBR) {
|
||||
shader_texture_unit("u_texture2d", q->textures[i], allocate_texture_unit());
|
||||
shader_texture_unit("u_texture2d", q->textures[i], texture_unit());
|
||||
shader_texture("u_lightmap", m.lightmap);
|
||||
|
||||
int loc;
|
||||
|
|
|
@ -136,6 +136,7 @@ API texture_t texture_from_mem(const void* ptr, int len, int flags);
|
|||
API texture_t texture_create(unsigned w, unsigned h, unsigned n, const void *pixels, int flags);
|
||||
API texture_t texture_checker();
|
||||
API void texture_destroy(texture_t *t);
|
||||
API int texture_unit(); // returns rolling counter
|
||||
// textureLod(filename, dir, lod);
|
||||
// void texture_add_loader( int(*loader)(const char *filename, int *w, int *h, int *bpp, int reqbpp, int flags) );
|
||||
API unsigned texture_update(texture_t *t, unsigned w, unsigned h, unsigned n, const void *pixels, int flags);
|
||||
|
|
|
@ -17219,7 +17219,7 @@ void glDebugEnable() {
|
|||
|
||||
static
|
||||
void glCopyBackbufferToTexture( texture_t *tex ) { // unused
|
||||
glActiveTexture( GL_TEXTURE0 + allocate_texture_unit() );
|
||||
glActiveTexture( GL_TEXTURE0 + texture_unit() );
|
||||
glBindTexture( GL_TEXTURE_2D, tex->id );
|
||||
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, window_width(), window_height(), 0 );
|
||||
}
|
||||
|
@ -17729,7 +17729,7 @@ void shader_mat44(const char *uniform, mat44 m) { glUniformMatrix4fv(shader_unif
|
|||
void shader_cubemap(const char *sampler, unsigned texture) { glUniform1i(shader_uniform(sampler), 0); glBindTexture(GL_TEXTURE_CUBE_MAP, texture); }
|
||||
void shader_bool(const char *uniform, bool x) { glUniform1i(shader_uniform(uniform), x); }
|
||||
void shader_uint(const char *uniform, unsigned x ) { glUniform1ui(shader_uniform(uniform), x); }
|
||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, allocate_texture_unit()); }
|
||||
void shader_texture(const char *sampler, texture_t t) { shader_texture_unit(sampler, t.id, texture_unit()); }
|
||||
void shader_texture_unit(const char *sampler, unsigned id, unsigned unit) {
|
||||
// @todo. if tex.h == 1 ? GL_TEXTURE_1D : GL_TEXTURE_2D
|
||||
glUniform1i(shader_uniform(sampler), unit);
|
||||
|
@ -17870,8 +17870,7 @@ vec3 bilinear(image_t in, vec2 uv) { // image_bilinear_pixel() ?
|
|||
// -----------------------------------------------------------------------------
|
||||
// textures
|
||||
|
||||
static
|
||||
int allocate_texture_unit() {
|
||||
int texture_unit() {
|
||||
static int textureUnit = 0, totalTextureUnits = 0;
|
||||
do_once glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &totalTextureUnits);
|
||||
// ASSERT(textureUnit < totalTextureUnits, "%d texture units exceeded", totalTextureUnits);
|
||||
|
@ -20931,7 +20930,7 @@ void model_draw_call(model_t m, int shader) {
|
|||
struct iqmmesh *im = &q->meshes[i];
|
||||
|
||||
if (m.shading != SHADING_PBR) {
|
||||
shader_texture_unit("u_texture2d", q->textures[i], allocate_texture_unit());
|
||||
shader_texture_unit("u_texture2d", q->textures[i], texture_unit());
|
||||
shader_texture("u_lightmap", m.lightmap);
|
||||
|
||||
int loc;
|
||||
|
|
|
@ -3225,6 +3225,7 @@ API texture_t texture_from_mem(const void* ptr, int len, int flags);
|
|||
API texture_t texture_create(unsigned w, unsigned h, unsigned n, const void *pixels, int flags);
|
||||
API texture_t texture_checker();
|
||||
API void texture_destroy(texture_t *t);
|
||||
API int texture_unit(); // returns rolling counter
|
||||
// textureLod(filename, dir, lod);
|
||||
// void texture_add_loader( int(*loader)(const char *filename, int *w, int *h, int *bpp, int reqbpp, int flags) );
|
||||
API unsigned texture_update(texture_t *t, unsigned w, unsigned h, unsigned n, const void *pixels, int flags);
|
||||
|
|
Loading…
Reference in New Issue