void gl4es_glTextureParameteriv(GLuint texture, GLenum target, GLenum pname, const GLint *param) { text(glTexParameteriv(target, pname, param)); }
void Texture::setParameters( GLenum pname, const GLint* params ) { KVS_ASSERT( this->isBound() ); KVS_GL_CALL( glTexParameteriv( m_target, pname, params ) ); }
/** * @internal * @~English * @brief Convert deprecated legacy-format texture to modern format. * * The function sets the GL_TEXTURE_SWIZZLEs necessary to get the same * behavior as the legacy format. * * @param [in] target texture target on which the swizzle will * be set. * @param [in, out] pFormat pointer to variable holding the base format of the * texture. The new base format is written here. * @param [in, out] pInternalFormat pointer to variable holding the internalformat * of the texture. The new internalformat is * written here. * @return void unrecognized formats will be passed on to OpenGL. Any loading error * that arises will be handled in the usual way. */ static void convertFormat(GLenum target, GLint* pFormat, GLint* pInternalFormat) { switch (*pFormat) { case GL_ALPHA: { GLenum swizzle[] = {GL_ZERO, GL_ZERO, GL_ZERO, GL_RED}; *pFormat = GL_RED; glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle); switch (*pInternalFormat) { case GL_ALPHA: case GL_ALPHA4: case GL_ALPHA8: *pInternalFormat = GL_R8; break; case GL_ALPHA12: case GL_ALPHA16: *pInternalFormat = GL_R16; break; } } case GL_LUMINANCE: { GLenum swizzle[] = {GL_RED, GL_RED, GL_RED, GL_ONE}; *pFormat = GL_RED; glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle); switch (*pInternalFormat) { case GL_LUMINANCE: case GL_LUMINANCE4: case GL_LUMINANCE8: *pInternalFormat = GL_R8; break; case GL_LUMINANCE12: case GL_LUMINANCE16: *pInternalFormat = GL_R16; break; #if 0 // XXX Must avoid doing the swizzle in these cases case GL_SLUMINANCE: case GL_SLUMINANCE8: *pInternalFormat = GL_SRGB8; break; #endif } break; } case GL_LUMINANCE_ALPHA: { GLenum swizzle[] = {GL_RED, GL_RED, GL_RED, GL_GREEN}; *pFormat = GL_RG; glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle); switch (*pInternalFormat) { case GL_LUMINANCE_ALPHA: case GL_LUMINANCE4_ALPHA4: case GL_LUMINANCE6_ALPHA2: case GL_LUMINANCE8_ALPHA8: *pInternalFormat = GL_RG8; break; case GL_LUMINANCE12_ALPHA4: case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: *pInternalFormat = GL_RG16; break; #if 0 // XXX Must avoid doing the swizzle in these cases case GL_SLUMINANCE_ALPHA: case GL_SLUMINANCE8_ALPHA8: *pInternalFormat = GL_SRGB8_ALPHA8; break; #endif } break; } case GL_INTENSITY: { GLenum swizzle[] = {GL_RED, GL_RED, GL_RED, GL_RED}; *pFormat = GL_RED; glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle); switch (*pInternalFormat) { case GL_INTENSITY: case GL_INTENSITY4: case GL_INTENSITY8: *pInternalFormat = GL_R8; break; case GL_INTENSITY12: case GL_INTENSITY16: *pInternalFormat = GL_R16; break; } break; } default: break; } }
static bool gl_raster_font_upload_atlas(gl_raster_t *font) { unsigned i, j; GLint gl_internal = GL_LUMINANCE_ALPHA; GLenum gl_format = GL_LUMINANCE_ALPHA; size_t ncomponents = 2; uint8_t *tmp = NULL; #if 0 bool ancient = false; /* add a check here if needed */ #endif #if defined(GL_VERSION_3_0) struct retro_hw_render_callback *hwr = video_driver_get_hw_context(); #endif #if 0 if (ancient) { gl_internal = GL_RGBA; gl_format = GL_RGBA; ncomponents = 4; } #endif #if defined(GL_VERSION_3_0) if (gl_query_core_context_in_use() || (hwr->context_type == RETRO_HW_CONTEXT_OPENGL && hwr->version_major >= 3)) { GLint swizzle[] = { GL_ONE, GL_ONE, GL_ONE, GL_RED }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); gl_internal = GL_R8; gl_format = GL_RED; ncomponents = 1; } #endif tmp = (uint8_t*)calloc(font->tex_height, font->tex_width * ncomponents); if (!tmp) return false; for (i = 0; i < font->atlas->height; ++i) { const uint8_t *src = &font->atlas->buffer[i * font->atlas->width]; uint8_t *dst = &tmp[i * font->tex_width * ncomponents]; switch (ncomponents) { case 1: memcpy(dst, src, font->atlas->width); break; case 2: for (j = 0; j < font->atlas->width; ++j) { *dst++ = 0xff; *dst++ = *src++; } break; case 4: for (j = 0; j < font->atlas->width; ++j) { *dst++ = 0xff; *dst++ = 0xff; *dst++ = 0xff; *dst++ = *src++; } break; default: RARCH_ERR("Unsupported number of components: %u\n", (unsigned)ncomponents); free(tmp); return false; } } glTexImage2D(GL_TEXTURE_2D, 0, gl_internal, font->tex_width, font->tex_height, 0, gl_format, GL_UNSIGNED_BYTE, tmp); free(tmp); return true; }
void GL::texParameteriv(Enum target, Enum pname, const Int * params) { glTexParameteriv(target, pname, params); CHECK_GL_ERROR3(glTexParameteriv, target, pname, params); }
void Texture::setParam(GLenum pname, GLint* value) { glTexParameteriv(target, pname, value); }
uintptr_t processFn(struct fnargs* args, char* parg) { uintptr_t ret = 0; switch (args->fn) { case glfnUNDEFINED: abort(); // bad glfn break; case glfnActiveTexture: glActiveTexture((GLenum)args->a0); break; case glfnAttachShader: glAttachShader((GLint)args->a0, (GLint)args->a1); break; case glfnBindAttribLocation: glBindAttribLocation((GLint)args->a0, (GLint)args->a1, (GLchar*)args->a2); break; case glfnBindBuffer: glBindBuffer((GLenum)args->a0, (GLuint)args->a1); break; case glfnBindFramebuffer: glBindFramebuffer((GLenum)args->a0, (GLint)args->a1); break; case glfnBindRenderbuffer: glBindRenderbuffer((GLenum)args->a0, (GLint)args->a1); break; case glfnBindTexture: glBindTexture((GLenum)args->a0, (GLint)args->a1); break; case glfnBlendColor: glBlendColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnBlendEquation: glBlendEquation((GLenum)args->a0); break; case glfnBlendEquationSeparate: glBlendEquationSeparate((GLenum)args->a0, (GLenum)args->a1); break; case glfnBlendFunc: glBlendFunc((GLenum)args->a0, (GLenum)args->a1); break; case glfnBlendFuncSeparate: glBlendFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3); break; case glfnBufferData: glBufferData((GLenum)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg, (GLenum)args->a2); break; case glfnBufferSubData: glBufferSubData((GLenum)args->a0, (GLint)args->a1, (GLsizeiptr)args->a2, (GLvoid*)parg); break; case glfnCheckFramebufferStatus: ret = glCheckFramebufferStatus((GLenum)args->a0); break; case glfnClear: glClear((GLenum)args->a0); break; case glfnClearColor: glClearColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnClearDepthf: glClearDepthf(*(GLfloat*)&args->a0); break; case glfnClearStencil: glClearStencil((GLint)args->a0); break; case glfnColorMask: glColorMask((GLboolean)args->a0, (GLboolean)args->a1, (GLboolean)args->a2, (GLboolean)args->a3); break; case glfnCompileShader: glCompileShader((GLint)args->a0); break; case glfnCompressedTexImage2D: glCompressedTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLsizeiptr)args->a6, (GLvoid*)parg); break; case glfnCompressedTexSubImage2D: glCompressedTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLenum)args->a6, (GLsizeiptr)args->a7, (GLvoid*)parg); break; case glfnCopyTexImage2D: glCopyTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7); break; case glfnCopyTexSubImage2D: glCopyTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7); break; case glfnCreateProgram: ret = glCreateProgram(); break; case glfnCreateShader: ret = glCreateShader((GLenum)args->a0); break; case glfnCullFace: glCullFace((GLenum)args->a0); break; case glfnDeleteBuffer: glDeleteBuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteFramebuffer: glDeleteFramebuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteProgram: glDeleteProgram((GLint)args->a0); break; case glfnDeleteRenderbuffer: glDeleteRenderbuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteShader: glDeleteShader((GLint)args->a0); break; case glfnDeleteTexture: glDeleteTextures(1, (const GLuint*)(&args->a0)); break; case glfnDepthFunc: glDepthFunc((GLenum)args->a0); break; case glfnDepthMask: glDepthMask((GLboolean)args->a0); break; case glfnDepthRangef: glDepthRangef(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1); break; case glfnDetachShader: glDetachShader((GLint)args->a0, (GLint)args->a1); break; case glfnDisable: glDisable((GLenum)args->a0); break; case glfnDisableVertexAttribArray: glDisableVertexAttribArray((GLint)args->a0); break; case glfnDrawArrays: glDrawArrays((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2); break; case glfnDrawElements: glDrawElements((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (void*)args->a3); break; case glfnEnable: glEnable((GLenum)args->a0); break; case glfnEnableVertexAttribArray: glEnableVertexAttribArray((GLint)args->a0); break; case glfnFinish: glFinish(); break; case glfnFlush: glFlush(); break; case glfnFramebufferRenderbuffer: glFramebufferRenderbuffer((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3); break; case glfnFramebufferTexture2D: glFramebufferTexture2D((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4); break; case glfnFrontFace: glFrontFace((GLenum)args->a0); break; case glfnGenBuffer: glGenBuffers(1, (GLuint*)&ret); break; case glfnGenFramebuffer: glGenFramebuffers(1, (GLuint*)&ret); break; case glfnGenRenderbuffer: glGenRenderbuffers(1, (GLuint*)&ret); break; case glfnGenTexture: glGenTextures(1, (GLuint*)&ret); break; case glfnGenerateMipmap: glGenerateMipmap((GLenum)args->a0); break; case glfnGetActiveAttrib: glGetActiveAttrib( (GLuint)args->a0, (GLuint)args->a1, (GLsizei)args->a2, NULL, (GLint*)&ret, (GLenum*)args->a3, (GLchar*)parg); break; case glfnGetActiveUniform: glGetActiveUniform( (GLuint)args->a0, (GLuint)args->a1, (GLsizei)args->a2, NULL, (GLint*)&ret, (GLenum*)args->a3, (GLchar*)parg); break; case glfnGetAttachedShaders: glGetAttachedShaders((GLuint)args->a0, (GLsizei)args->a1, (GLsizei*)&ret, (GLuint*)parg); break; case glfnGetAttribLocation: ret = glGetAttribLocation((GLint)args->a0, (GLchar*)args->a1); break; case glfnGetBooleanv: glGetBooleanv((GLenum)args->a0, (GLboolean*)parg); break; case glfnGetBufferParameteri: glGetBufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetFloatv: glGetFloatv((GLenum)args->a0, (GLfloat*)parg); break; case glfnGetIntegerv: glGetIntegerv((GLenum)args->a0, (GLint*)parg); break; case glfnGetError: ret = glGetError(); break; case glfnGetFramebufferAttachmentParameteriv: glGetFramebufferAttachmentParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint*)&ret); break; case glfnGetProgramiv: glGetProgramiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetProgramInfoLog: glGetProgramInfoLog((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetRenderbufferParameteriv: glGetRenderbufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetShaderiv: glGetShaderiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetShaderInfoLog: glGetShaderInfoLog((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetShaderPrecisionFormat: glGetShaderPrecisionFormat((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg, &((GLint*)parg)[2]); break; case glfnGetShaderSource: glGetShaderSource((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetString: ret = (uintptr_t)glGetString((GLenum)args->a0); break; case glfnGetTexParameterfv: glGetTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnGetTexParameteriv: glGetTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnGetUniformfv: glGetUniformfv((GLuint)args->a0, (GLint)args->a1, (GLfloat*)parg); break; case glfnGetUniformiv: glGetUniformiv((GLuint)args->a0, (GLint)args->a1, (GLint*)parg); break; case glfnGetUniformLocation: ret = glGetUniformLocation((GLint)args->a0, (GLchar*)args->a1); break; case glfnGetVertexAttribfv: glGetVertexAttribfv((GLuint)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnGetVertexAttribiv: glGetVertexAttribiv((GLuint)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnHint: glHint((GLenum)args->a0, (GLenum)args->a1); break; case glfnIsBuffer: ret = glIsBuffer((GLint)args->a0); break; case glfnIsEnabled: ret = glIsEnabled((GLenum)args->a0); break; case glfnIsFramebuffer: ret = glIsFramebuffer((GLint)args->a0); break; case glfnIsProgram: ret = glIsProgram((GLint)args->a0); break; case glfnIsRenderbuffer: ret = glIsRenderbuffer((GLint)args->a0); break; case glfnIsShader: ret = glIsShader((GLint)args->a0); break; case glfnIsTexture: ret = glIsTexture((GLint)args->a0); break; case glfnLineWidth: glLineWidth(*(GLfloat*)&args->a0); break; case glfnLinkProgram: glLinkProgram((GLint)args->a0); break; case glfnPixelStorei: glPixelStorei((GLenum)args->a0, (GLint)args->a1); break; case glfnPolygonOffset: glPolygonOffset(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1); break; case glfnReadPixels: glReadPixels((GLint)args->a0, (GLint)args->a1, (GLsizei)args->a2, (GLsizei)args->a3, (GLenum)args->a4, (GLenum)args->a5, (void*)parg); break; case glfnReleaseShaderCompiler: glReleaseShaderCompiler(); break; case glfnRenderbufferStorage: glRenderbufferStorage((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnSampleCoverage: glSampleCoverage(*(GLfloat*)&args->a0, (GLboolean)args->a1); break; case glfnScissor: glScissor((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnShaderSource: #if defined(os_ios) || defined(os_osx) glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar *const *)args->a2, NULL); #else glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar **)args->a2, NULL); #endif break; case glfnStencilFunc: glStencilFunc((GLenum)args->a0, (GLint)args->a1, (GLuint)args->a2); break; case glfnStencilFuncSeparate: glStencilFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLuint)args->a3); break; case glfnStencilMask: glStencilMask((GLuint)args->a0); break; case glfnStencilMaskSeparate: glStencilMaskSeparate((GLenum)args->a0, (GLuint)args->a1); break; case glfnStencilOp: glStencilOp((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2); break; case glfnStencilOpSeparate: glStencilOpSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3); break; case glfnTexImage2D: glTexImage2D( (GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLsizei)args->a3, (GLsizei)args->a4, 0, // border (GLenum)args->a5, (GLenum)args->a6, (const GLvoid*)parg); break; case glfnTexSubImage2D: glTexSubImage2D( (GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLsizei)args->a4, (GLsizei)args->a5, (GLenum)args->a6, (GLenum)args->a7, (const GLvoid*)parg); break; case glfnTexParameterf: glTexParameterf((GLenum)args->a0, (GLenum)args->a1, *(GLfloat*)&args->a2); break; case glfnTexParameterfv: glTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnTexParameteri: glTexParameteri((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2); break; case glfnTexParameteriv: glTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnUniform1f: glUniform1f((GLint)args->a0, *(GLfloat*)&args->a1); break; case glfnUniform1fv: glUniform1fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform1i: glUniform1i((GLint)args->a0, (GLint)args->a1); break; case glfnUniform1iv: glUniform1iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform2f: glUniform2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2); break; case glfnUniform2fv: glUniform2fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform2i: glUniform2i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2); break; case glfnUniform2iv: glUniform2iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform3f: glUniform3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnUniform3fv: glUniform3fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform3i: glUniform3i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnUniform3iv: glUniform3iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform4f: glUniform4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4); break; case glfnUniform4fv: glUniform4fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform4i: glUniform4i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4); break; case glfnUniform4iv: glUniform4iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniformMatrix2fv: glUniformMatrix2fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix3fv: glUniformMatrix3fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix4fv: glUniformMatrix4fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUseProgram: glUseProgram((GLint)args->a0); break; case glfnValidateProgram: glValidateProgram((GLint)args->a0); break; case glfnVertexAttrib1f: glVertexAttrib1f((GLint)args->a0, *(GLfloat*)&args->a1); break; case glfnVertexAttrib1fv: glVertexAttrib1fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib2f: glVertexAttrib2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2); break; case glfnVertexAttrib2fv: glVertexAttrib2fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib3f: glVertexAttrib3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnVertexAttrib3fv: glVertexAttrib3fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib4f: glVertexAttrib4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4); break; case glfnVertexAttrib4fv: glVertexAttrib4fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttribPointer: glVertexAttribPointer((GLuint)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLboolean)args->a3, (GLsizei)args->a4, (const GLvoid*)args->a5); break; case glfnViewport: glViewport((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; } return ret; }
DrawTexture::DrawTexture(uint32_t width, uint32_t height, const char* const szArgs, const std::string sBasePath) : LoadTestSample(width, height, sBasePath) { GLint iCropRect[4] = {0, 0, 0, 0}; const GLchar* szExtensions = (const GLchar*)glGetString(GL_EXTENSIONS); const char* filename; std::string pathname; GLenum target; GLboolean isMipmapped; GLboolean npotTexture; GLenum glerror; GLubyte* pKvData; GLuint kvDataLen; KTX_dimensions dimensions; KTX_error_code ktxresult; KTX_hash_table kvtable; GLint sign_s = 1, sign_t = 1; bInitialized = false; gnTexture = 0; typedef void (*PFN_voidFunction)(void); if (strstr(szExtensions, "OES_draw_texture") != NULL) { /* * This strange casting is because SDL_GL_GetProcAddress returns a * void* thus is not compatible with ISO C which forbids conversion * of object pointers to function pointers. The cast masks the * conversion from the compiler thus no warning even though -pedantic * is set. Ideally, if SDL_GL_GetPRocAddress returned a (void*)(void), * the assignment would be * * glDrawFooOES = (PFNHLDRAWFOOOESPROC)SDL_GetProcAddress(...) */ \ *(void **)(&glDrawTexsOES) = SDL_GL_GetProcAddress("glDrawTexsOES"); *(void **)(&glDrawTexiOES) = SDL_GL_GetProcAddress("glDrawTexiOES"); *(void **)(&glDrawTexxOES) = SDL_GL_GetProcAddress("glDrawTexxOES"); *(void **)(&glDrawTexfOES) = SDL_GL_GetProcAddress("glDrawTexfOES"); *(void **)(&glDrawTexsvOES) = SDL_GL_GetProcAddress("glDrawTexsvOES"); *(void **)(&glDrawTexivOES) = SDL_GL_GetProcAddress("glDrawTexivOES"); *(void **)(&glDrawTexxvOES) = SDL_GL_GetProcAddress("glDrawTexxvOES"); *(void **)(&glDrawTexfvOES) = SDL_GL_GetProcAddress("glDrawTexfvOES"); } else { /* Can't do anything */ std::stringstream message; message << "DrawTexture: this OpenGL ES implementation does not support" << " OES_draw_texture. Can't Run Test"; throw std::runtime_error(message.str()); } if (strstr(szExtensions, "OES_texture_npot") != NULL) bNpotSupported = GL_TRUE; else bNpotSupported = GL_FALSE; if ((filename = strchr(szArgs, ' ')) != NULL) { npotTexture = GL_FALSE; if (!strncmp(szArgs, "--npot ", 7)) { npotTexture = GL_TRUE; #if defined(DEBUG) } else { assert(0); /* Unknown argument in sampleInvocations */ #endif } } else { filename = szArgs; npotTexture = GL_FALSE; } if (npotTexture && !bNpotSupported) { /* Load error texture. */ filename = "testimages/no-npot.ktx"; } pathname = getAssetPath() + filename; ktxresult = ktxLoadTextureN(pathname.c_str(), &gnTexture, &target, &dimensions, &isMipmapped, &glerror, &kvDataLen, &pKvData); if (KTX_SUCCESS == ktxresult) { if (target != GL_TEXTURE_2D) { /* Can only draw 2D textures */ glDeleteTextures(1, &gnTexture); return; } ktxresult = ktxHashTable_Deserialize(kvDataLen, pKvData, &kvtable); if (KTX_SUCCESS == ktxresult) { GLchar* pValue; GLuint valueLen; if (KTX_SUCCESS == ktxHashTable_FindValue(kvtable, KTX_ORIENTATION_KEY, &valueLen, (void**)&pValue)) { char s, t; if (sscanf(pValue, /*valueLen,*/ KTX_ORIENTATION2_FMT, &s, &t) == 2) { if (s == 'l') sign_s = -1; if (t == 'd') sign_t = -1; } } ktxHashTable_Destroy(kvtable); free(pKvData); } iCropRect[2] = uTexWidth = dimensions.width; iCropRect[3] = uTexHeight = dimensions.height; iCropRect[2] *= sign_s; iCropRect[3] *= sign_t; glEnable(target); if (isMipmapped) // Enable bilinear mipmapping. // TO DO: application can consider inserting a key,value pair in // the KTX file that indicates what type of filtering to use. glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); else glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameteriv(target, GL_TEXTURE_CROP_RECT_OES, iCropRect); /* Check for any errors */ assert(GL_NO_ERROR == glGetError()); } else { std::stringstream message; message << "Load of texture from \"" << pathname << "\" failed: "; if (ktxresult == KTX_GL_ERROR) { message << std::showbase << "GL error " << std::hex << glerror << "occurred."; } else { message << ktxErrorString(ktxresult); } throw std::runtime_error(message.str()); } glClearColor(0.4f, 0.4f, 0.5f, 1.0f); glColor4f(1.0f, 1.0f, 0.0f, 1.0f); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_BYTE, 0, (GLvoid *)frame_position); bInitialized = GL_TRUE; }
void drawGLScene(AndroidContext *rc) { #ifdef DROID_EXTREME_LOGS LOG( ANDROID_LOG_VERBOSE, TAG, "drawGLScene : start"); #endif /* DROID_EXTREME_LOGS */ GLfloat vertices[4][3]; GLfloat texcoord[4][2]; // int i, j; float rgba[4]; #ifdef GLES_FRAMEBUFFER_TEST glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); #endif // Reset states rgba[0] = rgba[1] = rgba[2] = 0.f; rgba[0] = 1.f; glColor4f(1.f, 1.f, 1.f, 1.f); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, rgba); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, rgba); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, rgba); glDisable(GL_CULL_FACE | GL_NORMALIZE | GL_LIGHTING | GL_BLEND | GL_FOG | GL_COLOR_MATERIAL | GL_TEXTURE_2D); /* Clear The Screen And The Depth Buffer */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, rc->texID); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // for ( i = 0; i < rc->height/2; i++ ) // for ( j = 0; j < rc->width; j++ ) // rc->texData[ i*rc->width*NBPP + j*NBPP + 3] = 200; // memset(rc->texData, 255, 4 * rc->width * rc->height ); #ifndef GLES_FRAMEBUFFER_TEST glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, rc->tex_width, rc->tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rc->texData ); #endif if ( rc->draw_texture ) { int cropRect[4] = {0,rc->height,rc->width,-rc->height}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); glDrawTexsOES(0, 0, 0, rc->width, rc->height); } else { /* Enable VERTEX array */ glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); /* Setup pointer to VERTEX array */ glVertexPointer(3, GL_FLOAT, 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, texcoord); /* Move Left 1.5 Units And Into The Screen 6.0 */ glLoadIdentity(); //glTranslatef(0.0f, 0.0f, -3.3f); //glTranslatef(0.0f, 0.0f, -2.3f); /* Top Right Of The Quad */ vertices[0][0]=rc->tex_width; vertices[0][1]=rc->tex_height; vertices[0][2]=0.0f; texcoord[0][0]=1.f; texcoord[0][1]=0.f; /* Top Left Of The Quad */ vertices[1][0]=0.f; vertices[1][1]=rc->tex_height; vertices[1][2]=0.0f; texcoord[1][0]=0.f; texcoord[1][1]=0.f; /* Bottom Left Of The Quad */ vertices[2][0]=rc->tex_width; vertices[2][1]=0.f; vertices[2][2]=0.0f; texcoord[2][0]=1.f; texcoord[2][1]=1.f; /* Bottom Right Of The Quad */ vertices[3][0]=0.f; vertices[3][1]=0.f; vertices[3][2]=0.0f; texcoord[3][0]=0.f; texcoord[3][1]=1.f; /* Drawing using triangle strips, draw triangles using 4 vertices */ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); /* Disable vertex array */ glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } glDisable(GL_TEXTURE_2D); /* Flush all drawings */ glFinish(); #ifdef GLES_FRAMEBUFFER_TEST glBindFramebufferOES(GL_FRAMEBUFFER_OES, rc->framebuff); #endif #ifdef DROID_EXTREME_LOGS LOG( ANDROID_LOG_VERBOSE, TAG, "drawGLScene : end"); #endif /* DROID_EXTREME_LOGS */ }
void texture::binding::set_swizzle( swizzle r, swizzle g, swizzle b, swizzle a ) { GLint mask[4] = { static_cast<GLint>(r), static_cast<GLint>(g), static_cast<GLint>(b), static_cast<GLint>(a) }; glTexParameteriv( _target, GL_TEXTURE_SWIZZLE_RGBA, mask ); }
M(void, glTexParameteriv, jint target, jint pname, jobject params) { glTexParameteriv(target, pname, BUFF(GLint, params)); }
void _glTexParameteriv( int target,int pname,Array<int> params,int offset ) { glTexParameteriv( target,pname,¶ms[offset] ); }
void gles2_glTexParameteriv(void *_glfuncs, GLenum target, GLenum pname, const GLint* params) { glTexParameteriv(target, pname, params); }
void gl4es_glMultiTexParameteriv(GLenum texunit, GLenum target, GLenum pname, const GLint *param) { text(glTexParameteriv(target, pname, param)); }
void GlfBaseTexture::_CreateTexture(GlfBaseTextureDataConstPtr texData, bool const useMipmaps, int const unpackCropTop, int const unpackCropBottom, int const unpackCropLeft, int const unpackCropRight) { TRACE_FUNCTION(); if (texData && texData->HasRawBuffer()) { glBindTexture(GL_TEXTURE_2D, _textureName); // Check if mip maps have been requested, if so, it will either // enable automatic generation or use the ones loaded in cpu memory int numMipLevels = 1; if (useMipmaps) { numMipLevels = texData->GetNumMipLevels(); // When we are using uncompressed textures and late cropping // we won't use cpu loaded mips. if (!texData->IsCompressed() && (unpackCropRight || unpackCropLeft || unpackCropTop || unpackCropBottom)) { numMipLevels = 1; } if (numMipLevels > 1) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, numMipLevels-1); } else { glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); } } else { glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); } if (texData->IsCompressed()) { // Compressed textures don't have as many options, so // we just need to send the mips to the driver. for (int i = 0 ; i < numMipLevels; i++) { glCompressedTexImage2D( GL_TEXTURE_2D, i, texData->GLInternalFormat(), texData->ResizedWidth(i), texData->ResizedHeight(i), 0, texData->ComputeBytesUsedByMip(i), texData->GetRawBuffer(i)); } } else { // Uncompressed textures can have cropping and other special // behaviours. if (GlfGetNumElements(texData->GLFormat()) == 1) { GLint swizzleMask[] = {GL_RED, GL_RED, GL_RED, GL_ONE}; glTexParameteriv( GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } // If we are not sending full mipchains to the gpu then we can // do some extra work in the driver to prepare our textures. if (numMipLevels == 1) { int texDataWidth = texData->ResizedWidth(); int texDataHeight = texData->ResizedHeight(); int unpackRowLength = texDataWidth; int unpackSkipPixels = 0; int unpackSkipRows = 0; if (unpackCropTop < 0 || unpackCropTop > texDataHeight) { return; } else if (unpackCropTop > 0) { unpackSkipRows = unpackCropTop; texDataHeight -= unpackCropTop; } if (unpackCropBottom < 0 || unpackCropBottom > texDataHeight) { return; } else if (unpackCropBottom) { texDataHeight -= unpackCropBottom; } if (unpackCropLeft < 0 || unpackCropLeft > texDataWidth) { return; } else { unpackSkipPixels = unpackCropLeft; texDataWidth -= unpackCropLeft; } if (unpackCropRight < 0 || unpackCropRight > texDataWidth) { return; } else if (unpackCropRight > 0) { texDataWidth -= unpackCropRight; } glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels); glPixelStorei(GL_UNPACK_SKIP_ROWS, unpackSkipRows); // Send the mip to the driver now glTexImage2D( GL_TEXTURE_2D, 0, texData->GLInternalFormat(), texDataWidth, texDataHeight, 0, texData->GLFormat(), texData->GLType(), texData->GetRawBuffer(0)); // Reset the OpenGL state if we have modify it previously glPopClientAttrib(); } else { // Send the mips to the driver now for (int i = 0 ; i < numMipLevels; i++) { glTexImage2D( GL_TEXTURE_2D, i, texData->GLInternalFormat(), texData->ResizedWidth(i), texData->ResizedHeight(i), 0, texData->GLFormat(), texData->GLType(), texData->GetRawBuffer(i)); } } } glBindTexture(GL_TEXTURE_2D, 0); _SetMemoryUsed(texData->ComputeBytesUsed()); } }
void Texture::parameter( const GLenum pname, GLint * ip ) { glTexParameteriv( m_target, pname, ip ); }
void operator()(GLenum target, GLenum pname, const GLint *param) { glTexParameteriv(target, pname, param); }
status_t BootAnimation::initTexture(void* buffer, size_t len) { //StopWatch watch("blah"); SkBitmap bitmap; SkMemoryStream stream(buffer, len); SkImageDecoder* codec = SkImageDecoder::Factory(&stream); codec->setDitherImage(false); if (codec) { codec->decode(&stream, &bitmap, SkBitmap::kRGB_565_Config, SkImageDecoder::kDecodePixels_Mode); delete codec; } // ensure we can call getPixels(). No need to call unlock, since the // bitmap will go out of scope when we return from this method. bitmap.lockPixels(); const int w = bitmap.width(); const int h = bitmap.height(); const void* p = bitmap.getPixels(); GLint crop[4] = { 0, h, w, -h }; int tw = 1 << (31 - __builtin_clz(w)); int th = 1 << (31 - __builtin_clz(h)); if (tw < w) tw <<= 1; if (th < h) th <<= 1; switch (bitmap.getConfig()) { case SkBitmap::kARGB_8888_Config: if (tw != w || th != h) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p); } else { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, p); } break; case SkBitmap::kRGB_565_Config: if (tw != w || th != h) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); } else { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); } break; default: break; } glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); return NO_ERROR; }
void Texture::SetParamFloatVector(unsigned int pName, int * param){ GLCALL( glBindTexture(type, buffer) ); GLCALL( glTexParameteriv(type, pName, param) ); }
void Ex06_02::InitGL() { if (! LoadGL() ) return; ShaderInfo base_shaders[] = { { GL_VERTEX_SHADER, "Shaders/sh06_02.vert" }, { GL_FRAGMENT_SHADER, "Shaders/sh06_02.frag" }, { GL_NONE, NULL } }; base_prog = LoadShaders( base_shaders ); glGenBuffers(1, &quad_vbo); glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); static const GLfloat quad_data[] = { 0.75f, -0.75f, -0.75f, -0.75f, -0.75f, 0.75f, 0.75f, 0.75f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }; glBufferData(GL_ARRAY_BUFFER, sizeof(quad_data), quad_data, GL_STATIC_DRAW); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(8 * sizeof(float))); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glLinkProgram(base_prog); glGenTextures(1, &tex_checkerboard); glBindTexture(GL_TEXTURE_2D, tex_checkerboard); glTexStorage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 8, 8); // The following is an 8x8 checkerboard pattern using // GL_RED, GL_UNSIGNED_BYTE data. static const unsigned char tex_checkerboard_data[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF }; glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RED, GL_UNSIGNED_BYTE, tex_checkerboard_data); static const GLint swizzles[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzles); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glGenerateMipmap(GL_TEXTURE_2D); glGenTextures(1, &tex_color); glBindTexture(GL_TEXTURE_2D, tex_color); glTexStorage2D(GL_TEXTURE_2D, 2, GL_RGBA32F, 2, 2); // The following data represents a 2x2 texture with red, // green, blue, and yellow texels represented as GL_RGBA, // GL_FLOAT data. static const GLfloat tex_color_data[] = { // Red texel Green texel 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, // Blue texel Yellow texel 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f }; glTexSubImage2D(GL_TEXTURE_2D, // target 0, // First mipmap level 0, 0, // x and y offset 2, 2, // width and height GL_RGBA, GL_FLOAT, // format and type tex_color_data); // data glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glGenerateMipmap(GL_TEXTURE_2D); }
GLuint vglLoadTexture(const char* filename, GLuint texture, vglImageData* image) { vglImageData local_image; int level; if (image == 0) image = &local_image; vglLoadImage(filename, image); if (texture == 0) { glGenTextures(1, &texture); } glBindTexture(image->target, texture); GLubyte * ptr = (GLubyte *)image->mip[0].data; switch (image->target) { case GL_TEXTURE_1D: glTexStorage1D(image->target, image->mipLevels, image->internalFormat, image->mip[0].width); for (level = 0; level < image->mipLevels; ++level) { glTexSubImage1D(GL_TEXTURE_1D, level, 0, image->mip[level].width, image->format, image->type, image->mip[level].data); } break; case GL_TEXTURE_1D_ARRAY: glTexStorage2D(image->target, image->mipLevels, image->internalFormat, image->mip[0].width, image->slices); for (level = 0; level < image->mipLevels; ++level) { glTexSubImage2D(GL_TEXTURE_1D, level, 0, 0, image->mip[level].width, image->slices, image->format, image->type, image->mip[level].data); } break; case GL_TEXTURE_2D: glTexStorage2D(image->target, image->mipLevels, image->internalFormat, image->mip[0].width, image->mip[0].height); for (level = 0; level < image->mipLevels; ++level) { glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->mip[level].width, image->mip[level].height, image->format, image->type, image->mip[level].data); } break; case GL_TEXTURE_CUBE_MAP: for (level = 0; level < image->mipLevels; ++level) { ptr = (GLubyte *)image->mip[level].data; for (int face = 0; face < 6; face++) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, image->internalFormat, image->mip[level].width, image->mip[level].height, 0, image->format, image->type, ptr + image->sliceStride * face); } } break; case GL_TEXTURE_2D_ARRAY: glTexStorage3D(image->target, image->mipLevels, image->internalFormat, image->mip[0].width, image->mip[0].height, image->slices); for (level = 0; level < image->mipLevels; ++level) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 0, 0, 0, image->mip[level].width, image->mip[level].height, image->slices, image->format, image->type, image->mip[level].data); } break; case GL_TEXTURE_CUBE_MAP_ARRAY: glTexStorage3D(image->target, image->mipLevels, image->internalFormat, image->mip[0].width, image->mip[0].height, image->slices); break; case GL_TEXTURE_3D: glTexStorage3D(image->target, image->mipLevels, image->internalFormat, image->mip[0].width, image->mip[0].height, image->mip[0].depth); for (level = 0; level < image->mipLevels; ++level) { glTexSubImage3D(GL_TEXTURE_3D, level, 0, 0, 0, image->mip[level].width, image->mip[level].height, image->mip[level].depth, image->format, image->type, image->mip[level].data); } break; default: break; } glTexParameteriv(image->target, GL_TEXTURE_SWIZZLE_RGBA, reinterpret_cast<const GLint *>(image->swizzle)); if (image == &local_image) { vglUnloadImage(image); } return texture; }
////////////////////////////////////////////////////////////////////////////// /// \brief Set a texture parameter /// /// Set the given parameter to the given value /// /// \param pname Name of the parameter to set /// \param param Pointer to the value to set the parameter to /// ////////////////////////////////////////////////////////////////////////////// void parameter( GLenum pname, const GLint* param ) { bind(); check_gl_error( glTexParameteriv( Target, pname, param ) ); unbind(); }
void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) { GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; // Texlayout setTexture(0, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } //Tex detail0 setTexture(1, mesh.textures[2], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } //Tex detail1 setTexture(2, mesh.textures[3], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } //Tex detail2 setTexture(3, mesh.textures[4], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } //Tex detail3 setTexture(4, mesh.textures[5], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); if (irr_driver->getLightViz()) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } else { GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } // Diffuse setTexture(5, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); // Specular setTexture(6, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); // SSAO setTexture(7, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } glUseProgram(MeshShader::SplattingShader::Program); MeshShader::SplattingShader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3, 4, 5, 6, 7); glBindVertexArray(mesh.vao_second_pass); glDrawElements(ptype, count, itype, 0); }
void Font::drawString(int x, int y, int fontWidth, int fontHeight, const char *str, DrawAnchor anchor) { #ifndef GL_OES_draw_texture #ifdef DEBUG printf("Unsupport GL_OES_draw_texture extension...\n"); #endif #else glPushMatrix(); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture->textureId); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glColor4f(m_color->red, m_color->green, m_color->blue, m_color->alpha); GLuint len = strlen(str); for (GLuint i = 0; i < len; i++) { int index = (int)(str[i] - 32); #if (defined(DEBUG) && defined(SHOW_FONT_POS)) printf("str[%d]: %c, index: %d\n", i, str[i], index); #endif GLint crop[4] = { 0, 0, m_charWidth, m_charHeight }; int x_idx = index % m_colCount; int y_idx = (int)(index / m_colCount); crop[0] = x_idx * m_charWidth; crop[1] = (m_rowCount - y_idx) * m_charHeight; #if (defined(DEBUG) && defined(SHOW_FONT_POS)) printf("x_idx: %d, y_idx: %d, crop[0]: %d, crop[1]: %d\n", x_idx, y_idx, crop[0], crop[1]); #endif glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); //calc the x, y & draw int scr_width = World::getInstance()->getWidth(); int scr_height = World::getInstance()->getHeight(); switch (anchor) { case(TOP_LEFT): //if draw from top & left, set y with screen height - image draw height glDrawTexiOES(x + i * fontWidth, scr_height - fontHeight - y, 0, fontWidth, fontHeight); break; case(TOP_RIGHT): glDrawTexiOES(scr_width - (len - i) * fontWidth - x, scr_height - fontHeight - y, 0, fontWidth, fontHeight); break; case(BOTTOM_RIGHT): glDrawTexiOES(scr_width - (len - i) * fontWidth - x, y, 0, fontWidth, fontHeight); break; case(BOTTOM_LEFT): default: glDrawTexiOES(x + i * fontWidth, y, 0, fontWidth, fontHeight); break; } // glDrawTexiOES(x + i * fontWidth, y, 0, fontWidth, fontHeight); } glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glPopMatrix(); #endif }
void LayerBlur::onDraw(const Region& clip) const { const DisplayHardware& hw(graphicPlane(0).displayHardware()); const uint32_t fbHeight = hw.getHeight(); int x = mTransformedBounds.left; int y = mTransformedBounds.top; int w = mTransformedBounds.width(); int h = mTransformedBounds.height(); GLint X = x; GLint Y = fbHeight - (y + h); if (X < 0) { w += X; X = 0; } if (Y < 0) { h += Y; Y = 0; } if (w<0 || h<0) { // we're outside of the framebuffer return; } if (mTextureName == -1U) { // create the texture name the first time // can't do that in the ctor, because it runs in another thread. glGenTextures(1, &mTextureName); glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, &mReadFormat); glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, &mReadType); if (mReadFormat != GL_RGB || mReadType != GL_UNSIGNED_SHORT_5_6_5) { mReadFormat = GL_RGBA; mReadType = GL_UNSIGNED_BYTE; mBlurFormat = GGL_PIXEL_FORMAT_RGBX_8888; } } Region::const_iterator it = clip.begin(); Region::const_iterator const end = clip.end(); if (it != end) { #if defined(GL_OES_EGL_image_external) if (GLExtensions::getInstance().haveTextureExternal()) { glDisable(GL_TEXTURE_EXTERNAL_OES); } #endif glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, mTextureName); if (mRefreshCache) { mRefreshCache = false; mAutoRefreshPending = false; int32_t pixelSize = 4; int32_t s = w; if (mReadType == GL_UNSIGNED_SHORT_5_6_5) { // allocate enough memory for 4-bytes (2 pixels) aligned data s = (w + 1) & ~1; pixelSize = 2; } uint16_t* const pixels = (uint16_t*)malloc(s*h*pixelSize); // This reads the frame-buffer, so a h/w GL would have to // finish() its rendering first. we don't want to do that // too often. Read data is 4-bytes aligned. glReadPixels(X, Y, w, h, mReadFormat, mReadType, pixels); // blur that texture. GGLSurface bl; bl.version = sizeof(GGLSurface); bl.width = w; bl.height = h; bl.stride = s; bl.format = mBlurFormat; bl.data = (GGLubyte*)pixels; blurFilter(&bl, 8, 2); if (GLExtensions::getInstance().haveNpot()) { glTexImage2D(GL_TEXTURE_2D, 0, mReadFormat, w, h, 0, mReadFormat, mReadType, pixels); mWidthScale = 1.0f / w; mHeightScale =-1.0f / h; mYOffset = 0; } else { GLuint tw = 1 << (31 - clz(w)); GLuint th = 1 << (31 - clz(h)); if (tw < GLuint(w)) tw <<= 1; if (th < GLuint(h)) th <<= 1; glTexImage2D(GL_TEXTURE_2D, 0, mReadFormat, tw, th, 0, mReadFormat, mReadType, NULL); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, mReadFormat, mReadType, pixels); mWidthScale = 1.0f / tw; mHeightScale =-1.0f / th; mYOffset = th-h; } free((void*)pixels); } const State& s = drawingState(); if (UNLIKELY(s.alpha < 0xFF)) { const GLfloat alpha = s.alpha * (1.0f/255.0f); glColor4f(0, 0, 0, alpha); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } else { glDisable(GL_BLEND); } if (mFlags & DisplayHardware::SLOW_CONFIG) { glDisable(GL_DITHER); } else { glEnable(GL_DITHER); } glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); #ifdef AVOID_DRAW_TEXTURE if(UNLIKELY(transformed())) #endif { glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(mWidthScale, mHeightScale, 1); glTranslatef(-x, mYOffset - y, 0); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(2, GL_FLOAT, 0, mVertices); glTexCoordPointer(2, GL_FLOAT, 0, mVertices); while (it != end) { const Rect& r = *it++; const GLint sy = fbHeight - (r.top + r.height()); glScissor(r.left, sy, r.width(), r.height()); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } glDisableClientState(GL_TEXTURE_COORD_ARRAY); } #ifdef AVOID_DRAW_TEXTURE else{ Rect r; GLint crop[4] = { 0, 0, w, h }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); y = fbHeight - (y + h); while (it != end) { const Rect& r = *it++; const GLint sy = fbHeight - (r.top + r.height()); glScissor(r.left, sy, r.width(), r.height()); glDrawTexiOES(x, y, 0, w, h); } } #endif glLoadIdentity(); glMatrixMode(GL_MODELVIEW); } }
Framebuffer make_eye_framebuffer(int width, int height, int num_views) { Framebuffer result = {}; result.width = width; result.height = height; PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR glFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR)eglGetProcAddress ("glFramebufferTextureMultiviewOVR"); PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVR glFramebufferTextureMultisampleMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVR)eglGetProcAddress ("glFramebufferTextureMultisampleMultiviewOVR"); if (!glFramebufferTextureMultiviewOVR) { LOGE("Did not have glFramebufferTextureMultiviewOVR\n"); exit(EXIT_FAILURE); } if (!glFramebufferTextureMultisampleMultiviewOVR) { LOGE("Did not have glFramebufferTextureMultisampleMultiviewOVR\n"); } bool have_multisampled_ext = glFramebufferTextureMultisampleMultiviewOVR != 0; GL_CHECK(glGenFramebuffers(1, &result.framebuffer)); GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, result.framebuffer)); GL_CHECK(glGenTextures(1, &result.depthbuffer)); GL_CHECK(glBindTexture(GL_TEXTURE_2D_ARRAY, result.depthbuffer)); GL_CHECK(glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT16, width, height, num_views)); if (have_multisampled_ext) { GL_CHECK(glFramebufferTextureMultisampleMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, result.depthbuffer, 0, Multisample_Samples, 0, num_views)); } else { GL_CHECK(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, result.depthbuffer, 0, 0, num_views)); } GL_CHECK(glGenTextures(1, &result.colorbuffer)); GL_CHECK(glBindTexture(GL_TEXTURE_2D_ARRAY, result.colorbuffer)); GL_CHECK(glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, width, height, num_views)); GL_CHECK(glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); GL_CHECK(glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); GL_CHECK(glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_EXT)); GL_CHECK(glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_EXT)); GLint border_color[4] = {0, 0, 0, 0}; GL_CHECK(glTexParameteriv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR_EXT, border_color)); GL_CHECK(glBindTexture(GL_TEXTURE_2D_ARRAY, 0)); if (have_multisampled_ext) { GL_CHECK(glFramebufferTextureMultisampleMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, result.colorbuffer, 0, Multisample_Samples, 0, num_views)); } else { GL_CHECK(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, result.colorbuffer, 0, 0, num_views)); } GLenum status = GL_CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER)); if (status != GL_FRAMEBUFFER_COMPLETE) LOGE("Framebuffer not complete\n"); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0)); return result; }
static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect) { GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; int minx, miny, maxx, maxy; GLfloat minu, maxu, minv, maxv; GLES_ActivateRenderer(renderer); glEnable(GL_TEXTURE_2D); glBindTexture(texturedata->type, texturedata->texture); if (texturedata->scaleMode != data->current.scaleMode) { glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, texturedata->scaleMode); glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, texturedata->scaleMode); data->current.scaleMode = texturedata->scaleMode; } if (texture->modMode) { GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a); } else { GLES_SetColor(data, 255, 255, 255, 255); } GLES_SetBlendMode(data, texture->blendMode); GLES_SetTexCoords(data, SDL_TRUE); if (data->GL_OES_draw_texture_supported && data->useDrawTexture) { /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */ GLint cropRect[4]; int w, h; SDL_Window *window = renderer->window; SDL_GetWindowSize(window, &w, &h); cropRect[0] = srcrect->x; cropRect[1] = srcrect->y + srcrect->h; cropRect[2] = srcrect->w; cropRect[3] = -srcrect->h; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); glDrawTexiOES(dstrect->x, h - dstrect->y - dstrect->h, 0, dstrect->w, dstrect->h); } else { minx = dstrect->x; miny = dstrect->y; maxx = dstrect->x + dstrect->w; maxy = dstrect->y + dstrect->h; minu = (GLfloat) srcrect->x / texture->w; minu *= texturedata->texw; maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; maxu *= texturedata->texw; minv = (GLfloat) srcrect->y / texture->h; minv *= texturedata->texh; maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; maxv *= texturedata->texh; GLshort vertices[8]; GLfloat texCoords[8]; vertices[0] = minx; vertices[1] = miny; vertices[2] = maxx; vertices[3] = miny; vertices[4] = minx; vertices[5] = maxy; vertices[6] = maxx; vertices[7] = maxy; texCoords[0] = minu; texCoords[1] = minv; texCoords[2] = maxu; texCoords[3] = minv; texCoords[4] = minu; texCoords[5] = maxv; texCoords[6] = maxu; texCoords[7] = maxv; glVertexPointer(2, GL_SHORT, 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } glDisable(GL_TEXTURE_2D); return 0; }
inline void __Texture::setTexParameteriv(GLenum pname, const GLint* param) { glTexParameteriv(m_target, pname, param); }
void LoadTextureExample::Initialize(const char * title) { base::Initialize(title); base_prog = glCreateProgram(); static const char quad_shader_vs[] = "#version 330 core\n" "\n" "layout (location = 0) in vec2 in_position;\n" "layout (location = 1) in vec2 in_tex_coord;\n" "\n" "out vec2 tex_coord;\n" "\n" "void main(void)\n" "{\n" " gl_Position = vec4(in_position, 0.5, 1.0);\n" " tex_coord = in_tex_coord;\n" "}\n" ; static const char quad_shader_fs[] = "#version 330 core\n" "\n" "in vec2 tex_coord;\n" "\n" "layout (location = 0) out vec4 color;\n" "\n" "uniform sampler2D tex;\n" "\n" "void main(void)\n" "{\n" " color = texture(tex, tex_coord);\n" "}\n" ; vglAttachShaderSource(base_prog, GL_VERTEX_SHADER, quad_shader_vs); vglAttachShaderSource(base_prog, GL_FRAGMENT_SHADER, quad_shader_fs); glGenBuffers(1, &quad_vbo); glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); static const GLfloat quad_data[] = { -0.75f, -0.75f, 0.75f, -0.75f, 0.75f, 0.75f, -0.75f, 0.75f, 0.0f, 0.0f, 4.0f, 0.0f, 4.0f, 4.0f, 0.0f, 4.0f }; glBufferData(GL_ARRAY_BUFFER, sizeof(quad_data), quad_data, GL_STATIC_DRAW); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(8 * sizeof(float))); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glLinkProgram(base_prog); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexStorage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 8, 8); static const unsigned char texture_data[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF }; glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RED, GL_UNSIGNED_BYTE, texture_data); static const GLint swizzles[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzles); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glGenerateMipmap(GL_TEXTURE_2D); }
void Texture :: setSwizzle ( GLenum red, GLenum green, GLenum blue, GLenum alpha ) { int swizzle [4] = { red, green, blue, alpha }; glTexParameteriv ( target, GL_TEXTURE_SWIZZLE_RGBA, swizzle ); }