void Application::prepare_framebuffer() { glGenFramebuffers(1, &render_fbo); glBindFramebuffer(GL_FRAMEBUFFER, render_fbo); glGenTextures(3, fbo_textures); glBindTexture(GL_TEXTURE_2D, fbo_textures[0]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB16F, 2048, 2048); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, fbo_textures[1]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, 2048, 2048); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, fbo_textures[2]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT32F, 2048, 2048); 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); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, fbo_textures[0], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, fbo_textures[1], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, fbo_textures[2], 0); static const GLenum draw_buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; glDrawBuffers(2, draw_buffers); glBindFramebuffer(GL_FRAMEBUFFER, 0); glGenVertexArrays(1, &quad_vao); glBindVertexArray(quad_vao); }
void OnStart() { mTriangle = new WaterBear::Renderables::TriangleRO("../assets/ktx/pattern1.ktx"); mCube = new WaterBear::Renderables::CubeRO("../assets/ktx/baboon.ktx"); glGenFramebuffers(1, &mFbo); glBindFramebuffer(GL_FRAMEBUFFER, mFbo); glGenTextures(1, &mFboColorTexture); glBindTexture(GL_TEXTURE_2D, mFboColorTexture); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 512, 512); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glGenTextures(1, &mFboDepthTexture); glBindTexture(GL_TEXTURE_2D, mFboDepthTexture); glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT32F, 512, 512); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mFboColorTexture, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, mFboDepthTexture, 0); static const GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, drawBuffers); // rendering settings glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); }
void MainDeferredRenderer::setupGBuffer() { printf("Setting up G-Buffer!.\n"); glGenFramebuffers(1, &gbuffer); glBindFramebuffer(GL_FRAMEBUFFER, gbuffer); glGenTextures(3, gbuffer_tex); glBindTexture(GL_TEXTURE_2D, gbuffer_tex[0]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32UI, MAX_DISPLAY_WIDTH, MAX_DISPLAY_HEIGHT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, gbuffer_tex[1]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, MAX_DISPLAY_WIDTH, MAX_DISPLAY_HEIGHT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, gbuffer_tex[2]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT32F, MAX_DISPLAY_WIDTH, MAX_DISPLAY_HEIGHT); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, gbuffer_tex[0], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, gbuffer_tex[1], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gbuffer_tex[2], 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); }
void ComputeBasicGLSL::initRendering(void) { NV_APP_BASE_SHARED_INIT(); NvAssetLoaderAddSearchPath("es3aep-kepler/ComputeBasicGLSL"); if (!requireMinAPIVersion(NvGLAPIVersionES3_1())) return; { NvScopedShaderPrefix switched( (getGLContext()->getConfiguration().apiVer.api == NvGLAPI::GL) ? "#version 430\n" : "#version 310 es\n"); //init shaders m_blitProg = NvGLSLProgram::createFromFiles("shaders/plain.vert", "shaders/plain.frag"); m_computeProg = new NvGLSLProgram; int32_t len; NvGLSLProgram::ShaderSourceItem sources[1]; sources[0].type = GL_COMPUTE_SHADER; sources[0].src = NvAssetLoaderRead("shaders/invert.glsl", len); m_computeProg->setSourceFromStrings(sources, 1); NvAssetLoaderFree((char*)sources[0].src); } //load input texture - this is a normal, "mutable" texture m_sourceImage = NvImage::CreateFromDDSFile("textures/flower1024.dds"); GLint w = m_sourceImage->getWidth(); GLint h = m_sourceImage->getHeight(); GLint intFormat = m_sourceImage->getInternalFormat(); GLint format = m_sourceImage->getFormat(); GLint type = m_sourceImage->getType(); // Image must be immutable in order to be used with glBindImageTexture // So we copy the mutable texture to an immutable texture glGenTextures(1, &m_sourceTexture ); glBindTexture(GL_TEXTURE_2D, m_sourceTexture); glTexStorage2D(GL_TEXTURE_2D, 1, intFormat, w, h ); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, type, m_sourceImage->getLevel(0)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); //create output texture with same size and format as input // Image must be immutable in order to be used with glBindImageTexture glGenTextures(1, &m_resultTexture ); glBindTexture(GL_TEXTURE_2D, m_resultTexture); glTexStorage2D(GL_TEXTURE_2D, 1, intFormat, w, h ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); CHECK_GL_ERROR(); glBindTexture(GL_TEXTURE_2D, 0); }
void shadowmapping_app::startup() { load_shaders(); int i; static const char * const object_names[] = { "media/objects/dragon.sbm", "media/objects/sphere.sbm", "media/objects/cube.sbm", "media/objects/cube.sbm", "media/objects/cube.sbm", }; static const vmath::vec4 object_colors[] = { vmath::vec4(1.0f, 0.7f, 0.8f, 1.0f), vmath::vec4(0.7f, 0.8f, 1.0f, 1.0f), vmath::vec4(0.3f, 0.9f, 0.4f, 1.0f), vmath::vec4(0.6f, 0.4f, 0.9f, 1.0f), vmath::vec4(0.8f, 0.2f, 0.1f, 1.0f), }; for (i = 0; i < OBJECT_COUNT; i++) { objects[i].obj.load(object_names[i]); objects[i].diffuse_albedo = object_colors[i]; } glGenFramebuffers(1, &depth_fbo); glBindFramebuffer(GL_FRAMEBUFFER, depth_fbo); glGenTextures(1, &depth_tex); glBindTexture(GL_TEXTURE_2D, depth_tex); glTexStorage2D(GL_TEXTURE_2D, 11, GL_DEPTH_COMPONENT32F, FBO_SIZE, FBO_SIZE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glGenTextures(1, &color_tex); glBindTexture(GL_TEXTURE_2D, color_tex); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, FBO_SIZE, FBO_SIZE); glGenTextures(1, &temp_tex); glBindTexture(GL_TEXTURE_2D, temp_tex); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, FBO_SIZE, FBO_SIZE); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depth_tex, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, color_tex, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); glEnable(GL_DEPTH_TEST); glGenVertexArrays(1, &quad_vao); glBindVertexArray(quad_vao); }
bool initTexture() { bool Validated(true); gli::gl GL; gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); assert(!Texture.empty()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(texture::MAX, &TextureName[0]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); GLint Swizzle[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, Swizzle); gli::gl::format const Format = GL.translate(Texture.format()); for (gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexImage2D(GL_TEXTURE_2D, static_cast<GLint>(Level), Format.Internal, static_cast<GLsizei>(Texture[Level].dimensions().x), static_cast<GLsizei>(Texture[Level].dimensions().y), 0, Format.External, Format.Type, Texture[Level].data()); } glm::ivec2 WindowSize(this->getWindowSize() * this->FramebufferScale); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, static_cast<GLsizei>(WindowSize.x), static_cast<GLsizei>(WindowSize.y)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RENDERBUFFER]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT24, static_cast<GLsizei>(WindowSize.x), static_cast<GLsizei>(WindowSize.y)); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return Validated; }
void Renderer::uploadTerrainData() { //height map { if (glIsTexture(mTextures.heightMap)) glDeleteTextures(1, &mTextures.heightMap); glGenTextures(1, &mTextures.heightMap); glBindTexture(GL_TEXTURE_2D, mTextures.heightMap); const HeightMap &hm = mTerrainData->heightMap(); glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, hm.size(), hm.size()); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, hm.size(), hm.size(), GL_RED, GL_FLOAT, hm.raw()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } //light map { if (glIsTexture(mTextures.lightMap)) glDeleteTextures(1, &mTextures.lightMap); glGenTextures(1, &mTextures.lightMap); glBindTexture(GL_TEXTURE_2D, mTextures.lightMap); const LightMap &lm = mTerrainData->lightMap(); glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, lm.size(), lm.size()); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, lm.size(), lm.size(), GL_RED, GL_UNSIGNED_SHORT, lm.raw()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } //texture indicies { if (glIsTexture(mTextures.indicies)) glDeleteTextures(1, &mTextures.indicies); glGenTextures(1, &mTextures.indicies); glBindTexture(GL_TEXTURE_BUFFER, mTextures.indicies); { GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_TEXTURE_BUFFER, buffer); { glBufferData(GL_TEXTURE_BUFFER, sizeof(GLubyte)*mTerrainData->textureIndicies().size(), &mTerrainData->textureIndicies()[0], GL_STATIC_DRAW); glTexBuffer(GL_TEXTURE_BUFFER, GL_R8UI, buffer); } } } }
void NormalBlendedDecal::reshape(int32_t width, int32_t height) { glViewport(0, 0, (GLint) width, (GLint) height); destroyBuffers(); // Build buffers if ((width > 0) && (height > 0)) { glGenFramebuffers(1, &mGbufferFBO); glBindFramebuffer(GL_FRAMEBUFFER, mGbufferFBO); glGenTextures(NUM_GBUFFER_TEXTURES, mGbufferTextures); // uColorTex glBindTexture(GL_TEXTURE_2D, mGbufferTextures[COLOR_TEXTURE]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA16F, m_width, m_height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // uNormalTex glBindTexture(GL_TEXTURE_2D, mGbufferTextures[NORMAL_TEXTURE]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA16F, m_width, m_height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // uWorldPosTex glBindTexture(GL_TEXTURE_2D, mGbufferTextures[WORLDPOS_TEXTURE]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_width, m_height, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Depth texture glBindTexture(GL_TEXTURE_2D, mGbufferTextures[DEPTH_TEXTURE]); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_width, m_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mGbufferTextures[COLOR_TEXTURE], 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, mGbufferTextures[NORMAL_TEXTURE], 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, mGbufferTextures[WORLDPOS_TEXTURE], 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, mGbufferTextures[DEPTH_TEXTURE], 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Set GbufferDecalFBO glGenFramebuffers(1, &mGbufferDecalFBO); glBindFramebuffer(GL_FRAMEBUFFER, mGbufferDecalFBO); // Only color output glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mGbufferTextures[COLOR_TEXTURE], 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, mGbufferTextures[DEPTH_TEXTURE], 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); } }
bool initTexture() { bool Validated(true); gli::gl GL; gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); assert(!Texture.empty()); gli::gl::format const Format = GL.translate(Texture.format()); gli::gl::swizzles const Swizzles = GL.translate(Texture.swizzles()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(texture::MAX, &TextureName[0]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, Swizzles[0]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, Swizzles[1]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, Swizzles[2]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, Swizzles[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexStorage2D(GL_TEXTURE_2D, static_cast<GLint>(Texture.levels()), Format.Internal, static_cast<GLsizei>(Texture.extent().x), static_cast<GLsizei>(Texture.extent().y)); for(std::size_t Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage2D(GL_TEXTURE_2D, GLint(Level), 0, 0, static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), Format.External, Format.Type, Texture[Level].data()); } glm::ivec2 WindowSize(this->getWindowSize()); glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexStorage2D(GL_TEXTURE_2D, static_cast<GLint>(1), GL_RGBA8, static_cast<GLsizei>(WindowSize.x * this->Supersampling), static_cast<GLsizei>(WindowSize.y * this->Supersampling)); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return Validated; }
bool initTexture() { bool Validated(true); gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); assert(!Texture.empty()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(texture::MAX, &TextureName[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y)); for(std::size_t Level = 0; Level < Texture.levels(); ++Level) { glCompressedTexSubImage2D( GL_TEXTURE_2D, GLint(Level), 0, 0, GLsizei(Texture[Level].dimensions().x), GLsizei(Texture[Level].dimensions().y), GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GLsizei(Texture[Level].size()), Texture[Level].data()); } glm::vec2 WindowSize(this->getWindowSize()); glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glTexStorage2D(GL_TEXTURE_2D, GLint(1), GL_RGBA8, GLsizei(WindowSize.x), GLsizei(WindowSize.y)); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RENDERBUFFER]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glTexStorage2D(GL_TEXTURE_2D, GLint(1), GL_DEPTH_COMPONENT24, GLsizei(WindowSize.x), GLsizei(WindowSize.y)); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return Validated; }
void TopazSample::initFramebuffers(int32_t width, int32_t height) { if (textures.sceneColor && GLEW_ARB_bindless_texture) { glMakeTextureHandleNonResidentARB(texturesAddress64.sceneColor); glMakeTextureHandleNonResidentARB(texturesAddress64.sceneDepth); } if (textures.sceneColor) { glDeleteTextures(1, &textures.sceneColor); } glGenTextures(1, &textures.sceneColor); glBindTexture(GL_TEXTURE_RECTANGLE, textures.sceneColor); glTexStorage2D(GL_TEXTURE_RECTANGLE, 1, GL_RGBA16F, width, height); glBindTexture(GL_TEXTURE_RECTANGLE, 0); if (textures.sceneDepth) { glDeleteTextures(1, &textures.sceneDepth); } glGenTextures(1, &textures.sceneDepth); glBindTexture(GL_TEXTURE_RECTANGLE, textures.sceneDepth); glTexStorage2D(GL_TEXTURE_RECTANGLE, 1, GL_DEPTH_COMPONENT24, width, height); glBindTexture(GL_TEXTURE_RECTANGLE, 0); if (fbos.scene) { glDeleteFramebuffers(1, &fbos.scene); } glGenFramebuffers(1, &fbos.scene); glBindFramebuffer(GL_FRAMEBUFFER, fbos.scene); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, textures.sceneColor, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_RECTANGLE, textures.sceneDepth, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); if (GLEW_ARB_bindless_texture) { texturesAddress64.sceneColor = glGetTextureHandleARB(textures.sceneColor); texturesAddress64.sceneDepth = glGetTextureHandleARB(textures.sceneDepth); glMakeTextureHandleResidentARB(texturesAddress64.sceneColor); glMakeTextureHandleResidentARB(texturesAddress64.sceneDepth); } cmdlist.state.fboIncarnation++; }
//////////////////////////////////////////////////////////////////////////////// // SoftShadowsRenderer::createShadowMap() //////////////////////////////////////////////////////////////////////////////// bool SoftShadowsRenderer::createShadowMap() { GLuint prevFBO = 0; // Enum has MANY names based on extension/version // but they all map to 0x8CA6 glGetIntegerv(0x8CA6, (GLint*)&prevFBO); // Setup the shadowmap depth sampler glSamplerParameteri(m_samplers[ShadowDepthTextureUnit], GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(m_samplers[ShadowDepthTextureUnit], GL_TEXTURE_MIN_FILTER, GL_NEAREST); glSamplerParameteri(m_samplers[ShadowDepthTextureUnit], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_samplers[ShadowDepthTextureUnit], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // glSamplerParameterfv(m_samplers[ShadowDepthTextureUnit], GL_TEXTURE_BORDER_COLOR, borderColor); CHECK_GL_ERROR(); // Setup the shadowmap PCF sampler glSamplerParameteri(m_samplers[ShadowPcfTextureUnit], GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(m_samplers[ShadowPcfTextureUnit], GL_TEXTURE_MIN_FILTER, GL_NEAREST); glSamplerParameteri(m_samplers[ShadowPcfTextureUnit], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_samplers[ShadowPcfTextureUnit], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // glSamplerParameterfv(m_samplers[ShadowPcfTextureUnit], GL_TEXTURE_BORDER_COLOR, borderColor); glSamplerParameteri(m_samplers[ShadowPcfTextureUnit], GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glSamplerParameteri(m_samplers[ShadowPcfTextureUnit], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); CHECK_GL_ERROR(); // Generate the framebuffer glGenFramebuffers(1, &m_shadowMapFramebuffer); CHECK_GL_ERROR(); if (m_shadowMapFramebuffer == 0) return false; glBindFramebuffer(GL_FRAMEBUFFER, m_shadowMapFramebuffer); // Generate the shadowmap texture glActiveTexture(GL_TEXTURE0 + ShadowDepthTextureUnit); glGenTextures(1, &m_textures[ShadowDepthTextureUnit]); if (&m_textures[ShadowDepthTextureUnit] == 0) return false; m_textures[ShadowPcfTextureUnit] = m_textures[ShadowDepthTextureUnit]; glBindTexture(GL_TEXTURE_2D, m_textures[ShadowDepthTextureUnit]); glTexStorage2D( GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT32F, LIGHT_RES, LIGHT_RES); CHECK_GL_ERROR(); // Add the shadowmap texture to the framebuffer glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_textures[ShadowDepthTextureUnit], 0); CHECK_GL_ERROR(); GLuint buffer = GL_NONE; glDrawBuffers(1, &buffer); CHECK_GL_ERROR(); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; glBindFramebuffer(GL_FRAMEBUFFER, prevFBO); return true; }
bool initTexture() { gli::texture2D Texture(gli::loadStorageDDS(glf::DATA_DIRECTORY + TEXTURE_DIFFUSE)); assert(!Texture.empty()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &TextureName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), GL_RGBA8, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y)); for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage2D( GL_TEXTURE_2D, GLint(Level), 0, 0, GLsizei(Texture[Level].dimensions().x), GLsizei(Texture[Level].dimensions().y), GL_BGR, GL_UNSIGNED_BYTE, Texture[Level].data()); } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return true; }
/* This function should only be used without mipmaps and when data == NULL */ void gl_load_texture_image(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data) { #ifndef HAVE_PSGL #ifdef HAVE_OPENGLES2 if (gl_check_capability(GL_CAPS_TEX_STORAGE_EXT) && internalFormat != GL_BGRA_EXT) { gl_size_format(&internalFormat); glTexStorage2DEXT(target, 1, internalFormat, width, height); } #else if (gl_check_capability(GL_CAPS_TEX_STORAGE) && internalFormat != GL_BGRA_EXT) { gl_size_format(&internalFormat); glTexStorage2D(target, 1, internalFormat, width, height); } #endif else #endif { #ifdef HAVE_OPENGLES if (gl_check_capability(GL_CAPS_GLES3_SUPPORTED)) #endif gl_size_format(&internalFormat); glTexImage2D(target, level, internalFormat, width, height, border, format, type, data); } }
bool initTexture() { gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); assert(!Texture.empty()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(texture::MAX, &TextureName[0]); glActiveTexture(GL_TEXTURE0); for(std::size_t i = 0; i < texture::MAX; ++i) { glBindTexture(GL_TEXTURE_2D, TextureName[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TextureFormat[i] == GL_RGB_INTEGER ? GL_NEAREST_MIPMAP_NEAREST : GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TextureFormat[i] == GL_RGB_INTEGER ? GL_NEAREST : GL_LINEAR); glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), TextureInternalFormat[i], GLsizei(Texture[0].extent().x), GLsizei(Texture[0].extent().y)); for(std::size_t Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage2D(GL_TEXTURE_2D, GLint(Level), 0, 0, GLsizei(Texture[Level].extent().x), GLsizei(Texture[Level].extent().y), TextureFormat[i], GL_UNSIGNED_BYTE, Texture[Level].data()); } } glBindTexture(GL_TEXTURE_2D, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return true; }
uint32 gfxCreateTexture2D(const char* filename, uint16* w, uint16* h, uint8 texFormat, uint8 numMips) { ASSERT(texFormat < TEX_D16F); int x,y,n; uint8 levels = numMips + 1; TextureFormatsGL format = s_textureFormats[texFormat]; uint8 numComponents = s_requestedComponents[texFormat]; unsigned char *data = stbi_load(filename, &x, &y, &n, numComponents); ASSERT(data != NULL); if (w && h) { *w = x; *h = y; } glBindTexture(GL_TEXTURE_2D, gctx.tex[gctx.texCnt]); // Allocates storage for #levels mips glTexStorage2D(GL_TEXTURE_2D, levels, format.sizedInternalFormat, x, y); if (texFormat < TEX_D16F) { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, x, y, format.baseInternalFormat, GL_UNSIGNED_BYTE, data); } if (numMips > 0) { glGenerateMipmap(GL_TEXTURE_2D); } glBindTexture(GL_TEXTURE_2D, 0); stbi_image_free(data); return gctx.tex[gctx.texCnt++]; }
bool initTexture() { gli::gl GL; gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); assert(!Texture.empty()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &TextureName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), GL.internal_format(Texture.format()), GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y)); for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage2D(GL_TEXTURE_2D, GLint(Level), 0, 0, GLsizei(Texture[Level].dimensions().x), GLsizei(Texture[Level].dimensions().y), GL.external_format(Texture.format()), GL.type_format(Texture.format()), Texture[Level].data()); } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return true; }
bool ShadowMap::initWithMapSize(const Size &shadowMapSize) { int _default_framebufferId; int _default_texture_textureId; glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_default_framebufferId); glGetIntegerv(GL_TEXTURE_BINDING_2D, &_default_texture_textureId); //Size _size = GLContext::getInstance()->getWinSize(); glGenFramebuffers(1, &_framebufferId); glBindFramebuffer(GL_FRAMEBUFFER, _framebufferId); glGenTextures(1, &_depthTextureId); glBindTexture(GL_TEXTURE_2D, _depthTextureId); // glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, _size.width, _size.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glTexStorage2D(GL_TEXTURE_2D,1,GL_DEPTH_COMPONENT32F, shadowMapSize.width, shadowMapSize.height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _depthTextureId, 0); //禁止写入颜色 glDrawBuffer(GL_NONE); assert(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); //检查真缓冲区对象的完整性 glBindTexture(GL_TEXTURE_2D, _default_texture_textureId); glBindFramebuffer(GL_FRAMEBUFFER, _default_framebufferId); _shadowMapSize = shadowMapSize; return true; }
// -------------------------------------------------------------------------------------------------------------------- GLuint NewTex2DFromDetails(const TextureDetails& _texDetails) { GLuint retVal = 0; GLuint texs[2] = { 0 }; glGenTextures(1, &retVal); if (retVal == 0) { return retVal; } glBindTexture(GL_TEXTURE_2D, retVal); glTexStorage2D(GL_TEXTURE_2D, _texDetails.szMipMapCount, _texDetails.glFormat, _texDetails.dwWidth, _texDetails.dwHeight); size_t offset = 0; for (int mip = 0; mip < _texDetails.szMipMapCount; ++mip) { glCompressedTexSubImage2D(GL_TEXTURE_2D, mip, 0, 0, _texDetails.MipMapWidth(mip), _texDetails.MipMapHeight(mip), _texDetails.glFormat, _texDetails.pSizes[mip], (char*)_texDetails.pPixels + offset); offset += _texDetails.pSizes[mip]; } assert(GLRenderer::GetApiError() == GL_NO_ERROR); return retVal; }
bool Texture2D::createStorage(Size2i size, unsigned int channels, bool compressed, int levels) { if (created) { return false; } // levels = -1 means max mipmap level according to texture dimensions const int maxLevels = ilogb(size.max()) + 1; if (levels == 0) levels = 1; if (levels < 0 || levels > maxLevels) levels = maxLevels; this->channels = std::min(std::max(1u, channels), 4u); this->size = size; this->levels = levels; if (glTexStorage2D) { // try to allocate immutable storage (ogl 4.3) glTexStorage2D(target, levels, glInternalFormat(compressed), size.width(), size.height()); } else { // ensure texture completeness despite mutable storage for (int i=0; i<levels; ++i) { glTexImage2D(target, i, glInternalFormat(compressed), size.width(), size.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, nullptr); size = Size2i(std::max(1, size.width()>>1), std::max(1, size.height()>>1)); } glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1); } return created = true; }
void Texture2d::allocate_mipmap_storage(int mipmap_levels, InternalPixelFormat format) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmap_levels); CHECK_GL_ERROR(glTexParameteri); #if GL_TARGET_VERSION >= 402 //Use immutable storage if available glTexStorage2D(GL_TEXTURE_2D, mipmapLevels, static_cast<GLenum>(format), m_width, m_height); CHECK_GL_ERROR(glTexStorage2D); #else auto level_width = m_width; auto level_height = m_height; for(auto i = 0; i < mipmap_levels; ++i) { glTexImage2D(GL_TEXTURE_2D, i, static_cast<GLenum>(format), level_width, level_height, 0, GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE, nullptr); CHECK_GL_ERROR(glTexImage2D); if(level_width == 1 && level_height == 1) { break; } level_width = std::max(1, level_width / 2); level_height = std::max(1, level_height / 2); } #endif }
bool Texture::initWithData(int32_t format, const uint8_t * buffer, uint32_t width, uint32_t height, bool mipmaps, int pixelFormat) { destroy(); m_target = GL_TEXTURE_2D; m_format = format; m_pixelFormat = pixelFormat < 0 ? findPixelFormat(format) : pixelFormat; m_width = width; m_height = height; glGenTextures(1, &m_texture); glBindTexture(m_target, m_texture); int mipLevels = mipmaps ? getMipLevelsCount(m_width, m_height) : 1; glTexStorage2D(m_target, mipLevels, m_format, m_width, m_height); glTexSubImage2D(m_target, 0, 0, 0, m_width, m_height, m_pixelFormat, GL_UNSIGNED_BYTE, buffer); setSampling(); if (mipmaps) generateMipmaps(); glBindTexture(m_target, 0); if (glCheckError()) { destroy(); return false; } m_isLoaded = true; return m_isLoaded; }
void App::CreateQuadBuffer() { glGenFramebuffers(1, &quadBuffer.FBO); glBindFramebuffer(GL_FRAMEBUFFER, quadBuffer.FBO); glGenTextures(1, &quadBuffer.textureID); glBindTexture(GL_TEXTURE_2D, quadBuffer.textureID); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1280, 720); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, quadBuffer.textureID, 0); glGenRenderbuffers(1, &quadBuffer.depth); glBindRenderbuffer(GL_RENDERBUFFER, quadBuffer.depth); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 1280, 720); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, quadBuffer.depth); GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, drawBuffers); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { printf("FrameBuffer Error!\n"); } glBindFramebuffer(GL_FRAMEBUFFER, 0); }
TextureCube::TextureCube(ezUInt32 size, GLuint format, ezInt32 numMipLevels) : Texture(size, size, 1, format, numMipLevels) { Bind(0); glTexStorage2D(GL_TEXTURE_CUBE_MAP, m_numMipLevels, format, size, size); gl::Utils::CheckError("glTexStorage2D"); }
/* * * Core in: * OpenGLES : 3.0 */ void rglTexStorage2D(GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height) { #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3) glTexStorage2D(target, levels, internalFormat, width, height); #endif }
void setUpShadowTexture(void) { glGenFramebuffers(1, &g_shadow_depthTexture_FrameBufferObjectID); glBindFramebuffer(GL_FRAMEBUFFER, g_shadow_depthTexture_FrameBufferObjectID); glGenTextures(1, &g_shadow_depthTexture_ID); glBindTexture(GL_TEXTURE_2D, g_shadow_depthTexture_ID); glTexStorage2D(GL_TEXTURE_2D, 11, GL_DEPTH_COMPONENT32F, SHADOW_DEPTH_TEXTURE_SIZE, SHADOW_DEPTH_TEXTURE_SIZE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, g_shadow_depthTexture_ID, 0); glDrawBuffer(GL_NONE); // No color buffer is drawn to. // Always check that our framebuffer is ok if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { return; } ExitOnGLError("There was a problem setting up the shadow texture."); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); return; }
pn::Image pn::RenderFactory::makeFromPNG(const char* filename) { PixelContainer pixels; Dimension width, height; PixelContainer buffer; lodepng::load_file(buffer, filename); lodepng::State state; auto error = lodepng::decode(pixels, width, height, state, buffer); if (error) { std::cout << "LodePNG: Could not load file '" << filename << "' : " << lodepng_error_text(error) << std::endl; } Image image; glGenTextures(1, &image.m_tbo); glBindTexture(GL_TEXTURE_2D, image.m_tbo); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width, height); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); glBindTexture(GL_TEXTURE_2D, 0); glGenSamplers(1, &image.m_sampler); glSamplerParameteri(image.m_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(image.m_sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(image.m_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); return image; }
bool initTexture() { gli::gl GL; gli::texture2D Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); assert(!Texture.empty()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &TextureName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName); glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), GL_RGBA8, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y)); for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage2D(GL_TEXTURE_2D, GLint(Level), 0, 0, GLsizei(Texture[Level].dimensions().x), GLsizei(Texture[Level].dimensions().y), GL.external_format(Texture.format()), GL.type_format(Texture.format()), Texture[Level].data()); } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return true; }
Material::Material(ColorMaterial c) : texture(0) , sampler(0) { // Load Texture // Texture is Targa TGAFILE tgaColor; // Change Abs Path to WorkingDir Path std::string s(c.colorFileName); s = s.substr(s.find_last_of('/') + 1); s = "Textures/" + s; bool result = LoadTGAFile(&tgaColor, s.c_str()); assert(result == true); // Has to be RGB uncompressed assert(tgaColor.imageTypeCode == 2); // To the GL glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexStorage2D(GL_TEXTURE_2D, 4, (tgaColor.bitCount == 24) ? GL_RGB8 : GL_RGBA8, tgaColor.imageWidth, tgaColor.imageHeight); // Do the Actual Loading glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tgaColor.imageWidth, tgaColor.imageHeight, (tgaColor.bitCount == 24) ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, tgaColor.imageData); glGenerateMipmap(GL_TEXTURE_2D); // Tex Parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 8); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); // TODO: too many samplers since all texture sampled as same // this can be reduced glGenSamplers(1, &sampler); glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8.0f); free(tgaColor.imageData); // Load Normal Map }
bool initTexture() { gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); assert(!Texture.empty()); gli::gl GL(gli::gl::PROFILE_GL33); gli::gl::format const& Format = GL.translate(Texture.format(), Texture.swizzles()); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &TextureName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, Format.Swizzles[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, Format.Swizzles[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, Format.Swizzles[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, Format.Swizzles[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), Format.Internal, GLsizei(Texture.extent().x), GLsizei(Texture.extent().y)); for(gli::texture2d::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage2D(GL_TEXTURE_2D, GLint(Level), 0, 0, GLsizei(Texture[Level].extent().x), GLsizei(Texture[Level].extent().y), Format.External, Format.Type, Texture[Level].data()); } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return true; }