void COpenGLRenderableObject::BindTexture(int unit /* = 0 */) { if (m_texture) { GLDebug(glActiveTexture(GL_TEXTURE0 + unit)); GLDebug(glBindTexture(GetGLTextureType(m_texture->GetTextureType()), m_texture->GetHandle())); } }
void TF::Texture::SetWrap(TextureWrap wrap) { static const u32 glWrap[] = { GL_REPEAT, // REPEAT, GL_CLAMP_TO_EDGE, // CLAMP, GL_MIRRORED_REPEAT // MIRROR, }; u32 glType = GetGLTextureType(type); u32 selection = glWrap[wrap]; glBindTexture(glType, specific.texture); glTexParameteri(glType, GL_TEXTURE_WRAP_S, selection); glTexParameteri(glType, GL_TEXTURE_WRAP_T, selection); glTexParameteri(glType, GL_TEXTURE_WRAP_R, selection); }
Result GraphicsInterfaceOpenGL::writeTexture2D(void *o_tex, int width, int height, TextureFormat format, const void *buf, size_t) { GLenum gl_format = 0; GLenum gl_type = 0; GLenum gl_itype = 0; GetGLTextureType(format, gl_format, gl_type, gl_itype); // available OpenGL 4.5 or later // glTextureSubImage2D((GLuint)(size_t)o_tex, 0, 0, 0, width, height, internal_format, internal_type, buf); auto ret = Result::OK; glBindTexture(GL_TEXTURE_2D, (GLuint)(size_t)o_tex); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, gl_format, gl_type, buf); ret = GetGLError(); glBindTexture(GL_TEXTURE_2D, 0); return ret; }
Result GraphicsInterfaceOpenGL::createTexture2D(void **dst_tex, int width, int height, TextureFormat format, const void *data, ResourceFlags flags) { GLenum gl_format = 0; GLenum gl_type = 0; GLenum gl_itype = 0; GetGLTextureType(format, gl_format, gl_type, gl_itype); auto ret = Result::OK; GLuint tex = 0; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, gl_itype, width, height, 0, gl_format, gl_type, data); ret = GetGLError(); glBindTexture(GL_TEXTURE_2D, 0); *(GLuint*)dst_tex = tex; return ret; }
Result GraphicsInterfaceOpenGL::readTexture2D(void *o_buf, size_t, void *tex, int, int, TextureFormat format) { GLenum gl_format = 0; GLenum gl_type = 0; GLenum gl_itype = 0; GetGLTextureType(format, gl_format, gl_type, gl_itype); // available OpenGL 4.5 or later // glGetTextureImage((GLuint)(size_t)tex, 0, internal_format, internal_type, bufsize, o_buf); sync(); auto ret = Result::OK; glBindTexture(GL_TEXTURE_2D, (GLuint)(size_t)tex); glGetTexImage(GL_TEXTURE_2D, 0, gl_format, gl_type, o_buf); ret = GetGLError(); glBindTexture(GL_TEXTURE_2D, 0); return ret; }
void TF::Texture::SetFiltering(TextureFilter filter) { static const struct { u32 min, mag; } glFilters[] = { { GL_NEAREST, GL_NEAREST }, // NONE { GL_LINEAR, GL_LINEAR }, // LINEAR { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR }, // TRILINEAR }; if ( filter == TFLT_TRILINEAR && mipLevels == 1 ) { LOGWARNING("Trying to set trilinear filtering on texture without mipmaps, defaulting to linear"); filter = TFLT_LINEAR; } u32 glType = GetGLTextureType(type); glBindTexture(glType, specific.texture); glTexParameteri(glType, GL_TEXTURE_MIN_FILTER, glFilters[filter].min); glTexParameteri(glType, GL_TEXTURE_MAG_FILTER, glFilters[filter].mag); }