bool StGLStereoFrameBuffer::initLazy(StGLContext& theCtx, const GLsizei theSizeX, const GLsizei theSizeY, const bool theNeedDepthBuffer, const bool theToCompress) { if(isValid() && (theSizeX <= getSizeX() && getSizeX() < theCtx.getMaxTextureSize()) && (theSizeY <= getSizeY() && getSizeY() < theCtx.getMaxTextureSize())) { if(!theToCompress || (((getSizeX() - theSizeX) < 256) && ((getSizeY() - theSizeY) < 256))) { setVPDimensions(theCtx, theSizeX, theSizeY); return true; } } release(theCtx); GLsizei aSizeX = stMax(32, (GLsizei )getAligned(theSizeX, 256)); GLsizei aSizeY = stMax(32, (GLsizei )getAligned(theSizeY, 256)); if(!theCtx.arbNPTW) { StGLFrameBuffer::convertToPowerOfTwo(theCtx, aSizeX, aSizeY); } if(!init(theCtx, aSizeX, aSizeY, theNeedDepthBuffer)) { return false; } theCtx.stglFillBitsFBO(myGLFBufferIds[StGLStereoTexture::LEFT_TEXTURE], aSizeX, aSizeY); ST_DEBUG_LOG("FBO resized to " + aSizeX + " x " + aSizeY + " (for " + theSizeX + " x " + theSizeY + ")"); setVPDimensions(theCtx, theSizeX, theSizeY); return true; }
bool StGLFontEntry::createTexture(StGLContext& theCtx) { const GLint aMaxSize = theCtx.getMaxTextureSize(); GLint aGlyphsNb = 0; if(myFont->hasCJK() || myFont->hasKorean()) { // italic does not make sense for Chinese // limit overall number of glyphs in the single texture to 4k // (single font file might contain about 20k-50k glyphs) aGlyphsNb = stMin(4000, 2 * myFont->getGlyphsNumber() - GLint(myLastTileId) + 1); } else { // western might contain reg/bold/italic/bolditalic styles // limit overall number of glyphs in the single texture to 1k // (single font file might contain about 6k glyphs for different languages) aGlyphsNb = stMin(1000, 4 * myFont->getGlyphsNumber() - GLint(myLastTileId) + 1); } const GLsizei aTextureSizeX = getPowerOfTwo(aGlyphsNb * myTileSizeX, aMaxSize); const size_t aTilesPerRow = aTextureSizeX / myTileSizeX; GLsizei aTextureSizeY = stMin(getEvenNumber(GLint((aGlyphsNb / aTilesPerRow) + 1) * myTileSizeY), aMaxSize); if(!theCtx.arbNPTW) { aTextureSizeY = getPowerOfTwo(aTextureSizeY, aMaxSize); } stMemZero(&myLastTilePx, sizeof(myLastTilePx)); myLastTilePx.bottom() = myTileSizeY; myTextures.add(new StGLTexture(theCtx.arbTexRG ? GL_R8 : GL_ALPHA)); myFbos.add(new StGLFrameBuffer()); StHandle<StGLTexture>& aTexture = myTextures[myTextures.size() - 1]; StHandle<StGLFrameBuffer>& aFbo = myFbos [myTextures.size() - 1]; if(!aTexture->initTrash(theCtx, aTextureSizeX, aTextureSizeY)) { return false; } aTexture->bind(theCtx); theCtx.core11fwd->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); theCtx.core11fwd->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); aTexture->unbind(theCtx); // destruction of temporary FBO produces broken texture on Catalyst drivers for unknown reason //StGLFrameBuffer::clearTexture(theCtx, aTexture); #if !defined(GL_ES_VERSION_2_0) if(theCtx.arbTexClear) { theCtx.core11fwd->glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); theCtx.core11fwd->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); theCtx.core11fwd->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); const stUByte_t THE_BLACK = 0; theCtx.extAll->glClearTexImage(aTexture->getTextureId(), 0, theCtx.arbTexRG ? GL_RED : GL_ALPHA, GL_UNSIGNED_BYTE, &THE_BLACK); } else if(aFbo->init(theCtx, aTexture, false)) { aFbo->clearTexture(theCtx); } else { ST_ERROR_LOG("Fail to bind " + (theCtx.arbTexRG ? "GL_R8" : "GL_ALPHA8") + " texture to FBO!"); } #else (void )aFbo; #endif return true; }
void StGLFrameTextures::increaseSize(StGLContext& theCtx, StGLFrameTexture& theTexture, const GLsizei theTextureSizeX, const GLsizei theTextureSizeY) { // test existing size / new size /// TODO (Kirill Gavrilov#8) we can automatically reduce texture size here if((theTexture.getSizeX() < theTextureSizeX) || (theTexture.getSizeY() < theTextureSizeY) || !theTexture.isValid()) { ST_DEBUG_LOG("Requested texture size (" + theTextureSizeX + 'x' + theTextureSizeY + ") larger than current texture size(" + theTexture.getSizeX() + 'x' + theTexture.getSizeY() + ')'); const GLsizei anOriginalSizeX = theTexture.getSizeX(); const GLsizei anOriginalSizeY = theTexture.getSizeY(); const GLint aMaxTexDim = theCtx.getMaxTextureSize(); GLsizei aNewSizeX = stMin(theTextureSizeX, GLsizei(aMaxTexDim)); GLsizei aNewSizeY = stMin(theTextureSizeY, GLsizei(aMaxTexDim)); if(!theCtx.arbNPTW) { aNewSizeX = getPowerOfTwo(theTextureSizeX, GLsizei(aMaxTexDim)); aNewSizeY = getPowerOfTwo(theTextureSizeY, GLsizei(aMaxTexDim)); } if((aNewSizeY != anOriginalSizeY) || (aNewSizeX != anOriginalSizeX)) { if(!theTexture.initTrash(theCtx, aNewSizeX, aNewSizeY)) { theTexture.initTrash(theCtx, (anOriginalSizeX > 0) ? anOriginalSizeX : 512, (anOriginalSizeY > 0) ? anOriginalSizeY : 512); ST_DEBUG_LOG("FAILED to Increase the texture size to (" + aNewSizeX + 'x' + aNewSizeY + ")!"); } else { ST_DEBUG_LOG("Increase the texture size to (" + aNewSizeX + 'x' + aNewSizeY + ") success!"); } } else { ST_DEBUG_LOG("Not possible to Increase the texture size!"); } } }