diff options
author | 2011-11-16 12:22:10 -0800 | |
---|---|---|
committer | 2011-11-16 12:22:10 -0800 | |
commit | 2d8ef49914595f3f1df42fed0a9ae68777ff9411 (patch) | |
tree | a7bd41b3a01cb9a824056fc04972ddb72e88ee31 | |
parent | 7b95eba9f47a3992128d59a9ec593b887e4dac0e (diff) |
Fixing FBO font rendering bug that resulted from using old surface size.
Change-Id: I31d0967bb36ca6ffb6a4c8194597d3c523cfe954
-rw-r--r-- | libs/rs/rsContext.cpp | 24 | ||||
-rw-r--r-- | libs/rs/rsContext.h | 3 | ||||
-rw-r--r-- | libs/rs/rsFont.cpp | 10 | ||||
-rw-r--r-- | libs/rs/rsFont.h | 3 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.cpp | 5 | ||||
-rw-r--r-- | libs/rs/rsScriptC_LibGL.cpp | 5 |
6 files changed, 44 insertions, 6 deletions
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index f8213a1d2b11..293fc3ad953b 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -472,6 +472,30 @@ void Context::setSurface(uint32_t w, uint32_t h, RsNativeWindow sur) { } } +uint32_t Context::getCurrentSurfaceWidth() const { + for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) { + if (mFBOCache.mHal.state.colorTargets[i] != NULL) { + return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimX(); + } + } + if (mFBOCache.mHal.state.depthTarget != NULL) { + return mFBOCache.mHal.state.depthTarget->getType()->getDimX(); + } + return mWidth; +} + +uint32_t Context::getCurrentSurfaceHeight() const { + for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) { + if (mFBOCache.mHal.state.colorTargets[i] != NULL) { + return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimY(); + } + } + if (mFBOCache.mHal.state.depthTarget != NULL) { + return mFBOCache.mHal.state.depthTarget->getType()->getDimY(); + } + return mHeight; +} + void Context::pause() { rsAssert(mIsGraphicsContext); mPaused = true; diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index 199cc5a36051..c6582c9dffbc 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -164,6 +164,9 @@ public: uint32_t getWidth() const {return mWidth;} uint32_t getHeight() const {return mHeight;} + uint32_t getCurrentSurfaceWidth() const; + uint32_t getCurrentSurfaceHeight() const; + mutable ThreadIO mIO; // Timers diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp index 7efed9d9f948..81b96af685f4 100644 --- a/libs/rs/rsFont.cpp +++ b/libs/rs/rsFont.cpp @@ -654,11 +654,7 @@ void FontState::appendMeshQuad(float x1, float y1, float z1, const uint32_t floatsPerVert = 5; float *currentPos = mTextMeshPtr + mCurrentQuadIndex * vertsPerQuad * floatsPerVert; - // Cull things that are off the screen - float width = (float)mRSC->getWidth(); - float height = (float)mRSC->getHeight(); - - if (x1 > width || y1 < 0.0f || x2 < 0 || y4 > height) { + if (x1 > mSurfaceWidth || y1 < 0.0f || x2 < 0 || y4 > mSurfaceHeight) { return; } @@ -746,6 +742,10 @@ void FontState::renderText(const char *text, uint32_t len, int32_t x, int32_t y, return; } + // Cull things that are off the screen + mSurfaceWidth = (float)mRSC->getCurrentSurfaceWidth(); + mSurfaceHeight = (float)mRSC->getCurrentSurfaceHeight(); + currentFont->renderUTF(text, len, x, y, startIndex, numGlyphs, mode, bounds, bitmap, bitmapW, bitmapH); diff --git a/libs/rs/rsFont.h b/libs/rs/rsFont.h index 679591ca434f..4ca794dcee1c 100644 --- a/libs/rs/rsFont.h +++ b/libs/rs/rsFont.h @@ -160,6 +160,9 @@ public: protected: + float mSurfaceWidth; + float mSurfaceHeight; + friend class Font; struct CacheTextureLine { diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index 4a1362254b0b..871caacd6f66 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -206,8 +206,11 @@ void ProgramVertexState::init(Context *rsc) { void ProgramVertexState::updateSize(Context *rsc) { float *f = static_cast<float *>(mDefaultAlloc->getPtr()); + float surfaceWidth = (float)rsc->getCurrentSurfaceWidth(); + float surfaceHeight = (float)rsc->getCurrentSurfaceHeight(); + Matrix4x4 m; - m.loadOrtho(0,rsc->getWidth(), rsc->getHeight(),0, -1,1); + m.loadOrtho(0, surfaceWidth, surfaceHeight, 0, -1, 1); memcpy(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], m.m, sizeof(m)); memcpy(&f[RS_PROGRAM_VERTEX_MVP_OFFSET], m.m, sizeof(m)); diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp index 7862f3c7d1d3..26e2374719ce 100644 --- a/libs/rs/rsScriptC_LibGL.cpp +++ b/libs/rs/rsScriptC_LibGL.cpp @@ -79,23 +79,28 @@ void rsrBindProgramRaster(Context *rsc, Script *sc, ProgramRaster *pr) { void rsrBindFrameBufferObjectColorTarget(Context *rsc, Script *sc, Allocation *a, uint32_t slot) { CHECK_OBJ(va); rsc->mFBOCache.bindColorTarget(rsc, a, slot); + rsc->mStateVertex.updateSize(rsc); } void rsrBindFrameBufferObjectDepthTarget(Context *rsc, Script *sc, Allocation *a) { CHECK_OBJ(va); rsc->mFBOCache.bindDepthTarget(rsc, a); + rsc->mStateVertex.updateSize(rsc); } void rsrClearFrameBufferObjectColorTarget(Context *rsc, Script *sc, uint32_t slot) { rsc->mFBOCache.bindColorTarget(rsc, NULL, slot); + rsc->mStateVertex.updateSize(rsc); } void rsrClearFrameBufferObjectDepthTarget(Context *rsc, Script *sc) { rsc->mFBOCache.bindDepthTarget(rsc, NULL); + rsc->mStateVertex.updateSize(rsc); } void rsrClearFrameBufferObjectTargets(Context *rsc, Script *sc) { rsc->mFBOCache.resetAll(rsc); + rsc->mStateVertex.updateSize(rsc); } ////////////////////////////////////////////////////////////////////////////// |