void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUTexture *tex) { GLenum arbnumber; int number = GPU_texture_bound_number(tex); int bindcode = GPU_texture_opengl_bindcode(tex); int target = GPU_texture_target(tex); if (number >= GPU_max_textures()) { fprintf(stderr, "Not enough texture slots.\n"); return; } if (number == -1) return; if (location == -1) return; GPU_ASSERT_NO_GL_ERRORS("Pre Uniform Texture"); arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + number); if (number != 0) glActiveTexture(arbnumber); if (bindcode != 0) glBindTexture(target, bindcode); else GPU_invalid_tex_bind(target); glUniform1i(location, number); glEnable(target); if (number != 0) glActiveTexture(GL_TEXTURE0); GPU_ASSERT_NO_GL_ERRORS("Post Uniform Texture"); }
void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter) { if (tex->number >= GPU_max_textures()) { fprintf(stderr, "Not enough texture slots.\n"); return; } if (tex->number == -1) return; GPU_ASSERT_NO_GL_ERRORS("Pre Texture Unbind"); GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); if (tex->number != 0) glActiveTexture(arbnumber); if (tex->depth) { if (compare) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); } if (use_filter) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } if (tex->number != 0) glActiveTexture(GL_TEXTURE0); GPU_ASSERT_NO_GL_ERRORS("Post Texture Unbind"); }
void GPU_texture_bind(GPUTexture *tex, int number) { if (number >= GPU_max_textures()) { fprintf(stderr, "Not enough texture slots.\n"); return; } if ((G.debug & G_DEBUG)) { if (tex->fb && GPU_framebuffer_bound(tex->fb)) { fprintf(stderr, "Feedback loop warning!: Attempting to bind texture attached to current framebuffer!\n"); } } if (number < 0) return; GPU_ASSERT_NO_GL_ERRORS("Pre Texture Bind"); GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + number); if (number != 0) glActiveTexture(arbnumber); if (tex->bindcode != 0) { glBindTexture(tex->target, tex->bindcode); } else GPU_invalid_tex_bind(tex->target); glEnable(tex->target); if (number != 0) glActiveTexture(GL_TEXTURE0); tex->number = number; GPU_ASSERT_NO_GL_ERRORS("Post Texture Bind"); }
void GPU_texture_unbind(GPUTexture *tex) { if (tex->number >= GPU_max_textures()) { fprintf(stderr, "Not enough texture slots.\n"); return; } if (tex->number == -1) return; GPU_ASSERT_NO_GL_ERRORS("Pre Texture Unbind"); GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number); if (tex->number != 0) glActiveTexture(arbnumber); glBindTexture(tex->target, 0); glDisable(tex->target); glBindTexture(tex->target_base, 0); glDisable(tex->target_base); if (tex->number != 0) glActiveTexture(GL_TEXTURE0); tex->number = -1; GPU_ASSERT_NO_GL_ERRORS("Post Texture Unbind"); }