bool initTexture() { gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); if(Texture.empty()) return false; gli::gl GL(gli::gl::PROFILE_GL33); gli::gl::format const Format = GL.translate(Texture.format(), Texture.swizzles()); glGenTextures(1, &TextureName); glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, Format.Swizzles[0]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, Format.Swizzles[1]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, Format.Swizzles[2]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, Format.Swizzles[3]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexStorage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Texture.levels()), Format.Internal, static_cast<GLsizei>(Texture[0].extent().x), static_cast<GLsizei>(Texture[0].extent().y), static_cast<GLsizei>(1)); for(std::size_t Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Level), 0, 0, 0, static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), GLsizei(1), Format.External, Format.Type, Texture[Level].data()); } return true; }
bool initTexture() { glm::uvec2 WindowSize(this->getWindowSize()); glGenTextures(texture::MAX, &TextureName[0]); { glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName[texture::DIFFUSE]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); std::vector<glm::u8vec4> Colors; Colors.resize(2048); for(std::size_t ColorIndex = 0; ColorIndex < Colors.size(); ++ColorIndex) Colors[ColorIndex] = glm::u8vec4(glm::vec4(glm::linearRand(glm::vec3(0), glm::vec3(1)) * 255.f, 1.0f)); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 1, 1, static_cast<GLsizei>(Colors.size())); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 1, 1, static_cast<GLsizei>(Colors.size()), GL_RGBA, GL_UNSIGNED_BYTE, &Colors[0][0]); } { glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName[texture::INDIRECTION]); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); std::vector<glm::u32vec1> Data; Data.resize(WindowSize.x * WindowSize.y); for(std::size_t Index = 0; Index < Data.size(); ++Index) //Data[Index] = glm::u32vec1(glm::linearRand(glm::vec1(0), glm::vec1(1)) * 255.0f); Data[Index] = glm::u32vec1(glm::linearRand(glm::vec1(0), glm::vec1(1)) * glm::vec1(Data.size() - 1)); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_R32UI, WindowSize.x, WindowSize.y, 1); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, WindowSize.x, WindowSize.y, 1, GL_RED_INTEGER, GL_UNSIGNED_INT, &Data[0][0]); } return true; }
GLuint CreateArrayTexture2D (U32 width, U32 height, std::vector<std::string>& filenames) { GLuint textureID = 0; GLuint mipLevelCount = 1; glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D_ARRAY, textureID); // Allocate the storage. glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevelCount, GL_RGBA8, width, height, filenames.size()); // Upload pixel data. // The first 0 refers to the mipmap level (level 0, since there's only 1) // The following 2 zeroes refers to the x and y offsets in case you only want to specify a subrectangle. // The final 0 refers to the layer index offset (we start from index 0 and have 2 levels). // Altogether you can specify a 3D box subset of the overall texture, but only one mip level at a time. for (U32 i = 0; i < filenames.size(); i++) { int w, h; auto pixels = stbi_load(filenames[i].c_str(), &w, &h, nullptr, 4); assert(w == height); assert(h == height); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); stbi_image_free(pixels); } glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); return textureID; }
unsigned int grLoadTextureArray(void) { unsigned int textureHandle; glGenTextures(1, &textureHandle); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, textureHandle); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 10, // mipmap level GL_RGBA8, //Internal format 4096, 4096, //width,height 5); //Number of layers grLoadTexture("img/atlas.png", 0); grLoadTexture("img/explosion1.png", 1); grLoadTexture("img/explosion2.png", 2); grLoadTexture("img/explosion3.png", 3); grLoadTexture("img/explosion4.png", 4); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); return textureHandle; }
bool initTexture() { gli::textureCube Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::textureCube::texelcoord_type(2), 1); assert(!Texture.empty()); gli::gl GL; gli::gl::format const Format = GL.translate(Texture.format()); Texture[0].clear<glm::u8vec4>(glm::u8vec4(255, 0, 0, 255)); Texture[1].clear<glm::u8vec4>(glm::u8vec4(255, 128, 0, 255)); Texture[2].clear<glm::u8vec4>(glm::u8vec4(255, 255, 0, 255)); Texture[3].clear<glm::u8vec4>(glm::u8vec4( 0, 255, 0, 255)); Texture[4].clear<glm::u8vec4>(glm::u8vec4( 0, 255, 255, 255)); Texture[5].clear<glm::u8vec4>(glm::u8vec4( 0, 0, 255, 255)); glGenTextures(1, &TextureName); glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, TextureName); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, GLint(Texture.levels()), Format.Internal, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y), GLsizei(Texture.faces())); glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, 0, 0, 0, static_cast<GLsizei>(Texture.dimensions().x), static_cast<GLsizei>(Texture.dimensions().y), static_cast<GLsizei>(Texture.faces()), Format.External, Format.Type, Texture.data()); return true; }
void GenerateArrayTexture() { //Generate an array texture glGenTextures( 1, &gArrayTexture ); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, gArrayTexture); //Create storage for the texture. (100 layers of 1x1 texels) glTexStorage3D( GL_TEXTURE_2D_ARRAY, 1, //No mipmaps as textures are 1x1 GL_RGB8, //Internal format 1, 1, //width,height 100 //Number of layers ); for( unsigned int i(0); i!=100;++i) { //Choose a random color for the i-essim image GLubyte color[3] = {rand()%255,rand()%255,rand()%255}; //Specify i-essim image glTexSubImage3D( GL_TEXTURE_2D_ARRAY, 0, //Mipmap number 0,0,i, //xoffset, yoffset, zoffset 1,1,1, //width, height, depth GL_RGB, //format GL_UNSIGNED_BYTE, //type color); //pointer to data } glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); }
bool ShadowMap::initWithMapLayer(const Size &mapSize, const int numberOfLayer) { int defaultFramebufferId; int defaultTextureId; glGetIntegerv(GL_FRAMEBUFFER_BINDING,&defaultFramebufferId); glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY,&defaultTextureId); //创建帧缓冲区对象 glGenFramebuffers(1, &_framebufferId); glBindFramebuffer(GL_FRAMEBUFFER,_framebufferId); //创建深度纹理对象 glGenTextures(1, &_depthTextureId); glBindTexture(GL_TEXTURE_2D_ARRAY,_depthTextureId); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT32F, mapSize.width, mapSize.height, numberOfLayer); glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _depthTextureId, 0); //禁止颜色写入 glDrawBuffer(GL_NONE); //Check Status Of Draw-Framebuffer assert(glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_COMPLETE); // glBindTexture(GL_TEXTURE_BINDING_2D_ARRAY,defaultTextureId); glBindFramebuffer(GL_FRAMEBUFFER,defaultFramebufferId); _shadowMapSize = mapSize; _isDepthLayerArray = true; _numberOfLayer = numberOfLayer; return true; }
ArrayTexture::ArrayTexture(string tmpl, int num, const unsigned int width, const unsigned int height, GLenum format, GLenum internalFormat, GLenum precision) { this->width = width; this->height = height; this->format = format; this->internalFormat = internalFormat; this->precision = precision; this->target = GL_TEXTURE_2D_ARRAY; mipLevels = 10; this->layers = num; glGenTextures(1, &glId); GL_CHECK_ERRORS(); glBindTexture(target, glId); GL_CHECK_ERRORS(); glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, mipLevels); glTexStorage3D(target, mipLevels, precision, width, height, layers); tmpl = FOLDER + tmpl; for (int i = 0; i < num; i++) { char buff[1024]; snprintf(buff, sizeof(buff), tmpl.c_str(), i); string file = buff; if (!Globals::File_Exists(file)) { cout << "File " << file << " does not exist. Can not load texture." << endl; return; } int load_width; int load_height; int load_channels; unsigned char *image = SOIL_load_image((file).c_str(), &load_width, &load_height, &load_channels, format == GL_RGBA ? SOIL_LOAD_RGBA : SOIL_LOAD_RGB); //cout << file << " " << width << "x" << height << " (" << load_channels << ") " << endl; assert(width == load_width); assert(height == load_height); glTexSubImage3D(target, 0, 0, 0, i, width, height, 1, format, internalFormat, image); SOIL_free_image_data(image); } if (mipLevels > 0) glGenerateMipmap(target); glBindTexture(target, 0); GL_CHECK_ERRORS(); }
void QOpenGLTextureHelper::qt_TextureStorage3D(GLuint texture, GLenum target, GLenum bindingTarget, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth) { GLint oldTexture; glGetIntegerv(bindingTarget, &oldTexture); glBindTexture(target, texture); glTexStorage3D(target, levels, internalFormat, width, height, depth); glBindTexture(target, oldTexture); }
static GLuint create_texcube(void) { GLuint tex, fb; GLenum status; int layer; glGenTextures(1, &tex); glBindTexture(target, tex); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (test_array) glTexStorage3D(target, TEX_LEVELS, format, TEX_SIZE, TEX_SIZE, num_layers); else glTexStorage2D(target, TEX_LEVELS, format, TEX_SIZE, TEX_SIZE); glGenFramebuffers(1, &fb); glBindFramebuffer(GL_FRAMEBUFFER, fb); for (layer = 0; layer < num_layers; layer++) { if (test_array) glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0, layer); else glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer, tex, 0); status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { load_texcube(); goto done; } glViewport(0, 0, TEX_SIZE, TEX_SIZE); piglit_ortho_projection(TEX_SIZE, TEX_SIZE, GL_FALSE); glColor4fv(colors[(layer + 0) % NUM_COLORS]); piglit_draw_rect(0, 0, TEX_HALF, TEX_HALF); glColor4fv(colors[(layer + 2) % NUM_COLORS]); piglit_draw_rect(TEX_HALF, 0, TEX_HALF, TEX_HALF); glColor4fv(colors[(layer + 4) % NUM_COLORS]); piglit_draw_rect(0, TEX_HALF, TEX_HALF, TEX_HALF); glColor4fv(colors[(layer + 6) % NUM_COLORS]); piglit_draw_rect(TEX_HALF, TEX_HALF, TEX_HALF, TEX_HALF); } done: glGenerateMipmap(target); glDeleteFramebuffers(1, &fb); return tex; }
void ShadowDevice::Init(GLRenderer* p_renderer, int p_width, int p_height, BufferInterface* p_cameraBuffer, BufferInterface* p_uniforms) { m_width = p_width; m_height = p_height; m_cameraBuffer = p_cameraBuffer; m_uniforms = p_uniforms; glGenTextures(1, &m_depthTextureArray); glBindTexture(GL_TEXTURE_2D_ARRAY, m_depthTextureArray); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT32F, m_width, m_height, RENDER_SHADOW_CASCADES); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); for(int i = 0; i < RENDER_SHADOW_CASCADES; i++) { glGenFramebuffers(1, &m_framebuffers[i]); glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffers[i]); glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_depthTextureArray, 0, i); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); switch (status) { case GL_FRAMEBUFFER_COMPLETE: g_context.m_logger->LogText(LogTag::RENDER, LogLevel::SUCCESS, "Good framebuffer support."); break; default: g_context.m_logger->LogText(LogTag::RENDER, LogLevel::WARNING, "Bad framebuffer support!"); break; } glBindFramebuffer(GL_FRAMEBUFFER, 0); } glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); m_shadowEffect = g_context.m_resourceManager->LoadEffect("Renderer/Shadow"); glGenSamplers(1, &m_samplerObjectPCF); glGenSamplers(1, &m_samplerObjectFloat); glSamplerParameteri(m_samplerObjectPCF, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_samplerObjectPCF, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_samplerObjectPCF, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(m_samplerObjectPCF, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(m_samplerObjectPCF, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glSamplerParameteri(m_samplerObjectPCF, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glSamplerParameteri(m_samplerObjectFloat, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_samplerObjectFloat, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_samplerObjectFloat, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(m_samplerObjectFloat, GL_TEXTURE_MAG_FILTER, GL_LINEAR); }
void CascadedShadowMappingRenderer::initRendering() { initCamera( NvCameraXformType::MAIN, nv::vec3f(-15.0f, 5.0f, 15.0f), // position nv::vec3f(0.0f, 0.0f, 0.0f)); // look at point // Setup the light parameters. initLight( nv::vec3f(100.0f, 100.0f, 100.0f), nv::vec3f(0.0f, 0.0f, 0.0f), nv::vec3f(0.0f, 1.0f, 0.0f)); // Load shaders. NvAssetLoaderAddSearchPath("gl4-maxwell/CascadedShadowMapping"); m_cameraProgram = new CameraProgram(); m_cameraProgram->init("shaders/Camera.vert", "shaders/Camera.frag"); m_lightStandardProgram = new LightProgram(); m_lightStandardProgram->init("shaders/Light.vert", "shaders/LightStandard.geom"); m_lightGsCullProgram = new LightProgram(); m_lightGsCullProgram->init("shaders/Light.vert", "shaders/LightGsCull.geom"); m_lightGsMulticastCullProgram = new LightProgram(); m_lightGsMulticastCullProgram->init("shaders/Light.vert", "shaders/LightMulticast.geom"); m_lightFgsMulticastCullProgram = new LightProgram(); m_lightFgsMulticastCullProgram->init("shaders/Light.vert", "shaders/LightFgsMulticast.geom"); m_lightVsOnlyMulticastProgram = new LightVsOnlyProgram(); m_lightVsOnlyMulticastProgram->init("shaders/LightVsOnly.vert"); // Setup geometry. initGeometry(10); // Setup resources for shadow pass. glGenFramebuffers(1, &m_lightFBO); glBindFramebuffer(GL_FRAMEBUFFER, m_lightFBO); glGenTextures(1, &m_lightTex); glBindTexture(GL_TEXTURE_2D_ARRAY, m_lightTex); glTexStorage3D(GL_TEXTURE_2D_ARRAY, LIGHT_TEXUTRE_MIPMAP_LEVELS, GL_DEPTH_COMPONENT32F, LIGHT_TEXTURE_SIZE, LIGHT_TEXTURE_SIZE, MAX_CAMERA_FRUSTUM_SPLIT_COUNT); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_lightTex, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, m_app.getMainFBO()); glGetFloatv(GL_MAX_VIEWPORT_DIMS, m_viewportDims._array); }
static bool test_single_layer(const Params* p, int layer) { int l; GLuint tex_src, tex_view; GLboolean pass; GLubyte *image; assert(layer < p->num_layers); glGenTextures(1, &tex_src); glBindTexture(GL_TEXTURE_2D_ARRAY, tex_src); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, p->width, p->height, p->num_layers); /* load each array layer with red */ image = makesolidimage(p->width, p->height, red); for (l = 0; l < p->num_layers; l++) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l, p->width, p->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image); } /* make layer to check red, but green for pixel at (0,0) which should be the only one sampled */ memcpy(image, green, sizeof(green)); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layer, p->width, p->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image); free(image); glGenTextures(1, &tex_view); /* checked layer is supposed to be green */ glTextureView(tex_view, GL_TEXTURE_2D, tex_src, GL_RGBA8, 0, 1, layer, 1); 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_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, tex_view); /* draw it! */ piglit_draw_rect(-1, -1, 2, 2); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, greenf); if (!pass) { printf("layer %d failed\n", layer); } glDeleteTextures(1, &tex_view); glDeleteTextures(1, &tex_src); return pass; }
void Texture3D::LoadTexture(int width, int height, int depth, const char *data, Format format, int stride /*= -1*/) { GLint glFormat; GLint glInternalFormat; int elementSize = 0; switch (format) { case RGB: elementSize = 3; glFormat = GL_RGB; glInternalFormat = GL_RGB8; break; case RGBA: elementSize = 4; glFormat = GL_RGBA; glInternalFormat = GL_RGBA8; break; case Red: elementSize = 1; glFormat = GL_RED; glInternalFormat = GL_R8; break; case USHORT_5_5_5_1: elementSize = 2; glFormat = GL_UNSIGNED_SHORT_5_5_5_1; glInternalFormat = GL_RGBA8; break; case USHORT_1_5_5_5: elementSize = 2; glFormat = GL_UNSIGNED_SHORT_1_5_5_5_REV; glInternalFormat = GL_RGBA8; break; default: throw GraphicsException(GL_INVALID_ENUM, "Texture format not recognized"); break; } if (stride == -1) { stride = width * elementSize; } // Generate an texture GL_CHECKED(glGenTextures(1, &_id)); Bind(); GL_CHECKED(glPixelStorei(GL_UNPACK_ROW_LENGTH, stride)); //GL_CHECKED(glTexImage3D(_type, 0, glInternalFormat, width, height, depth, 0, glFormat, GL_UNSIGNED_BYTE, data)); GL_CHECKED(glTexStorage3D(_type, 1, glInternalFormat, width, height, depth)); if (data != nullptr) { GL_CHECKED(glTexSubImage3D(_type, 0, 0, 0, 0, width, height, depth, glFormat, GL_UNSIGNED_BYTE, data)); } GL_CHECKED(glPixelStorei(GL_UNPACK_ROW_LENGTH, 0)); UnBind(); }
void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Vector3i& size) { bindInternal(); /** @todo Re-enable when extension wrangler is available for ES2 */ #ifndef MAGNUM_TARGET_GLES2 glTexStorage3D(target, levels, GLenum(internalFormat), size.x(), size.y(), size.z()); #else //glTexStorage3DEXT(target, levels, GLenum(internalFormat), size.x(), size.y(), size.z()); static_cast<void>(target); static_cast<void>(levels); static_cast<void>(internalFormat); static_cast<void>(size); #endif }
GLuint CreateTextureArray(U16 width, U16 height, U32 depth, GLenum internal_format, GLenum wrap_mode, GLenum filter_mode) { GLuint textureID; glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D_ARRAY, textureID); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, internal_format, width, height, depth); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, wrap_mode); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, wrap_mode); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, filter_mode); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, filter_mode); glBindTexture(GL_TEXTURE_2D_ARRAY, 0); return textureID; }
// INPUT a texture target, a number of mipmaps, a texture format, a texture size // OUTPUT nothing, allocates the space for a texture3D CAMLprim value caml_tex_storage_3D(value target, value lvls, value tfmt, value size) { CAMLparam4(target,lvls,tfmt,size); glTexStorage3D(Target_val(target), Int_val(lvls), TextureFormat_val(tfmt), Int_val(Field(size,0)), Int_val(Field(size,1)), Int_val(Field(size,2))); CAMLreturn(Val_unit); }
void Renderer::loadTextures() { { QVector<QString> files; files << "dirt.png" << "sand.png" << "grass.png" << "mountain.png"; QVector<QImage> images(files.count(), QImage(QSize(700,700), QImage::Format_RGBA8888)); for (int i=0; i<images.count(); i++) { QImage &image = images[i]; if (!image.load(gDefaultPathTextures + files[i])) qDebug() << "Error loading texture " << gDefaultPathTextures + files[i]; } int imageSize = images.first().width(); //for now, assume all images are the same width and height glGenTextures(1, &mTextures.terrain); qDebug() << "I am " << mTextures.terrain; glBindTexture(GL_TEXTURE_2D_ARRAY, mTextures.terrain); GLenum format = GL_BGRA; int mipLevels = 8; glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevels, GL_RGBA8, imageSize, imageSize, 4); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, imageSize, imageSize, 1, format, GL_UNSIGNED_BYTE, images[0].bits()); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, imageSize, imageSize, 1, format, GL_UNSIGNED_BYTE, images[1].bits()); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 2, imageSize, imageSize, 1, format, GL_UNSIGNED_BYTE, images[2].bits()); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 3, imageSize, imageSize, 1, format, GL_UNSIGNED_BYTE, images[3].bits()); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); glSamplerParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); } }
void OpenGLTexture2D::CreateWithImmutableStorage(ElementInitData* initData) { GLenum internalFormat, externFormat, formatType; OpenGLMapping::Mapping(internalFormat, externFormat, formatType, mFormat); uint32_t texelSize = PixelFormatUtils::GetNumElemBytes(mFormat); if (mTextureArraySize > 1) { glTexStorage3D(mTextureTarget, mMipLevels, internalFormat, mWidth, mHeight, mTextureArraySize); if (initData) { for (uint32_t arrIndex = 0; arrIndex < mTextureArraySize; ++ arrIndex) { for (uint32_t level = 0; level < mMipLevels; ++ level) { uint32_t levelWidth = (std::max)(1U, mWidth >> level); uint32_t levelHeight = (std::max)(1U, mHeight >> level); if (PixelFormatUtils::IsCompressed(mFormat)) { int blockSize = (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) ? 8 : 16; uint32_t imageSize = ((levelWidth+3)/4)*((levelHeight+3)/4)*blockSize; glCompressedTexSubImage3D(mTextureTarget, static_cast<GLint>(level), 0, 0, static_cast<GLint>(arrIndex), static_cast<GLsizei>(levelWidth), static_cast<GLsizei>(levelHeight), static_cast<GLsizei>(0), externFormat, static_cast<GLsizei>(imageSize), initData[arrIndex * mMipLevels + level].pData); } else { glTexSubImage3D(mTextureTarget, static_cast<GLint>(level), 0, 0, static_cast<GLint>(arrIndex), static_cast<GLsizei>(levelWidth), static_cast<GLsizei>(levelHeight), static_cast<GLsizei>(1), externFormat, formatType, initData[arrIndex * mMipLevels + level].pData); } } } } }
GLTexture3D::GLTexture3D( const Vector3i& size, GLImageInternalFormat internalFormat, GLsizei nMipMapLevels ) : GLTexture( GLTexture::Target::TEXTURE_3D, internalFormat, nMipMapLevels ), m_size( size ) { assert( size.x > 0 ); assert( size.y > 0 ); assert( size.z > 0 ); assert( size.x <= GLTexture::maxSize3D() ); assert( size.y <= GLTexture::maxSize3D() ); assert( size.z <= GLTexture::maxSize3D() ); glTexStorage3D( glTarget(), numMipMapLevels(), glInternalFormat(), size.x, size.y, size.z ); }
int mrgss_renderer_initialize(mrgss_screen* window) { mrgss_renderer *renderer = window->renderer; size_t bufferSize; GLbitfield flags; //Create and activate the shader program as it will always use the same shader GLuint vshader,fshader; renderer->item_count = 0; renderer->tex_count = 0; renderer->isOutdated = 0; vshader = compile_shader(default_vertex, GL_VERTEX_SHADER); fshader = compile_shader(default_fragment, GL_FRAGMENT_SHADER); renderer->shader = compile_shader_program(vshader, fshader); glUseProgram(renderer->shader); // set ortho to the shader mrgss_renderer_resize_window(window); //creamos el buffer glGenBuffers(1, &renderer->vbo); glBindBuffer(GL_ARRAY_BUFFER, renderer->vbo); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vertex2D), 0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vertex2D), (GLvoid *) (sizeof (GL_FLOAT) * 3) ); bufferSize = MAX_SPRITES * 4 * sizeof(vertex2D);//el tamaño del buffer es de 4 vertices por sprite flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT; glBufferStorage(GL_ARRAY_BUFFER, bufferSize, 0, flags); renderer->persistentBuffer = (vertex2D*)glMapBufferRange(GL_ARRAY_BUFFER, 0, bufferSize, flags); //// creamos un buffer para enviar info a los shadders glGenBuffers(1, &renderer->ssbo); glBindBuffer(GL_SHADER_STORAGE_BUFFER, renderer->ssbo); bufferSize = MAX_SPRITES * 16 * sizeof(GLfloat); glBufferStorage(GL_SHADER_STORAGE_BUFFER, bufferSize, 0, flags); renderer->persistentShaderBuffer = (GLfloat*)glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, bufferSize, flags); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, renderer->ssbo); glGenTextures(1, &renderer->texture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, renderer->texture); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, MAX_IMG_SIZE, MAX_IMG_SIZE, 100); glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); return 0; }
static bool query_layers_state(void) { bool pass = true; GLuint tex[2], viewtex, l; GLint param; glGenTextures(2, tex); glBindTexture(GL_TEXTURE_2D_ARRAY, tex[0]); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 7, GL_RG16F, 64, 64, 10); glTextureView(tex[1], GL_TEXTURE_2D_ARRAY,tex[0], GL_RG16I, 0, 3, 1, 8); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; for (l = 0; l < 4; l++) { glGenTextures(1, &viewtex); glTextureView(viewtex, GL_TEXTURE_2D_ARRAY, tex[1], GL_RG16UI, 0, 4, l, 9); glBindTexture(GL_TEXTURE_2D_ARRAY, viewtex); /* test min_layers are additive using chained views */ glGetTexParameteriv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_VIEW_MIN_LAYER, ¶m); if (param != (1 + l)) { glDeleteTextures(1, &viewtex); printf("bad query of view_min_layer expected %u got %u\n", 1+l, param); pass = false; break; } /* test num_layers are correct for chained views */ glGetTexParameteriv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_VIEW_NUM_LAYERS, ¶m); if (param != (8 - l)) { glDeleteTextures(1, &viewtex); printf("bad query of view_num_layers expected %u got %u\n", 8 - l, param); pass = false; break; } glDeleteTextures(1, &viewtex); } glDeleteTextures(2, tex); return pass; }
void piglit_init(int argc, char **argv) { int tex_loc_cube, prog_cube, l; GLuint tex_2DArray, tex_Cube; #ifdef PIGLIT_USE_OPENGL piglit_require_extension("GL_ARB_texture_view"); piglit_require_extension("GL_ARB_texture_cube_map_array"); #else piglit_require_extension("GL_OES_texture_view"); piglit_require_extension("GL_OES_texture_cube_map_array"); #endif /* setup shaders and program object for Cube rendering */ prog_cube = piglit_build_simple_program(vs, fs); tex_loc_cube = glGetUniformLocation(prog_cube, "tex"); glGenTextures(1, &tex_2DArray); glBindTexture(GL_TEXTURE_2D_ARRAY, tex_2DArray); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 1, 1, 16); /* load each array layer with red */ for (l = 0; l < 16; l++) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, red); } /* make array layer 9 have green */ glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 9, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, green); glGenTextures(1, &tex_Cube); /* the texture view starts at layer 2, so face 1 (-X) of * element 1 will have green */ glTextureView(tex_Cube, GL_TEXTURE_CUBE_MAP_ARRAY, tex_2DArray, GL_RGBA8, 0, 1, 2, 12); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, tex_Cube); glUseProgram(prog_cube); glUniform1i(tex_loc_cube, 0); }
bool initTextureArray() { GLint MaxTextureArrayLayers(0); glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &MaxTextureArrayLayers); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &Texture2DArrayName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, Texture2DArrayName); // Set image gli::texture2DArray Texture(gli::loadStorageDDS(glf::DATA_DIRECTORY + TEXTURE_DIFFUSE)); glTexStorage3D( GL_TEXTURE_2D_ARRAY, GLsizei(Texture.levels()), gli::internal_format(Texture.format()), GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y), GLsizei(Texture.layers())); //depth for(gli::texture2DArray::size_type Array = 0; Array < Texture.layers(); ++Array) for(gli::texture2DArray::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage3D( GL_TEXTURE_2D_ARRAY, GLint(Level), 0, // offset x 0, // offset y GLint(Array), // offset z GLsizei(Texture[Array][Level].dimensions().x), GLsizei(Texture[Array][Level].dimensions().y), GLsizei(1), //depth gli::external_format(Texture.format()), gli::type_format(Texture.format()), Texture[Array][Level].data()); } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return glf::checkError("initTextureArray"); }
/** * Allocate a 1-level 3D texture. */ static void alloc_tex3d(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth) { if (target == GL_TEXTURE_3D) { glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } if (piglit_is_extension_supported("GL_ARB_texture_storage")) { glTexStorage3D(target, 1, internalFormat, width, height, depth); } else { glTexImage3D(target, 0, internalFormat, width, height, depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } }
void Texture::SetStorage(int width, int height, int depth, int levels){ switch(type){ case TT_GL_TEXTURE_1D: GLCALL(glTexStorage1D(type, levels, format, width)); break; case TT_GL_TEXTURE_2D: case TT_GL_TEXTURE_1D_ARRAY: case TT_GL_TEXTURE_RECTANGLE: case TT_GL_TEXTURE_CUBE_MAP: GLCALL(glTexStorage2D(type, levels, format, width, height)); break; case TT_GL_TEXTURE_3D: case TT_GL_TEXTURE_2D_ARRAY: case TT_GL_TEXTURE_CUBE_MAP_ARRAY: GLCALL(glTexStorage3D(type, levels, format, width, height, depth)); break; } }
bool initTexture() { bool Validated(true); gli::gl GL(gli::gl::PROFILE_GL33); gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str())); 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_ARRAY, TextureName); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexStorage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Texture.levels()), Format.Internal, static_cast<GLsizei>(Texture[0].extent().x), static_cast<GLsizei>(Texture[0].extent().y), static_cast<GLsizei>(1)); for(gli::texture2d::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Level), 0, 0, 0, static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), static_cast<GLsizei>(1), Format.External, Format.Type, Texture[Level].data()); } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return Validated; }
bool initTexture() { GLint MaxTextureArrayLayers(0); glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &MaxTextureArrayLayers); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &TextureName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName); gli::texture2DArray Texture(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture2DArray::texelcoord_type(4), 15, 1); for(gli::size_t LayerIndex = 0, LayerCount = Texture.layers(); LayerIndex < LayerCount; ++LayerIndex) { float const Progress = static_cast<float>(LayerIndex) / static_cast<float>(LayerCount); glm::u8vec4 const Color(glm::vec4(Progress, 0.5f + Progress * 0.5f, 1.f - Progress, 1.f) * 255.f); Texture[LayerIndex].clear<glm::u8vec4>(Color); } gli::gl GL; gli::gl::format const Format = GL.translate(Texture.format()); glTexStorage3D(GL_TEXTURE_2D_ARRAY, GLsizei(Texture.levels()), Format.Internal, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y), GLsizei(Texture.layers())); for(gli::texture2DArray::size_type Array = 0; Array < Texture.layers(); ++Array) for(gli::texture2DArray::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage3D(GL_TEXTURE_2D_ARRAY, GLint(Level), 0, 0, GLint(Array), GLsizei(Texture[Array][Level].dimensions().x), GLsizei(Texture[Array][Level].dimensions().y), GLsizei(1), Format.External, Format.Type, Texture[Array][Level].data()); } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return true; }
bool initFramebuffer() { glGenTextures(1, &MultisampleTextureName); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, MultisampleTextureName); glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 4, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 1, GL_TRUE); glGenFramebuffers(1, &FramebufferRenderName); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferRenderName); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, MultisampleTextureName, 0); if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; glBindFramebuffer(GL_FRAMEBUFFER, 0); glGenTextures(1, &ColorTextureName); glBindTexture(GL_TEXTURE_2D_ARRAY, ColorTextureName); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 1); glGenFramebuffers(1, &FramebufferResolveName); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferResolveName); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, ColorTextureName, 0); if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; glBindFramebuffer(GL_FRAMEBUFFER, 0); return true; }
bool upDataT( DataTexture& t ) { //load file glGenTextures( 1, &t.textureID_ ); t.samplerPos_ = totalSamples; activateT( &t ); totalSamples++; if( t.depth_ > 1 ) { //glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, t.width_, t.height_, t.depth_, 0, GL_RGBA, GL_UNSIGNED_BYTE, t.data_.get()); glTexStorage3D( GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, t.width_, t.height_, t.depth_ ); glTexSubImage3D( GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, t.width_, t.height_, t.depth_, GL_RGBA, GL_UNSIGNED_BYTE, t.data_.get() ); } else { glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, t.width_, t.height_, 0, GL_RGBA, GL_UNSIGNED_BYTE, t.data_.get() ); } t.data_.memClear(); GLfloat fLargest; glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest ); if( t.depth_ > 1 ) { glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE ); glTexParameterf( GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest ); } else { 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 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest ); } return true; }