diff --git a/include/osgText/Text b/include/osgText/Text index ef4f2a940..52c2feba1 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -304,30 +304,15 @@ public: typedef osg::ref_ptr TexCoords; typedef osg::ref_ptr ColorCoords; -#ifdef NEW_APPROACH typedef Coords3 Coords; -#else - typedef Coords2 Coords; -#endif Glyphs _glyphs; Coords _coords; -#ifdef NEW_APPROACH -// Coords3 _transformedCoords; -#else - osg::buffered_object _transformedCoords; -#endif - - TexCoords _texcoords; LineNumbers _lineNumbers; -#ifdef NEW_APPROACH Coords3 _transformedBackdropCoords[8]; -#else - osg::buffered_object _transformedBackdropCoords[8]; -#endif ColorCoords _colorCoords; @@ -343,8 +328,6 @@ public: Glyphs& getGlyphs() { return _glyphs; } const Glyphs& getGlyphs() const { return _glyphs; } -#ifdef NEW_APPROACH - void addCoord(const osg::Vec2& c) { _coords->push_back(osg::Vec3(c.x(), c.y(), 0.0f)); } void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); } @@ -352,29 +335,9 @@ public: Coords3& getCoords() { return _coords; } const Coords3& getCoords() const { return _coords; } -#else - void addCoord(const osg::Vec2& c) { _coords->push_back(c); } - - void getCoord(unsigned int i, osg::Vec2& c) const { c = (*_coords)[i]; } - void getCoord(unsigned int i, osg::Vec3& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y(), 0.0f); } - - Coords2& getCoords() { return _coords; } - const Coords2& getCoords() const { return _coords; } -#endif void addTexCoord(const osg::Vec2& tc) { _texcoords->push_back(tc); } -#ifndef NEW_APPROACH - Coords3& getTransformedCoords(unsigned int contexID) { return _transformedCoords[contexID]; } - const Coords3& getTransformedCoords(unsigned int contexID) const { return _transformedCoords[contexID]; } - - TexCoords& getTexCoords() { return _texcoords; } - const TexCoords& getTexCoords() const { return _texcoords; } - - LineNumbers& getLineNumbers() { return _lineNumbers; } - const LineNumbers& getLineNumbers() const { return _lineNumbers; } -#endif - /** Resize any per context GLObject buffers to specified size. */ void resizeGLObjectBuffers(unsigned int maxSize); diff --git a/include/osgText/TextBase b/include/osgText/TextBase index f98189272..e2040405f 100644 --- a/include/osgText/TextBase +++ b/include/osgText/TextBase @@ -20,8 +20,6 @@ #include #include -#define NEW_APPROACH - namespace osgText { @@ -320,10 +318,6 @@ protected: int _width; int _height; osg::Vec3 _transformedPosition; -#ifndef NEW_APPROACH - osg::Matrix _modelview; - osg::Matrix _projection; -#endif osg::Matrix _matrix; }; diff --git a/src/osgText/FadeText.cpp b/src/osgText/FadeText.cpp index d572324c8..ca5ec443b 100644 --- a/src/osgText/FadeText.cpp +++ b/src/osgText/FadeText.cpp @@ -393,17 +393,9 @@ void FadeText::drawImplementation(osg::RenderInfo& renderInfo) const userData->_fadeTextInView.clear(); } - - -#ifdef NEW_APPROACH osg::Matrix lmv = state.getModelViewMatrix(); computeMatrix(state, lmv); lmv.postMult(state.getModelViewMatrix()); -#else - osgText::Text::AutoTransformCache& atc = _autoTransformCache[renderInfo.getContextID()]; - osg::Matrix lmv = atc._matrix; - lmv.postMult(state.getModelViewMatrix()); -#endif if (renderInfo.getView() && renderInfo.getView()->getCamera()) { diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 1680d0776..b023cce63 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -732,159 +732,15 @@ void Text::computePositions(unsigned int contextID) const case RIGHT_BOTTOM_BASE_LINE: _offset.set(_textBB.xMax(),-_characterHeight*(1.0 + _lineSpacing)*(_lineCount-1),0.0f); break; } -#ifndef NEW_APPROACH - AutoTransformCache& atc = _autoTransformCache[contextID]; - osg::Matrix& matrix = atc._matrix; - - if (_characterSizeMode!=OBJECT_COORDS || _autoRotateToScreen) - { - - matrix.makeTranslate(-_offset); - - osg::Matrix rotate_matrix; - if (_autoRotateToScreen) - { - osg::Vec3d trans(atc._modelview.getTrans()); - atc._modelview.setTrans(0.0f,0.0f,0.0f); - - rotate_matrix.invert(atc._modelview); - - atc._modelview.setTrans(trans); - } - - matrix.postMultRotate(_rotation); - - if (_characterSizeMode!=OBJECT_COORDS) - { - - osg::Matrix M(rotate_matrix); - M.postMultTranslate(_position); - M.postMult(atc._modelview); - osg::Matrix& P = atc._projection; - - // compute the pixel size vector. - - // pre adjust P00,P20,P23,P33 by multiplying them by the viewport window matrix. - // here we do it in short hand with the knowledge of how the window matrix is formed - // note P23,P33 are multiplied by an implicit 1 which would come from the window matrix. - // Robert Osfield, June 2002. - - // scaling for horizontal pixels - float P00 = P(0,0)*atc._width*0.5f; - float P20_00 = P(2,0)*atc._width*0.5f + P(2,3)*atc._width*0.5f; - osg::Vec3 scale_00(M(0,0)*P00 + M(0,2)*P20_00, - M(1,0)*P00 + M(1,2)*P20_00, - M(2,0)*P00 + M(2,2)*P20_00); - - // scaling for vertical pixels - float P10 = P(1,1)*atc._height*0.5f; - float P20_10 = P(2,1)*atc._height*0.5f + P(2,3)*atc._height*0.5f; - osg::Vec3 scale_10(M(0,1)*P10 + M(0,2)*P20_10, - M(1,1)*P10 + M(1,2)*P20_10, - M(2,1)*P10 + M(2,2)*P20_10); - - float P23 = P(2,3); - float P33 = P(3,3); - - float pixelSizeVector_w = M(3,2)*P23 + M(3,3)*P33; - - float pixelSizeVert=(_characterHeight*sqrtf(scale_10.length2()))/(pixelSizeVector_w*0.701f); - float pixelSizeHori=(_characterHeight/getCharacterAspectRatio()*sqrtf(scale_00.length2()))/(pixelSizeVector_w*0.701f); - - // avoid nasty math by preventing a divide by zero - if (pixelSizeVert == 0.0f) - pixelSizeVert= 1.0f; - if (pixelSizeHori == 0.0f) - pixelSizeHori= 1.0f; - - if (_characterSizeMode==SCREEN_COORDS) - { - float scale_font_vert=_characterHeight/pixelSizeVert; - float scale_font_hori=_characterHeight/getCharacterAspectRatio()/pixelSizeHori; - - if (P10<0) - scale_font_vert=-scale_font_vert; - matrix.postMultScale(osg::Vec3f(scale_font_hori, scale_font_vert,1.0f)); - } - else if (pixelSizeVert>getFontHeight()) - { - float scale_font = getFontHeight()/pixelSizeVert; - matrix.postMultScale(osg::Vec3f(scale_font, scale_font,1.0f)); - } - - } - - if (_autoRotateToScreen) - { - matrix.postMult(rotate_matrix); - } - - matrix.postMultTranslate(_position); - } - else if (!_rotation.zeroRotation()) - { - matrix.makeRotate(_rotation); - matrix.preMultTranslate(-_offset); - matrix.postMultTranslate(_position); - - // OSG_NOTICE<<"Old Need to rotate "<second; - //OSG_NOTICE<<"Text::computePositions("<size()); } } - -#ifndef NEW_APPROACH - // restore the previous modelview matrix - state.applyModelViewMatrix(previous); -#endif } #if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) @@ -1620,58 +1373,42 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie state.unbindElementBufferObject(); } -#ifdef NEW_APPROACH if (needToApplyMatrix) { // apply this new modelview matrix state.applyModelViewMatrix(previous_modelview); } -#endif } void Text::accept(osg::Drawable::ConstAttributeFunctor& af) const { + // TODO what to do about local transforms? for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin(); titr!=_textureGlyphQuadMap.end(); ++titr) { const GlyphQuads& glyphquad = titr->second; -#ifdef NEW_APPROACH if (glyphquad._coords.valid() ) { af.apply(osg::Drawable::VERTICES, glyphquad._coords->size(), &(glyphquad._coords->front())); af.apply(osg::Drawable::TEXTURE_COORDS_0, glyphquad._texcoords->size(), &(glyphquad._texcoords->front())); } -#else - if (!glyphquad._transformedCoords.empty() && glyphquad._transformedCoords[0].valid()) - { - af.apply(osg::Drawable::VERTICES, glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front())); - af.apply(osg::Drawable::TEXTURE_COORDS_0, glyphquad._texcoords->size(), &(glyphquad._texcoords->front())); - } -#endif } } void Text::accept(osg::PrimitiveFunctor& pf) const { + // TODO what to do about local transforms? for(TextureGlyphQuadMap::const_iterator titr=_textureGlyphQuadMap.begin(); titr!=_textureGlyphQuadMap.end(); ++titr) { const GlyphQuads& glyphquad = titr->second; -#ifdef NEW_APPROACH if (glyphquad._coords.valid()) { pf.setVertexArray(glyphquad._coords->size(), &(glyphquad._coords->front())); pf.drawArrays(GL_QUADS, 0, glyphquad._coords->size()); } -#else - if (!glyphquad._transformedCoords.empty() && glyphquad._transformedCoords[0].valid()) - { - pf.setVertexArray(glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front())); - pf.drawArrays(GL_QUADS, 0, glyphquad._transformedCoords[0]->size()); - } -#endif } } @@ -1780,13 +1517,8 @@ float Text::bilinearInterpolate(float x1, float x2, float y1, float y2, float x, void Text::drawForegroundText(osg::State& state, const GlyphQuads& glyphquad, const osg::Vec4& colorMultiplier) const { - -#ifdef NEW_APPROACH const GlyphQuads::Coords3& transformedCoords = glyphquad._coords; -#else - unsigned int contextID = state.getContextID(); - const GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID]; -#endif + if (transformedCoords.valid() && !transformedCoords->empty()) { state.setVertexPointer(transformedCoords.get()); @@ -1851,10 +1583,6 @@ void Text::renderWithDelayedDepthWrites(osg::State& state, const osg::Vec4& colo void Text::drawTextWithBackdrop(osg::State& state, const osg::Vec4& colorMultiplier) const { -#ifndef NEW_APPROACH - unsigned int contextID = state.getContextID(); -#endif - for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin(); titr!=_textureGlyphQuadMap.end(); ++titr) @@ -1885,11 +1613,7 @@ void Text::drawTextWithBackdrop(osg::State& state, const osg::Vec4& colorMultipl for( ; backdrop_index < max_backdrop_index; backdrop_index++) { -#ifdef NEW_APPROACH const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; -#else - const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; -#endif if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer(transformedBackdropCoords.get()); @@ -1907,10 +1631,6 @@ void Text::renderWithPolygonOffset(osg::State& state, const osg::Vec4& colorMult { #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) -#ifndef NEW_APPROACH - unsigned int contextID = state.getContextID(); -#endif - if (!osg::PolygonOffset::areFactorAndUnitsMultipliersSet()) { osg::PolygonOffset::setFactorAndUnitsMultipliersUsingBestGuessForDriver(); @@ -1948,11 +1668,7 @@ void Text::renderWithPolygonOffset(osg::State& state, const osg::Vec4& colorMult for( ; backdrop_index < max_backdrop_index; backdrop_index++) { -#ifdef NEW_APPROACH const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; -#else - const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; -#endif if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( transformedBackdropCoords.get()); @@ -1979,10 +1695,6 @@ void Text::renderWithNoDepthBuffer(osg::State& state, const osg::Vec4& colorMult { #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) -#ifndef NEW_APPROACH - unsigned int contextID = state.getContextID(); -#endif - glPushAttrib(GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); @@ -2014,11 +1726,7 @@ void Text::renderWithNoDepthBuffer(osg::State& state, const osg::Vec4& colorMult for( ; backdrop_index < max_backdrop_index; backdrop_index++) { -#ifdef NEW_APPROACH const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; -#else - const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; -#endif if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( transformedBackdropCoords.get()); @@ -2040,10 +1748,6 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl { #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) -#ifndef NEW_APPROACH - unsigned int contextID = state.getContextID(); -#endif - // Hmmm, the man page says GL_VIEWPORT_BIT for Depth range (near and far) // but experimentally, GL_DEPTH_BUFFER_BIT for glDepthRange. // glPushAttrib(GL_VIEWPORT_BIT); @@ -2077,11 +1781,7 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl for( ; backdrop_index < max_backdrop_index; backdrop_index++) { -#ifdef NEW_APPROACH const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; -#else - const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; -#endif if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( transformedBackdropCoords.get()); @@ -2119,9 +1819,6 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult * 7c) If priority levels are different, then make sure the foreground * text has the higher priority. */ -#ifndef NEW_APPROACH - unsigned int contextID = state.getContextID(); -#endif TextureGlyphQuadMap::iterator titr; // Moved up here for VC6 glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_STENCIL_TEST); @@ -2181,11 +1878,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult for( ; backdrop_index < max_backdrop_index; backdrop_index++) { -#ifdef NEW_APPROACH const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; -#else - const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; -#endif if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( transformedBackdropCoords.get()); @@ -2194,11 +1887,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult } // Draw the foreground text -#ifdef NEW_APPROACH const GlyphQuads::Coords3& transformedCoords = glyphquad._coords; -#else - const GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID]; -#endif if (transformedCoords.valid() && !transformedCoords->empty()) { state.setVertexPointer( transformedCoords.get()); @@ -2257,11 +1946,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult for( ; backdrop_index < max_backdrop_index; backdrop_index++) { -#ifdef NEW_APPROACH const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; -#else - const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; -#endif if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( transformedBackdropCoords.get()); @@ -2290,8 +1975,6 @@ Text::GlyphQuads::GlyphQuads(const GlyphQuads&) void Text::GlyphQuads::initGlyphQuads() { - -#ifdef NEW_APPROACH _coords = new osg::Vec3Array(); _texcoords = new osg::Vec2Array(); _colorCoords = new osg::Vec4Array(); @@ -2300,24 +1983,6 @@ void Text::GlyphQuads::initGlyphQuads() { _transformedBackdropCoords[j] = new osg::Vec3Array(); } -#else - _coords = new osg::Vec2Array(); - _texcoords = new osg::Vec2Array(); - _colorCoords = new osg::Vec4Array(); - - for (size_t i = 0; i < _transformedCoords.size(); i++) - { - _transformedCoords[i] = new osg::Vec3Array(); - } - - for (int j = 0; j < 8; j++) - { - for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) - { - _transformedBackdropCoords[j][i] = new osg::Vec3Array(); - } - } -#endif _quadIndices = new DrawElementsUShort(PrimitiveSet::TRIANGLES); } @@ -2351,7 +2016,7 @@ void Text::GlyphQuads::initGPUBufferObjects() _texcoords->setVertexBufferObject(vbo); _colorCoords->setBinding(osg::Array::BIND_PER_VERTEX); _colorCoords->setVertexBufferObject(vbo); -#ifdef NEW_APPROACH + for (int j = 0; j < 8; j++) { if (_transformedBackdropCoords[j].valid()) @@ -2360,27 +2025,6 @@ void Text::GlyphQuads::initGPUBufferObjects() _transformedBackdropCoords[j]->setVertexBufferObject(vbo); } } -#else - for (size_t i = 0; i < _transformedCoords.size(); i++) - { - if (_transformedCoords[i].valid()) - { - _transformedCoords[i]->setBinding(osg::Array::BIND_PER_VERTEX); - _transformedCoords[i]->setVertexBufferObject(vbo); - } - } - for (int j = 0; j < 8; j++) - { - for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) - { - if (_transformedBackdropCoords[j][i].valid()) - { - _transformedBackdropCoords[j][i]->setBinding(osg::Array::BIND_PER_VERTEX); - _transformedBackdropCoords[j][i]->setVertexBufferObject(vbo); - } - } - } -#endif _quadIndices->setElementBufferObject(new osg::ElementBufferObject()); } @@ -2388,7 +2032,6 @@ void Text::GlyphQuads::initGPUBufferObjects() void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize) { -#ifdef NEW_APPROACH _coords->resizeGLObjectBuffers(maxSize); for (int j = 0; j < 8; j++) @@ -2398,20 +2041,6 @@ void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize) _transformedBackdropCoords[j]->resizeGLObjectBuffers(maxSize); } } -#else - _transformedCoords.resize(maxSize); - - for (int j = 0; j < 8; j++) - { - for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) - { - if (_transformedBackdropCoords[j][i].valid()) - { - _transformedBackdropCoords[j][i]->resizeGLObjectBuffers(maxSize); - } - } - } -#endif _quadIndices->resizeGLObjectBuffers(maxSize); @@ -2420,7 +2049,6 @@ void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize) void Text::GlyphQuads::releaseGLObjects(osg::State* state) const { -#ifdef NEW_APPROACH _coords->releaseGLObjects(state);; for (int j = 0; j < 8; j++) @@ -2430,17 +2058,6 @@ void Text::GlyphQuads::releaseGLObjects(osg::State* state) const _transformedBackdropCoords[j]->releaseGLObjects(state); } } -#else - for (int j = 0; j < 8; j++) - { - for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) - { - if (_transformedBackdropCoords[j][i].valid()) - { - _transformedBackdropCoords[j][i]->releaseGLObjects(state); - } - } - } -#endif + _quadIndices->releaseGLObjects(state); }