Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 29, 2009, 7:12:27 PM (16 years ago)
Author:
rgrieder
Message:
  • Added unified diff file with our changes for OgreCEGUIRenderer
  • Minimised our changes
Location:
code/branches/buildsystem2/src/ogreceguirenderer
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUIRenderer.cpp

    r2569 r2602  
    11/************************************************************************
    2     filename:   OgreCEGUIRenderer.cpp
    3     created:    11/5/2004
    4     author:             Paul D Turner
    5    
    6     purpose:    Implementation of Renderer class for Ogre engine
     2        filename:       OgreCEGUIRenderer.cpp
     3        created:        11/5/2004
     4        author:         Paul D Turner
     5       
     6        purpose:        Implementation of Renderer class for Ogre engine
    77*************************************************************************/
    88/*************************************************************************
     
    4444{
    4545/*************************************************************************
    46     Constants definitions
     46        Constants definitions
    4747*************************************************************************/
    4848const size_t    OgreCEGUIRenderer::VERTEX_PER_QUAD                      = 6;
     
    5252
    5353/*************************************************************************
    54     Utility function to create a render operation and vertex buffer to render quads
     54        Utility function to create a render operation and vertex buffer to render quads
    5555*************************************************************************/
    5656static void createQuadRenderOp(Ogre::RenderOperation &d_render_op,
     
    5959    using namespace Ogre;
    6060    // Create and initialise the Ogre specific parts required for use in rendering later.
    61     d_render_op.vertexData = new VertexData;
    62     d_render_op.vertexData->vertexStart = 0;
    63 
    64     // setup vertex declaration for the vertex format we use
    65     VertexDeclaration* vd = d_render_op.vertexData->vertexDeclaration;
    66     size_t vd_offset = 0;
    67     vd->addElement(0, vd_offset, VET_FLOAT3, VES_POSITION);
    68     vd_offset += VertexElement::getTypeSize(VET_FLOAT3);
    69     vd->addElement(0, vd_offset, VET_COLOUR, VES_DIFFUSE);
    70     vd_offset += VertexElement::getTypeSize(VET_COLOUR);
    71     vd->addElement(0, vd_offset, VET_FLOAT2, VES_TEXTURE_COORDINATES);
    72 
    73     // create hardware vertex buffer
    74     d_buffer = HardwareBufferManager::getSingleton().createVertexBuffer(vd->getVertexSize(0), nquads, 
     61        d_render_op.vertexData = new VertexData;
     62        d_render_op.vertexData->vertexStart = 0;
     63
     64        // setup vertex declaration for the vertex format we use
     65        VertexDeclaration* vd = d_render_op.vertexData->vertexDeclaration;
     66        size_t vd_offset = 0;
     67        vd->addElement(0, vd_offset, VET_FLOAT3, VES_POSITION);
     68        vd_offset += VertexElement::getTypeSize(VET_FLOAT3);
     69        vd->addElement(0, vd_offset, VET_COLOUR, VES_DIFFUSE);
     70        vd_offset += VertexElement::getTypeSize(VET_COLOUR);
     71        vd->addElement(0, vd_offset, VET_FLOAT2, VES_TEXTURE_COORDINATES);
     72
     73        // create hardware vertex buffer
     74        d_buffer = HardwareBufferManager::getSingleton().createVertexBuffer(vd->getVertexSize(0), nquads, 
    7575        HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, false);
    7676
    77     // bind vertex buffer
    78     d_render_op.vertexData->vertexBufferBinding->setBinding(0, d_buffer);
    79 
    80     // complete render operation basic initialisation
    81     d_render_op.operationType = RenderOperation::OT_TRIANGLE_LIST;
    82     d_render_op.useIndexes = false;
     77        // bind vertex buffer
     78        d_render_op.vertexData->vertexBufferBinding->setBinding(0, d_buffer);
     79
     80        // complete render operation basic initialisation
     81        d_render_op.operationType = RenderOperation::OT_TRIANGLE_LIST;
     82        d_render_op.useIndexes = false;
    8383}
    8484
     
    9292
    9393/*************************************************************************
    94     Constructor
     94        Constructor
    9595*************************************************************************/
    9696OgreCEGUIRenderer::OgreCEGUIRenderer(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads)
    9797{
    98     constructor_impl(window, queue_id, post_queue, max_quads);
    99 }
    100 
    101 
    102 /*************************************************************************
    103     Constructor (specifying scene manager)
     98        constructor_impl(window, queue_id, post_queue, max_quads);
     99}
     100
     101
     102/*************************************************************************
     103        Constructor (specifying scene manager)
    104104*************************************************************************/
    105105OgreCEGUIRenderer::OgreCEGUIRenderer(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads, Ogre::SceneManager* scene_manager)
    106106{
    107     constructor_impl(window, queue_id, post_queue, max_quads);
    108 
    109     // hook into ogre rendering system
    110     setTargetSceneManager(scene_manager);
    111 }
    112 
    113 
    114 /*************************************************************************
    115     Destructor
     107        constructor_impl(window, queue_id, post_queue, max_quads);
     108
     109        // hook into ogre rendering system
     110        setTargetSceneManager(scene_manager);
     111}
     112
     113
     114/*************************************************************************
     115        Destructor
    116116*************************************************************************/
    117117OgreCEGUIRenderer::~OgreCEGUIRenderer(void)
    118118{
    119     setTargetSceneManager(NULL);
    120 
    121     if (d_ourlistener)
    122     {
    123         delete d_ourlistener;
    124     }
    125 
    126     // cleanup vertex data we allocated in constructor
    127     destroyQuadRenderOp(d_render_op, d_buffer);
     119        setTargetSceneManager(NULL);
     120
     121        if (d_ourlistener)
     122        {
     123                delete d_ourlistener;
     124        }
     125
     126        // cleanup vertex data we allocated in constructor
     127        destroyQuadRenderOp(d_render_op, d_buffer);
    128128    destroyQuadRenderOp(d_direct_render_op, d_direct_buffer);
    129129
    130     destroyAllTextures();
    131 }
    132 
    133 
    134 /*************************************************************************
    135     add's a quad to the list to be rendered
     130        destroyAllTextures();
     131}
     132
     133
     134/*************************************************************************
     135        add's a quad to the list to be rendered
    136136*************************************************************************/
    137137void OgreCEGUIRenderer::addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode)
    138138{
    139     // if not queueing, render directly (as in, right now!). This is used for the mouse cursor.
    140     if (!d_queueing)
    141     {
    142         renderQuadDirect(dest_rect, z, tex, texture_rect, colours, quad_split_mode);
    143     }
    144     else
    145     {
    146         d_sorted = false;
    147         QuadInfo quad;
    148        
    149         // set quad position, flipping y co-ordinates, and applying appropriate texel origin offset
    150         quad.position.d_left    = dest_rect.d_left;
    151         quad.position.d_right   = dest_rect.d_right;
    152         quad.position.d_top             = d_display_area.getHeight() - dest_rect.d_top;
    153         quad.position.d_bottom  = d_display_area.getHeight() - dest_rect.d_bottom;
    154         quad.position.offset(d_texelOffset);
    155 
    156         // convert quad co-ordinates for a -1 to 1 co-ordinate system.
    157         quad.position.d_left    /= (d_display_area.getWidth() * 0.5f);
    158         quad.position.d_right   /= (d_display_area.getWidth() * 0.5f);
    159         quad.position.d_top             /= (d_display_area.getHeight() * 0.5f);
    160         quad.position.d_bottom  /= (d_display_area.getHeight() * 0.5f);
    161         quad.position.offset(Point(-1.0f, -1.0f));
    162 
    163         quad.z                          = -1 + z;
    164         quad.texture            = ((OgreCEGUITexture*)tex)->getOgreTexture();
    165         quad.texPosition        = texture_rect;
    166 
    167         // covert colours for ogre, note that top / bottom are switched.
    168         quad.topLeftCol         = colourToOgre(colours.d_bottom_left);
    169         quad.topRightCol        = colourToOgre(colours.d_bottom_right);
    170         quad.bottomLeftCol      = colourToOgre(colours.d_top_left);
    171         quad.bottomRightCol     = colourToOgre(colours.d_top_right);
    172        
    173         // set quad split mode
    174         quad.splitMode = quad_split_mode;
    175 
    176         d_quadlist.insert(quad);
    177     }
     139        // if not queueing, render directly (as in, right now!). This is used for the mouse cursor.
     140        if (!d_queueing)
     141        {
     142                renderQuadDirect(dest_rect, z, tex, texture_rect, colours, quad_split_mode);
     143        }
     144        else
     145        {
     146                d_sorted = false;
     147                QuadInfo quad;
     148               
     149                // set quad position, flipping y co-ordinates, and applying appropriate texel origin offset
     150                quad.position.d_left    = dest_rect.d_left;
     151                quad.position.d_right   = dest_rect.d_right;
     152                quad.position.d_top             = d_display_area.getHeight() - dest_rect.d_top;
     153                quad.position.d_bottom  = d_display_area.getHeight() - dest_rect.d_bottom;
     154                quad.position.offset(d_texelOffset);
     155
     156                // convert quad co-ordinates for a -1 to 1 co-ordinate system.
     157                quad.position.d_left    /= (d_display_area.getWidth() * 0.5f);
     158                quad.position.d_right   /= (d_display_area.getWidth() * 0.5f);
     159                quad.position.d_top             /= (d_display_area.getHeight() * 0.5f);
     160                quad.position.d_bottom  /= (d_display_area.getHeight() * 0.5f);
     161                quad.position.offset(Point(-1.0f, -1.0f));
     162
     163                quad.z                          = -1 + z;
     164                quad.texture            = ((OgreCEGUITexture*)tex)->getOgreTexture();
     165                quad.texPosition        = texture_rect;
     166
     167                // covert colours for ogre, note that top / bottom are switched.
     168                quad.topLeftCol         = colourToOgre(colours.d_bottom_left);
     169                quad.topRightCol        = colourToOgre(colours.d_bottom_right);
     170                quad.bottomLeftCol      = colourToOgre(colours.d_top_left);
     171                quad.bottomRightCol     = colourToOgre(colours.d_top_right);
     172               
     173                // set quad split mode
     174                quad.splitMode = quad_split_mode;
     175
     176                d_quadlist.insert(quad);
     177        }
    178178}
    179179
     
    186186{
    187187    // Render if overlays enabled and the quad list is not empty
    188 
    189     // ORXONOX CHANGE: Even render when OverlaysEnabled is deactivated
    190     // The reason is that we don't want the HUD to be shown in the viewport of the
    191     // GUI (uses its own viewport to be able render on top of all viewports).
    192     // But since we don't use overlays in the GUI, it doesn't matter.
    193     // ORXONOX REVERT: Changes are not in place anymore, but might be in the future!
    194     if (d_render_sys->_getViewport()->getOverlaysEnabled() && !d_quadlist.empty())
    195     //if (!d_quadlist.empty())
    196     {
     188        if (d_render_sys->_getViewport()->getOverlaysEnabled() && !d_quadlist.empty())
     189        {
    197190        /// Quad list needs to be sorted and thus the vertex buffer rebuilt. If not, we can
    198191        /// reuse the vertex buffer resulting in a nice speed gain.
     
    319312        /// Render the buffer
    320313        d_bufferPos = 0;
    321         bool first = true;
     314                bool first = true;
    322315
    323316        // Iterate over each quad in the list and render it
     
    332325                const QuadInfo& quad = (*i);
    333326                if (d_currTexture != quad.texture)
    334                 {
     327                                {
    335328                    /// If it has a different texture, render this quad in next operation
    336                     /// also need to reset render states
    337                     first = true;
    338                     break;
    339                 }
     329                                        /// also need to reset render states
     330                                        first = true;
     331                            break;
     332                                }
    340333                d_bufferPos += VERTEX_PER_QUAD;
    341334            }
     
    343336            /// Set texture, and do the render
    344337            d_render_sys->_setTexture(0, true, d_currTexture);
    345             if (first)
    346             {
    347                 initRenderStates();
    348                 first = false;
    349             }
     338                        if (first)
     339                        {
     340                                initRenderStates();
     341                                first = false;
     342                        }
    350343            d_render_sys->_render(d_render_op);
    351344        }
    352345
    353     }
     346        }
    354347    /// Count frames to check if utilization of vertex buffer was below half the capacity for 500,000 frames
    355348    if(d_bufferPos < d_buffer->getNumVertices()/2)
     
    361354
    362355/*************************************************************************
    363     clear the queue
     356        clear the queue
    364357*************************************************************************/
    365358void OgreCEGUIRenderer::clearRenderList(void)
    366359{
    367     d_sorted = true;
    368     d_quadlist.clear();
    369 }
    370 
    371 
    372 /*************************************************************************
    373     create an empty texture
     360        d_sorted = true;
     361        d_quadlist.clear();
     362}
     363
     364
     365/*************************************************************************
     366        create an empty texture
    374367*************************************************************************/
    375368Texture* OgreCEGUIRenderer::createTexture(void)
    376369{
    377     OgreCEGUITexture* tex = new OgreCEGUITexture(this);
    378     d_texturelist.push_back(tex);
    379     return tex;
    380 }
    381 
    382 
    383 /*************************************************************************
    384     create a texture and load it with the specified file.
     370        OgreCEGUITexture* tex = new OgreCEGUITexture(this);
     371        d_texturelist.push_back(tex);
     372        return tex;
     373}
     374
     375
     376/*************************************************************************
     377        create a texture and load it with the specified file.
    385378*************************************************************************/
    386379Texture* OgreCEGUIRenderer::createTexture(const String& filename, const String& resourceGroup)
    387380{
    388     OgreCEGUITexture* tex = (OgreCEGUITexture*)createTexture();
    389     tex->loadFromFile(filename, resourceGroup);
    390 
    391     return tex;
    392 }
    393 
    394 
    395 /*************************************************************************
    396     create a texture and set it to the specified size
     381        OgreCEGUITexture* tex = (OgreCEGUITexture*)createTexture();
     382        tex->loadFromFile(filename, resourceGroup);
     383
     384        return tex;
     385}
     386
     387
     388/*************************************************************************
     389        create a texture and set it to the specified size
    397390*************************************************************************/
    398391Texture* OgreCEGUIRenderer::createTexture(float size)
    399392{
    400     OgreCEGUITexture* tex = (OgreCEGUITexture*)createTexture();
    401     tex->setOgreTextureSize((uint)size);
    402 
    403     return tex;
    404 }
    405 
    406 
    407 /*************************************************************************
    408     destroy the given texture
     393        OgreCEGUITexture* tex = (OgreCEGUITexture*)createTexture();
     394        tex->setOgreTextureSize((uint)size);
     395
     396        return tex;
     397}
     398
     399
     400/*************************************************************************
     401        destroy the given texture
    409402*************************************************************************/
    410403void OgreCEGUIRenderer::destroyTexture(Texture* texture)
    411404{
    412     if (texture != NULL)
    413     {
    414         OgreCEGUITexture* tex = (OgreCEGUITexture*)texture;
    415 
    416         d_texturelist.remove(tex);
    417         delete tex;
    418     }
    419 }
    420 
    421 
    422 /*************************************************************************
    423     destroy all textures still active
     405        if (texture != NULL)
     406        {
     407                OgreCEGUITexture* tex = (OgreCEGUITexture*)texture;
     408
     409                d_texturelist.remove(tex);
     410                delete tex;
     411        }
     412}
     413
     414
     415/*************************************************************************
     416        destroy all textures still active
    424417*************************************************************************/
    425418void OgreCEGUIRenderer::destroyAllTextures(void)
    426419{
    427     while (!d_texturelist.empty())
    428     {
    429         destroyTexture(*(d_texturelist.begin()));
    430     }
    431 }
    432 
    433 
    434 /*************************************************************************
    435     setup states etc   
     420        while (!d_texturelist.empty())
     421        {
     422                destroyTexture(*(d_texturelist.begin()));
     423        }
     424}
     425
     426
     427/*************************************************************************
     428        setup states etc       
    436429*************************************************************************/
    437430void OgreCEGUIRenderer::initRenderStates(void)
    438431{
    439     using namespace Ogre;
    440 
    441     // set-up matrices
    442     d_render_sys->_setWorldMatrix(Matrix4::IDENTITY);
    443     d_render_sys->_setViewMatrix(Matrix4::IDENTITY);
    444     d_render_sys->_setProjectionMatrix(Matrix4::IDENTITY);
    445 
    446     // initialise render settings
    447     d_render_sys->setLightingEnabled(false);
    448     d_render_sys->_setDepthBufferParams(false, false);
    449     d_render_sys->_setDepthBias(0, 0);
    450     d_render_sys->_setCullingMode(CULL_NONE);
    451     d_render_sys->_setFog(FOG_NONE);
    452     d_render_sys->_setColourBufferWriteEnabled(true, true, true, true);
    453     d_render_sys->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
    454     d_render_sys->unbindGpuProgram(GPT_VERTEX_PROGRAM);
    455     d_render_sys->setShadingType(SO_GOURAUD);
    456     d_render_sys->_setPolygonMode(PM_SOLID);
    457 
    458     // initialise texture settings
    459     d_render_sys->_setTextureCoordCalculation(0, TEXCALC_NONE);
    460     d_render_sys->_setTextureCoordSet(0, 0);
    461     d_render_sys->_setTextureUnitFiltering(0, FO_LINEAR, FO_LINEAR, FO_POINT);
    462     d_render_sys->_setTextureAddressingMode(0, d_uvwAddressMode);
    463     d_render_sys->_setTextureMatrix(0, Matrix4::IDENTITY);
    464     d_render_sys->_setAlphaRejectSettings(CMPF_ALWAYS_PASS, 0);
    465     d_render_sys->_setTextureBlendMode(0, d_colourBlendMode);
    466     d_render_sys->_setTextureBlendMode(0, d_alphaBlendMode);
    467     d_render_sys->_disableTextureUnitsFrom(1);
    468 
    469     // enable alpha blending
    470     d_render_sys->_setSceneBlending(SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA);
     432        using namespace Ogre;
     433
     434        // set-up matrices
     435        d_render_sys->_setWorldMatrix(Matrix4::IDENTITY);
     436        d_render_sys->_setViewMatrix(Matrix4::IDENTITY);
     437        d_render_sys->_setProjectionMatrix(Matrix4::IDENTITY);
     438
     439        // initialise render settings
     440        d_render_sys->setLightingEnabled(false);
     441        d_render_sys->_setDepthBufferParams(false, false);
     442        d_render_sys->_setDepthBias(0, 0);
     443        d_render_sys->_setCullingMode(CULL_NONE);
     444        d_render_sys->_setFog(FOG_NONE);
     445        d_render_sys->_setColourBufferWriteEnabled(true, true, true, true);
     446        d_render_sys->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
     447        d_render_sys->unbindGpuProgram(GPT_VERTEX_PROGRAM);
     448        d_render_sys->setShadingType(SO_GOURAUD);
     449        d_render_sys->_setPolygonMode(PM_SOLID);
     450
     451        // initialise texture settings
     452        d_render_sys->_setTextureCoordCalculation(0, TEXCALC_NONE);
     453        d_render_sys->_setTextureCoordSet(0, 0);
     454        d_render_sys->_setTextureUnitFiltering(0, FO_LINEAR, FO_LINEAR, FO_POINT);
     455        d_render_sys->_setTextureAddressingMode(0, d_uvwAddressMode);
     456        d_render_sys->_setTextureMatrix(0, Matrix4::IDENTITY);
     457        d_render_sys->_setAlphaRejectSettings(CMPF_ALWAYS_PASS, 0);
     458        d_render_sys->_setTextureBlendMode(0, d_colourBlendMode);
     459        d_render_sys->_setTextureBlendMode(0, d_alphaBlendMode);
     460        d_render_sys->_disableTextureUnitsFrom(1);
     461
     462        // enable alpha blending
     463        d_render_sys->_setSceneBlending(SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA);
    471464}
    472465
     
    474467 
    475468/*************************************************************************
    476     sort quads list according to texture       
     469        sort quads list according to texture   
    477470*************************************************************************/
    478471void OgreCEGUIRenderer::sortQuads(void)
    479472{
    480     if (!d_sorted)
    481     {
    482         d_sorted = true;
    483     }
     473        if (!d_sorted)
     474        {
     475                d_sorted = true;
     476        }
    484477
    485478}
     
    490483void OgreCEGUIRenderer::renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode)
    491484{
    492     // ORXONOX CHANGE: Even render when OverlaysEnabled is deactivated
    493     // The reason is that we don't want the HUD to be shown in the viewport of the
    494     // GUI (uses its own viewport to be able render on top of all viewports).
    495     // But since we don't use overlays in the GUI, it doesn't matter.
    496     // ORXONOX REVERT: Changes are not in place anymore, but might be in the future!
    497     if (d_render_sys->_getViewport()->getOverlaysEnabled())
    498     //if (true)
    499     {
    500         z = -1 + z;
    501 
    502         Rect final_rect;
    503 
    504         // set quad position, flipping y co-ordinates, and applying appropriate texel origin offset
    505         final_rect.d_left       = dest_rect.d_left;
    506         final_rect.d_right      = dest_rect.d_right;
    507         final_rect.d_top        = d_display_area.getHeight() - dest_rect.d_top;
    508         final_rect.d_bottom     = d_display_area.getHeight() - dest_rect.d_bottom;
    509         final_rect.offset(d_texelOffset);
    510 
    511         // convert quad co-ordinates for a -1 to 1 co-ordinate system.
    512         final_rect.d_left       /= (d_display_area.getWidth() * 0.5f);
    513         final_rect.d_right      /= (d_display_area.getWidth() * 0.5f);
    514         final_rect.d_top        /= (d_display_area.getHeight() * 0.5f);
    515         final_rect.d_bottom     /= (d_display_area.getHeight() * 0.5f);
    516         final_rect.offset(Point(-1.0f, -1.0f));
    517 
    518         // convert colours for ogre, note that top / bottom are switched.
     485        if (d_render_sys->_getViewport()->getOverlaysEnabled())
     486        {
     487                z = -1 + z;
     488
     489                Rect final_rect;
     490
     491                // set quad position, flipping y co-ordinates, and applying appropriate texel origin offset
     492                final_rect.d_left       = dest_rect.d_left;
     493                final_rect.d_right      = dest_rect.d_right;
     494                final_rect.d_top        = d_display_area.getHeight() - dest_rect.d_top;
     495                final_rect.d_bottom     = d_display_area.getHeight() - dest_rect.d_bottom;
     496                final_rect.offset(d_texelOffset);
     497
     498                // convert quad co-ordinates for a -1 to 1 co-ordinate system.
     499                final_rect.d_left       /= (d_display_area.getWidth() * 0.5f);
     500                final_rect.d_right      /= (d_display_area.getWidth() * 0.5f);
     501                final_rect.d_top        /= (d_display_area.getHeight() * 0.5f);
     502                final_rect.d_bottom     /= (d_display_area.getHeight() * 0.5f);
     503                final_rect.offset(Point(-1.0f, -1.0f));
     504
     505                // convert colours for ogre, note that top / bottom are switched.
    519506        uint32 topLeftCol       = colourToOgre(colours.d_bottom_left);
    520507        uint32 topRightCol      = colourToOgre(colours.d_bottom_right);
     
    522509        uint32 bottomRightCol= colourToOgre(colours.d_top_right);
    523510
    524         QuadVertex*     buffmem = (QuadVertex*)d_direct_buffer->lock(Ogre::HardwareVertexBuffer::HBL_DISCARD);
    525 
    526         // setup Vertex 1...
    527         buffmem->x      = final_rect.d_left;
    528         buffmem->y      = final_rect. d_bottom;
    529         buffmem->z      = z;
    530         buffmem->diffuse = topLeftCol;
    531         buffmem->tu1    = texture_rect.d_left;
    532         buffmem->tv1    = texture_rect.d_bottom;
    533         ++buffmem;
    534 
    535         // setup Vertex 2...
    536        
    537         // top-left to bottom-right diagonal
    538         if (quad_split_mode == TopLeftToBottomRight)
    539         {
    540             buffmem->x  = final_rect.d_right;
    541             buffmem->y = final_rect.d_bottom;
    542             buffmem->z  = z;
    543             buffmem->diffuse = topRightCol;
    544             buffmem->tu1        = texture_rect.d_right;
    545             buffmem->tv1        = texture_rect.d_bottom;
    546             ++buffmem;
    547         }
    548         // bottom-left to top-right diagonal
    549         else
    550         {
    551             buffmem->x  = final_rect.d_right;
    552             buffmem->y = final_rect.d_top;
    553             buffmem->z  = z;
    554             buffmem->diffuse = bottomRightCol;
    555             buffmem->tu1        = texture_rect.d_right;
    556             buffmem->tv1        = texture_rect.d_top;
    557             ++buffmem;
    558         }
    559 
    560         // setup Vertex 3...
    561         buffmem->x      = final_rect.d_left;
    562         buffmem->y      = final_rect.d_top;
    563         buffmem->z      = z;
    564         buffmem->diffuse = bottomLeftCol;
    565         buffmem->tu1    = texture_rect.d_left;
    566         buffmem->tv1    = texture_rect.d_top;
    567         ++buffmem;
    568 
    569         // setup Vertex 4...
    570         buffmem->x      = final_rect.d_right;
    571         buffmem->y      = final_rect.d_bottom;
    572         buffmem->z      = z;
    573         buffmem->diffuse = topRightCol;
    574         buffmem->tu1    = texture_rect.d_right;
    575         buffmem->tv1    = texture_rect.d_bottom;
    576         ++buffmem;
    577 
    578         // setup Vertex 5...
    579         buffmem->x      = final_rect.d_right;
    580         buffmem->y      = final_rect.d_top;
    581         buffmem->z      = z;
    582         buffmem->diffuse = bottomRightCol;
    583         buffmem->tu1    = texture_rect.d_right;
    584         buffmem->tv1    = texture_rect.d_top;
    585         ++buffmem;
    586 
    587         // setup Vertex 6...
    588        
    589         // top-left to bottom-right diagonal
    590         if (quad_split_mode == TopLeftToBottomRight)
    591         {
    592             buffmem->x  = final_rect.d_left;
    593             buffmem->y = final_rect.d_top;
    594             buffmem->z  = z;
    595             buffmem->diffuse = bottomLeftCol;
    596             buffmem->tu1        = texture_rect.d_left;
    597             buffmem->tv1        = texture_rect.d_top;
    598         }
    599         // bottom-left to top-right diagonal
    600         else
    601         {
    602             buffmem->x  = final_rect.d_left;
    603             buffmem->y = final_rect.d_bottom;
    604             buffmem->z  = z;
    605             buffmem->diffuse = topLeftCol;
    606             buffmem->tu1        = texture_rect.d_left;
    607             buffmem->tv1        = texture_rect.d_bottom;
    608         }
    609 
    610         d_direct_buffer->unlock();
     511                QuadVertex*     buffmem = (QuadVertex*)d_direct_buffer->lock(Ogre::HardwareVertexBuffer::HBL_DISCARD);
     512
     513                // setup Vertex 1...
     514                buffmem->x      = final_rect.d_left;
     515                buffmem->y      = final_rect. d_bottom;
     516                buffmem->z      = z;
     517                buffmem->diffuse = topLeftCol;
     518                buffmem->tu1    = texture_rect.d_left;
     519                buffmem->tv1    = texture_rect.d_bottom;
     520                ++buffmem;
     521
     522                // setup Vertex 2...
     523               
     524                // top-left to bottom-right diagonal
     525                if (quad_split_mode == TopLeftToBottomRight)
     526                {
     527                        buffmem->x      = final_rect.d_right;
     528                        buffmem->y = final_rect.d_bottom;
     529                        buffmem->z      = z;
     530                        buffmem->diffuse = topRightCol;
     531                        buffmem->tu1    = texture_rect.d_right;
     532                        buffmem->tv1    = texture_rect.d_bottom;
     533                        ++buffmem;
     534                }
     535                // bottom-left to top-right diagonal
     536                else
     537                {
     538                        buffmem->x      = final_rect.d_right;
     539                        buffmem->y = final_rect.d_top;
     540                        buffmem->z      = z;
     541                        buffmem->diffuse = bottomRightCol;
     542                        buffmem->tu1    = texture_rect.d_right;
     543                        buffmem->tv1    = texture_rect.d_top;
     544                        ++buffmem;
     545                }
     546
     547                // setup Vertex 3...
     548                buffmem->x      = final_rect.d_left;
     549                buffmem->y      = final_rect.d_top;
     550                buffmem->z      = z;
     551                buffmem->diffuse = bottomLeftCol;
     552                buffmem->tu1    = texture_rect.d_left;
     553                buffmem->tv1    = texture_rect.d_top;
     554                ++buffmem;
     555
     556                // setup Vertex 4...
     557                buffmem->x      = final_rect.d_right;
     558                buffmem->y      = final_rect.d_bottom;
     559                buffmem->z      = z;
     560                buffmem->diffuse = topRightCol;
     561                buffmem->tu1    = texture_rect.d_right;
     562                buffmem->tv1    = texture_rect.d_bottom;
     563                ++buffmem;
     564
     565                // setup Vertex 5...
     566                buffmem->x      = final_rect.d_right;
     567                buffmem->y      = final_rect.d_top;
     568                buffmem->z      = z;
     569                buffmem->diffuse = bottomRightCol;
     570                buffmem->tu1    = texture_rect.d_right;
     571                buffmem->tv1    = texture_rect.d_top;
     572                ++buffmem;
     573
     574                // setup Vertex 6...
     575               
     576                // top-left to bottom-right diagonal
     577                if (quad_split_mode == TopLeftToBottomRight)
     578                {
     579                        buffmem->x      = final_rect.d_left;
     580                        buffmem->y = final_rect.d_top;
     581                        buffmem->z      = z;
     582                        buffmem->diffuse = bottomLeftCol;
     583                        buffmem->tu1    = texture_rect.d_left;
     584                        buffmem->tv1    = texture_rect.d_top;
     585                }
     586                // bottom-left to top-right diagonal
     587                else
     588                {
     589                        buffmem->x      = final_rect.d_left;
     590                        buffmem->y = final_rect.d_bottom;
     591                        buffmem->z      = z;
     592                        buffmem->diffuse = topLeftCol;
     593                        buffmem->tu1    = texture_rect.d_left;
     594                        buffmem->tv1    = texture_rect.d_bottom;
     595                }
     596
     597                d_direct_buffer->unlock();
    611598
    612599        //
    613         // perform rendering...
    614         //
    615         d_render_sys->_setTexture(0, true, ((OgreCEGUITexture*)tex)->getOgreTexture()->getName());
    616         initRenderStates();
    617         d_direct_render_op.vertexData->vertexCount = VERTEX_PER_QUAD;
    618         d_render_sys->_render(d_direct_render_op);
    619     }
    620 
    621 }
    622 
    623 /*************************************************************************
    624     convert ARGB colour value to whatever the Ogre render system is
    625     expecting. 
     600                // perform rendering...
     601                //
     602                d_render_sys->_setTexture(0, true, ((OgreCEGUITexture*)tex)->getOgreTexture()->getName());
     603                initRenderStates();
     604                d_direct_render_op.vertexData->vertexCount = VERTEX_PER_QUAD;
     605                d_render_sys->_render(d_direct_render_op);
     606        }
     607
     608}
     609
     610/*************************************************************************
     611        convert ARGB colour value to whatever the Ogre render system is
     612        expecting.     
    626613*************************************************************************/
    627614uint32 OgreCEGUIRenderer::colourToOgre(const colour& col) const
    628615{
    629     Ogre::ColourValue cv(col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha());
     616        Ogre::ColourValue cv(col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha());
    630617
    631618    uint32 final;
    632     d_render_sys->convertColourValue(cv, &final);
    633 
    634     return final;
    635 }
    636 
    637 
    638 /*************************************************************************
    639     Set the scene manager to be used for rendering the GUI.     
     619        d_render_sys->convertColourValue(cv, &final);
     620
     621        return final;
     622}
     623
     624
     625/*************************************************************************
     626        Set the scene manager to be used for rendering the GUI.
    640627*************************************************************************/
    641628void OgreCEGUIRenderer::setTargetSceneManager(Ogre::SceneManager* scene_manager)
    642629{
    643     // unhook from current scene manager.
    644     if (d_sceneMngr != NULL)
    645     {
    646         d_sceneMngr->removeRenderQueueListener(d_ourlistener);
    647         d_sceneMngr = NULL;
    648     }
    649 
    650     // hook new scene manager if that is not NULL
    651     if (scene_manager != NULL)
    652     {
    653         d_sceneMngr = scene_manager;
    654         d_sceneMngr->addRenderQueueListener(d_ourlistener);
    655     }
    656 
    657 }
    658 
    659 
    660 /*************************************************************************
    661     Set the target render queue for GUI rendering.     
     630        // unhook from current scene manager.
     631        if (d_sceneMngr != NULL)
     632        {
     633                d_sceneMngr->removeRenderQueueListener(d_ourlistener);
     634                d_sceneMngr = NULL;
     635        }
     636
     637        // hook new scene manager if that is not NULL
     638        if (scene_manager != NULL)
     639        {
     640                d_sceneMngr = scene_manager;
     641                d_sceneMngr->addRenderQueueListener(d_ourlistener);
     642        }
     643
     644}
     645
     646
     647/*************************************************************************
     648        Set the target render queue for GUI rendering. 
    662649*************************************************************************/
    663650void OgreCEGUIRenderer::setTargetRenderQueue(Ogre::uint8 queue_id, bool post_queue)
    664651{
    665     d_queue_id          = queue_id;
    666     d_post_queue        = post_queue;
    667 
    668     if (d_ourlistener != NULL)
    669     {
    670         d_ourlistener->setTargetRenderQueue(queue_id);
    671         d_ourlistener->setPostRenderQueue(post_queue);
    672     }
    673 
    674 }
    675 
    676 
    677 /*************************************************************************
    678     perform main work of the constructor
     652        d_queue_id              = queue_id;
     653        d_post_queue    = post_queue;
     654
     655        if (d_ourlistener != NULL)
     656        {
     657                d_ourlistener->setTargetRenderQueue(queue_id);
     658                d_ourlistener->setPostRenderQueue(post_queue);
     659        }
     660
     661}
     662
     663
     664/*************************************************************************
     665        perform main work of the constructor
    679666*************************************************************************/
    680667void OgreCEGUIRenderer::constructor_impl(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads)
    681668{
    682     using namespace Ogre;
    683 
    684     // initialise the renderer fields
    685     d_queueing          = true;
    686     d_queue_id          = queue_id;
    687     d_currTexture.isNull();
    688     d_post_queue        = post_queue;
    689     d_sceneMngr         = NULL;
    690     d_bufferPos         = 0;
    691     d_sorted            = true;
    692     d_ogre_root         = Root::getSingletonPtr();
    693     d_render_sys        = d_ogre_root->getRenderSystem();
     669        using namespace Ogre;
     670
     671        // initialise the renderer fields
     672        d_queueing              = true;
     673        d_queue_id              = queue_id;
     674        d_currTexture.isNull();
     675        d_post_queue    = post_queue;
     676        d_sceneMngr             = NULL;
     677        d_bufferPos             = 0;
     678        d_sorted                = true;
     679        d_ogre_root             = Root::getSingletonPtr();
     680        d_render_sys    = d_ogre_root->getRenderSystem();
    694681    // set ID string
    695682    d_identifierString = "CEGUI::OgreRenderer - Official Ogre based renderer module for CEGUI";
    696683
    697     // Create and initialise the Ogre specific parts required for use in rendering later.
     684        // Create and initialise the Ogre specific parts required for use in rendering later.
    698685    // Main GUI
    699686    createQuadRenderOp(d_render_op, d_buffer, VERTEXBUFFER_INITIAL_CAPACITY);
     
    703690    createQuadRenderOp(d_direct_render_op, d_direct_buffer, VERTEX_PER_QUAD);
    704691
    705     // Discover display settings and setup d_display_area
    706     d_display_area.d_left       = 0;
    707     d_display_area.d_top        = 0;
    708     d_display_area.d_right      = window->getWidth();
    709     d_display_area.d_bottom     = window->getHeight();
    710 
    711     // initialise required texel offset
    712     d_texelOffset = Point((float)d_render_sys->getHorizontalTexelOffset(), -(float)d_render_sys->getVerticalTexelOffset());
    713 
    714     // create listener which will handler the rendering side of things for us.
    715     d_ourlistener = new CEGUIRQListener(this, queue_id, post_queue);
    716 
    717     // Initialise blending modes to be used.
    718     d_colourBlendMode.blendType = Ogre::LBT_COLOUR;
    719     d_colourBlendMode.source1   = Ogre::LBS_TEXTURE;
    720     d_colourBlendMode.source2   = Ogre::LBS_DIFFUSE;
    721     d_colourBlendMode.operation = Ogre::LBX_MODULATE;
    722 
    723     d_alphaBlendMode.blendType  = Ogre::LBT_ALPHA;
    724     d_alphaBlendMode.source1    = Ogre::LBS_TEXTURE;
    725     d_alphaBlendMode.source2    = Ogre::LBS_DIFFUSE;
    726     d_alphaBlendMode.operation  = Ogre::LBX_MODULATE;
    727 
    728     d_uvwAddressMode.u = Ogre::TextureUnitState::TAM_CLAMP;
    729     d_uvwAddressMode.v = Ogre::TextureUnitState::TAM_CLAMP;
    730     d_uvwAddressMode.w = Ogre::TextureUnitState::TAM_CLAMP;
    731 }
    732 
    733 
    734 /*************************************************************************
    735     Create a texture from an existing Ogre::TexturePtr object   
     692        // Discover display settings and setup d_display_area
     693        d_display_area.d_left   = 0;
     694        d_display_area.d_top    = 0;
     695        d_display_area.d_right  = window->getWidth();
     696        d_display_area.d_bottom = window->getHeight();
     697
     698        // initialise required texel offset
     699        d_texelOffset = Point((float)d_render_sys->getHorizontalTexelOffset(), -(float)d_render_sys->getVerticalTexelOffset());
     700
     701        // create listener which will handler the rendering side of things for us.
     702        d_ourlistener = new CEGUIRQListener(this, queue_id, post_queue);
     703
     704        // Initialise blending modes to be used.
     705        d_colourBlendMode.blendType     = Ogre::LBT_COLOUR;
     706        d_colourBlendMode.source1       = Ogre::LBS_TEXTURE;
     707        d_colourBlendMode.source2       = Ogre::LBS_DIFFUSE;
     708        d_colourBlendMode.operation     = Ogre::LBX_MODULATE;
     709
     710        d_alphaBlendMode.blendType      = Ogre::LBT_ALPHA;
     711        d_alphaBlendMode.source1        = Ogre::LBS_TEXTURE;
     712        d_alphaBlendMode.source2        = Ogre::LBS_DIFFUSE;
     713        d_alphaBlendMode.operation      = Ogre::LBX_MODULATE;
     714
     715        d_uvwAddressMode.u = Ogre::TextureUnitState::TAM_CLAMP;
     716        d_uvwAddressMode.v = Ogre::TextureUnitState::TAM_CLAMP;
     717        d_uvwAddressMode.w = Ogre::TextureUnitState::TAM_CLAMP;
     718}
     719
     720
     721/*************************************************************************
     722        Create a texture from an existing Ogre::TexturePtr object       
    736723*************************************************************************/
    737724Texture* OgreCEGUIRenderer::createTexture(Ogre::TexturePtr& texture)
    738725{
    739     OgreCEGUITexture* t = (OgreCEGUITexture*)createTexture();
    740 
    741     if (!texture.isNull())
    742     {
    743         t->setOgreTexture(texture);
    744     }
    745 
    746     return t;
    747 
    748 }
    749 
    750 /*************************************************************************
    751     Create a resource provider object
     726        OgreCEGUITexture* t = (OgreCEGUITexture*)createTexture();
     727
     728        if (!texture.isNull())
     729        {
     730                t->setOgreTexture(texture);
     731        }
     732
     733        return t;
     734
     735}
     736
     737/*************************************************************************
     738        Create a resource provider object
    752739*************************************************************************/
    753740ResourceProvider* OgreCEGUIRenderer::createResourceProvider(void)
     
    762749void OgreCEGUIRenderer::setDisplaySize(const Size& sz)
    763750{
    764     if (d_display_area.getSize() != sz)
    765     {
    766         d_display_area.setSize(sz);
    767 
    768         EventArgs args;
    769         fireEvent(EventDisplaySizeChanged, args, EventNamespace);
    770     }
    771 
    772 }
    773 
    774 /*************************************************************************
    775     Callback from Ogre invoked before other stuff in our target queue
    776     is rendered
     751        if (d_display_area.getSize() != sz)
     752        {
     753                d_display_area.setSize(sz);
     754
     755                EventArgs args;
     756                fireEvent(EventDisplaySizeChanged, args, EventNamespace);
     757        }
     758
     759}
     760
     761/*************************************************************************
     762        Callback from Ogre invoked before other stuff in our target queue
     763        is rendered
    777764*************************************************************************/
    778765void CEGUIRQListener::renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation,
    779                                         bool& skipThisQueue)
    780 {
    781     if ((!d_post_queue) && (d_queue_id == id))
    782     {
    783         CEGUI::System::getSingleton().renderGUI();
    784     }
     766                                                                                bool& skipThisQueue)
     767{
     768        if ((!d_post_queue) && (d_queue_id == id))
     769        {
     770                CEGUI::System::getSingleton().renderGUI();
     771        }
    785772
    786773}
     
    793780void CEGUIRQListener::renderQueueEnded(Ogre::uint8 id, const Ogre::String& invocation, bool& repeatThisQueue)
    794781{
    795     if ((d_post_queue) && (d_queue_id == id))
    796     {
    797         CEGUI::System::getSingleton().renderGUI();
    798     }
     782        if ((d_post_queue) && (d_queue_id == id))
     783        {
     784                CEGUI::System::getSingleton().renderGUI();
     785        }
    799786
    800787}
  • code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUIRenderer.h

    r2569 r2602  
    11/************************************************************************
    2     filename:   OgreCEGUIRenderer.h
    3     created:    11/5/2004
    4     author:             Paul D Turner
    5 
    6     purpose:    Interface for main Ogre GUI renderer class
     2        filename:       OgreCEGUIRenderer.h
     3        created:        11/5/2004
     4        author:         Paul D Turner
     5
     6        purpose:        Interface for main Ogre GUI renderer class
    77*************************************************************************/
    88/*************************************************************************
     
    2525*************************************************************************/
    2626/*************************************************************************
    27     This file contains code that is specific to Ogre (http://www.ogre3d.org)
     27        This file contains code that is specific to Ogre (http://www.ogre3d.org)
    2828*************************************************************************/
    2929#ifndef _OgreCEGUIRenderer_h_
     
    5959{
    6060/*************************************************************************
    61     Forward refs
     61        Forward refs
    6262*************************************************************************/
    6363class OgreCEGUITexture;
     
    6767/*!
    6868\brief
    69     RenderQueueListener based class used to hook into the ogre rendering system
     69        RenderQueueListener based class used to hook into the ogre rendering system
    7070*/
    7171class _OgrePrivate CEGUIRQListener : public Ogre::RenderQueueListener
    7272{
    7373public:
    74     CEGUIRQListener(OgreCEGUIRenderer* renderer, Ogre::uint8 queue_id, bool post_queue)
    75     {
    76         d_renderer              = renderer;
    77         d_queue_id              = queue_id;
    78         d_post_queue    = post_queue;
    79     }
    80 
    81     virtual ~CEGUIRQListener() {}
    82 
    83     virtual void        renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, bool& skipThisQueue);
    84     virtual void        renderQueueEnded(Ogre::uint8 id, const Ogre::String& invocation, bool& repeatThisQueue);
    85 
    86     // methods for adjusting target queue settings
    87     void        setTargetRenderQueue(Ogre::uint8 queue_id)              {d_queue_id = queue_id;}
    88     void        setPostRenderQueue(bool post_queue)             {d_post_queue = post_queue;}
     74        CEGUIRQListener(OgreCEGUIRenderer* renderer, Ogre::uint8 queue_id, bool post_queue)
     75        {
     76                d_renderer              = renderer;
     77                d_queue_id              = queue_id;
     78                d_post_queue    = post_queue;
     79        }
     80
     81        virtual ~CEGUIRQListener() {}
     82
     83        virtual void    renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, bool& skipThisQueue);
     84        virtual void    renderQueueEnded(Ogre::uint8 id, const Ogre::String& invocation, bool& repeatThisQueue);
     85
     86        // methods for adjusting target queue settings
     87        void    setTargetRenderQueue(Ogre::uint8 queue_id)              {d_queue_id = queue_id;}
     88        void    setPostRenderQueue(bool post_queue)             {d_post_queue = post_queue;}
    8989
    9090private:
    91     /*************************************************************************
    92         Implementation Data
    93     *************************************************************************/
    94     OgreCEGUIRenderer*                          d_renderer;             //!< CEGUI renderer object for Ogre.
    95     Ogre::uint8 d_queue_id;             //!< ID of the queue that we are hooked into
    96     bool                                                d_post_queue;   //!< true if we render after everything else in our queue.
     91        /*************************************************************************
     92                Implementation Data
     93        *************************************************************************/
     94        OgreCEGUIRenderer*                              d_renderer;             //!< CEGUI renderer object for Ogre.
     95        Ogre::uint8     d_queue_id;             //!< ID of the queue that we are hooked into
     96        bool                                            d_post_queue;   //!< true if we render after everything else in our queue.
    9797};
    9898
     
    100100/*!
    101101\brief
    102     Renderer class to interface with Ogre engine.
     102        Renderer class to interface with Ogre engine.
    103103*/
    104104class OGRE_GUIRENDERER_API OgreCEGUIRenderer : public Renderer
    105105{
    106106public:
    107     /*!
    108     \brief
    109         Constructor for renderer class that uses Ogre for rendering. Note that if
    110         you use this option you must call setTargetSceneManager before rendering.
    111 
    112     \param window
    113         Pointer to an Ogre::RenderWindow object.
    114 
    115     \param queue_id
    116         Ogre::uint8 value that specifies where the GUI should appear in the ogre rendering output.
    117 
    118     \param post_queue
    119         set to true to have GUI rendered after render queue \a queue_id, or false to have the GUI rendered before render queue
    120         \a queue_id.
    121 
    122     \param max_quads
    123         Obsolete.  Set to 0.
    124 
    125     */
    126     OgreCEGUIRenderer(Ogre::RenderWindow* window,
    127         Ogre::uint8 queue_id = Ogre::RENDER_QUEUE_OVERLAY,
    128         bool post_queue = false, uint max_quads = 0);
    129 
    130 
    131     /*!
    132     \brief
    133         Constructor for renderer class that uses Ogre for rendering.
    134 
    135     \param window
    136         Pointer to an Ogre::RenderWindow object.
    137 
    138     \param queue_id
    139         Ogre::uint8 value that specifies where the GUI should appear in the ogre rendering output.
    140 
    141     \param post_queue
    142         set to true to have GUI rendered after render queue \a queue_id, or false to have the GUI rendered before render queue
    143         \a queue_id.
    144 
    145     \param max_quads
    146         Obsolete.  Set to 0.
    147 
    148     \param scene_manager
    149         Pointer to an Ogre::SceneManager object that is to be used for GUI rendering.
    150     */
    151     OgreCEGUIRenderer(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads, Ogre::SceneManager* scene_manager);
    152 
    153 
    154     /*!
    155     \brief
    156         Destructor for Ogre renderer.
    157     */
    158     virtual ~OgreCEGUIRenderer(void);
    159 
    160 
    161 
    162     // add's a quad to the list to be rendered
    163     virtual     void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
    164 
    165     // perform final rendering for all queued renderable quads.
    166     virtual     void    doRender(void);
    167 
    168     // clear the queue
    169     virtual     void    clearRenderList(void);
    170 
    171 
    172     /*!
    173     \brief
    174         Enable or disable the queueing of quads from this point on.
    175 
    176         This only affects queueing.  If queueing is turned off, any calls to addQuad will cause the quad to be rendered directly.  Note that
    177         disabling queueing will not cause currently queued quads to be rendered, nor is the queue cleared - at any time the queue can still
    178         be drawn by calling doRender, and the list can be cleared by calling clearRenderList.  Re-enabling the queue causes subsequent quads
    179         to be added as if queueing had never been disabled.
    180 
    181     \param setting
    182         true to enable queueing, or false to disable queueing (see notes above).
    183 
    184     \return
    185         Nothing
    186     */
    187     virtual void        setQueueingEnabled(bool setting)                {d_queueing = setting;}
    188 
    189 
    190     // create an empty texture
    191     virtual     Texture*        createTexture(void);
    192 
    193     // create a texture and load it with the specified file.
    194     virtual     Texture*        createTexture(const String& filename, const String& resourceGroup = "General");
    195 
    196     // create a texture and set it to the specified size
    197     virtual     Texture*        createTexture(float size);
     107        /*!
     108        \brief
     109                Constructor for renderer class that uses Ogre for rendering. Note that if
     110                you use this option you must call setTargetSceneManager before rendering.
     111
     112        \param window
     113                Pointer to an Ogre::RenderWindow object.
     114
     115        \param queue_id
     116                Ogre::uint8 value that specifies where the GUI should appear in the ogre rendering output.
     117
     118        \param post_queue
     119                set to true to have GUI rendered after render queue \a queue_id, or false to have the GUI rendered before render queue
     120                \a queue_id.
     121
     122        \param max_quads
     123                Obsolete.  Set to 0.
     124
     125        */
     126        OgreCEGUIRenderer(Ogre::RenderWindow* window,
     127                Ogre::uint8 queue_id = Ogre::RENDER_QUEUE_OVERLAY,
     128                bool post_queue = false, uint max_quads = 0);
     129
     130
     131        /*!
     132        \brief
     133                Constructor for renderer class that uses Ogre for rendering.
     134
     135        \param window
     136                Pointer to an Ogre::RenderWindow object.
     137
     138        \param queue_id
     139                Ogre::uint8 value that specifies where the GUI should appear in the ogre rendering output.
     140
     141        \param post_queue
     142                set to true to have GUI rendered after render queue \a queue_id, or false to have the GUI rendered before render queue
     143                \a queue_id.
     144
     145        \param max_quads
     146                Obsolete.  Set to 0.
     147
     148        \param scene_manager
     149                Pointer to an Ogre::SceneManager object that is to be used for GUI rendering.
     150        */
     151        OgreCEGUIRenderer(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads, Ogre::SceneManager* scene_manager);
     152
     153
     154        /*!
     155        \brief
     156                Destructor for Ogre renderer.
     157        */
     158        virtual ~OgreCEGUIRenderer(void);
     159
     160
     161
     162        // add's a quad to the list to be rendered
     163        virtual void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
     164
     165        // perform final rendering for all queued renderable quads.
     166        virtual void    doRender(void);
     167
     168        // clear the queue
     169        virtual void    clearRenderList(void);
     170
     171
     172        /*!
     173        \brief
     174                Enable or disable the queueing of quads from this point on.
     175
     176                This only affects queueing.  If queueing is turned off, any calls to addQuad will cause the quad to be rendered directly.  Note that
     177                disabling queueing will not cause currently queued quads to be rendered, nor is the queue cleared - at any time the queue can still
     178                be drawn by calling doRender, and the list can be cleared by calling clearRenderList.  Re-enabling the queue causes subsequent quads
     179                to be added as if queueing had never been disabled.
     180
     181        \param setting
     182                true to enable queueing, or false to disable queueing (see notes above).
     183
     184        \return
     185                Nothing
     186        */
     187        virtual void    setQueueingEnabled(bool setting)                {d_queueing = setting;}
     188
     189
     190        // create an empty texture
     191        virtual Texture*        createTexture(void);
     192
     193        // create a texture and load it with the specified file.
     194        virtual Texture*        createTexture(const String& filename, const String& resourceGroup = "General");
     195
     196        // create a texture and set it to the specified size
     197        virtual Texture*        createTexture(float size);
    198198
    199199    // create an OGRE resource provider.
    200200    virtual ResourceProvider* createResourceProvider(void);
    201201
    202     // destroy the given texture
    203     virtual     void            destroyTexture(Texture* texture);
    204 
    205     // destroy all textures still active
    206     virtual void                destroyAllTextures(void);
    207 
    208 
    209     /*!
    210     \brief
    211         Return whether queueing is enabled.
    212 
    213     \return
    214         true if queueing is enabled, false if queueing is disabled.
    215     */
    216     virtual bool        isQueueingEnabled(void) const   {return d_queueing;}
    217 
    218 
    219     /*!
    220     \brief
    221     Return the current width of the display in pixels
    222 
    223     \return
    224     float value equal to the current width of the display in pixels.
    225     */
    226     virtual float       getWidth(void) const            {return d_display_area.getWidth();}
    227 
    228 
    229     /*!
    230     \brief
    231     Return the current height of the display in pixels
    232 
    233     \return
    234     float value equal to the current height of the display in pixels.
    235     */
    236     virtual float       getHeight(void) const           {return d_display_area.getHeight();}
    237 
    238 
    239     /*!
    240     \brief
    241     Return the size of the display in pixels
    242 
    243     \return
    244     Size object describing the dimensions of the current display.
    245     */
    246     virtual Size        getSize(void) const                     {return d_display_area.getSize();}
    247 
    248 
    249     /*!
    250     \brief
    251     Return a Rect describing the screen
    252 
    253     \return
    254     A Rect object that describes the screen area.  Typically, the top-left values are always 0, and the size of the area described is
    255     equal to the screen resolution.
    256     */
    257     virtual Rect        getRect(void) const                     {return d_display_area;}
    258 
    259 
    260     /*!
    261     \brief
    262         Return the maximum texture size available
    263 
    264     \return
    265         Size of the maximum supported texture in pixels (textures are always assumed to be square)
    266     */
    267     virtual     uint    getMaxTextureSize(void) const           {return 2048;}          // TODO: Change to proper value
    268 
    269 
    270     /*!
    271     \brief
    272         Return the horizontal display resolution dpi
    273 
    274     \return
    275         horizontal resolution of the display in dpi.
    276     */
    277     virtual     uint    getHorzScreenDPI(void) const    {return 96;}
    278 
    279 
    280     /*!
    281     \brief
    282         Return the vertical display resolution dpi
    283 
    284     \return
    285         vertical resolution of the display in dpi.
    286     */
    287     virtual     uint    getVertScreenDPI(void) const    {return 96;}
    288 
    289 
    290     /*!
    291     \brief
    292         Set the scene manager to be used for rendering the GUI.
    293 
    294         The GUI system will be unhooked from the current scene manager and attached to what ever
    295         is specified here.
    296 
    297     \param scene_manager
    298         Pointer to an Ogre::SceneManager object that is the new target Ogre::SceneManager to be
    299         used for GUI rendering.
    300 
    301     \return
    302         Nothing.
    303     */
    304     void        setTargetSceneManager(Ogre::SceneManager* scene_manager);
    305 
    306 
    307     /*!
    308     \brief
    309         Set the target render queue for GUI rendering.
    310 
    311     \param queue_id
    312         Ogre::uint8 value specifying the render queue that the GUI system should attach to.
    313 
    314     \param post_queue
    315         - true to specify that the GUI should render after everything else in render queue \a queue_id.
    316         - false to specify the GUI should render before everything else in render queue \a queue_id.
    317 
    318     \return
    319         Nothing.
    320     */
    321     void        setTargetRenderQueue(Ogre::uint8 queue_id, bool post_queue);
    322 
    323 
    324     /*!
    325     \brief
    326         Create a texture from an existing Ogre::TexturePtr object.
    327 
    328     \note
    329         If you want to use an Ogre::RenderTexture (for putting rendered output onto Gui elements or other
    330         advanced techniques), you can get the Ogre::TexturePtr to be used by calling Ogre::TextureManager::getByName()
    331         passing the name returned from Ogre::RenderTexture::getName() (and casting the result as necessary).
    332 
    333     \param texture
    334         pointer to an Ogre::TexturePtr object to be used as the basis for the new CEGUI::Texture
    335 
    336     \return
    337         Pointer to the newly created CEGUI::TexturePtr object.
    338     */
    339     Texture*    createTexture(Ogre::TexturePtr& texture);
    340 
    341 
    342     /*!
    343     \brief
    344     Set the size of the display in pixels.
    345 
    346     You do not have to call this method under normal operation as the system
    347     will automatically extract the size from the current view port.
    348 
    349     \note
    350     This method will cause the EventDisplaySizeChanged event to fire if the
    351     display size has changed.
    352 
    353     \param sz
    354     Size object describing the size of the display.
    355 
    356     \return
    357     Nothing.
    358     */
    359     void        setDisplaySize(const Size& sz);
     202        // destroy the given texture
     203        virtual void            destroyTexture(Texture* texture);
     204
     205        // destroy all textures still active
     206        virtual void            destroyAllTextures(void);
     207
     208
     209        /*!
     210        \brief
     211                Return whether queueing is enabled.
     212
     213        \return
     214                true if queueing is enabled, false if queueing is disabled.
     215        */
     216        virtual bool    isQueueingEnabled(void) const   {return d_queueing;}
     217
     218
     219        /*!
     220        \brief
     221        Return the current width of the display in pixels
     222
     223        \return
     224        float value equal to the current width of the display in pixels.
     225        */
     226        virtual float   getWidth(void) const            {return d_display_area.getWidth();}
     227
     228
     229        /*!
     230        \brief
     231        Return the current height of the display in pixels
     232
     233        \return
     234        float value equal to the current height of the display in pixels.
     235        */
     236        virtual float   getHeight(void) const           {return d_display_area.getHeight();}
     237
     238
     239        /*!
     240        \brief
     241        Return the size of the display in pixels
     242
     243        \return
     244        Size object describing the dimensions of the current display.
     245        */
     246        virtual Size    getSize(void) const                     {return d_display_area.getSize();}
     247
     248
     249        /*!
     250        \brief
     251        Return a Rect describing the screen
     252
     253        \return
     254        A Rect object that describes the screen area.  Typically, the top-left values are always 0, and the size of the area described is
     255        equal to the screen resolution.
     256        */
     257        virtual Rect    getRect(void) const                     {return d_display_area;}
     258
     259
     260        /*!
     261        \brief
     262                Return the maximum texture size available
     263
     264        \return
     265                Size of the maximum supported texture in pixels (textures are always assumed to be square)
     266        */
     267        virtual uint    getMaxTextureSize(void) const           {return 2048;}          // TODO: Change to proper value
     268
     269
     270        /*!
     271        \brief
     272                Return the horizontal display resolution dpi
     273
     274        \return
     275                horizontal resolution of the display in dpi.
     276        */
     277        virtual uint    getHorzScreenDPI(void) const    {return 96;}
     278
     279
     280        /*!
     281        \brief
     282                Return the vertical display resolution dpi
     283
     284        \return
     285                vertical resolution of the display in dpi.
     286        */
     287        virtual uint    getVertScreenDPI(void) const    {return 96;}
     288
     289
     290        /*!
     291        \brief
     292                Set the scene manager to be used for rendering the GUI.
     293
     294                The GUI system will be unhooked from the current scene manager and attached to what ever
     295                is specified here.
     296
     297        \param scene_manager
     298                Pointer to an Ogre::SceneManager object that is the new target Ogre::SceneManager to be
     299                used for GUI rendering.
     300
     301        \return
     302                Nothing.
     303        */
     304        void    setTargetSceneManager(Ogre::SceneManager* scene_manager);
     305
     306
     307        /*!
     308        \brief
     309                Set the target render queue for GUI rendering.
     310
     311        \param queue_id
     312                Ogre::uint8 value specifying the render queue that the GUI system should attach to.
     313
     314        \param post_queue
     315                - true to specify that the GUI should render after everything else in render queue \a queue_id.
     316                - false to specify the GUI should render before everything else in render queue \a queue_id.
     317
     318        \return
     319                Nothing.
     320        */
     321        void    setTargetRenderQueue(Ogre::uint8 queue_id, bool post_queue);
     322
     323
     324        /*!
     325        \brief
     326                Create a texture from an existing Ogre::TexturePtr object.
     327
     328        \note
     329                If you want to use an Ogre::RenderTexture (for putting rendered output onto Gui elements or other
     330                advanced techniques), you can get the Ogre::TexturePtr to be used by calling Ogre::TextureManager::getByName()
     331                passing the name returned from Ogre::RenderTexture::getName() (and casting the result as necessary).
     332
     333        \param texture
     334                pointer to an Ogre::TexturePtr object to be used as the basis for the new CEGUI::Texture
     335
     336        \return
     337                Pointer to the newly created CEGUI::TexturePtr object.
     338        */
     339        Texture*        createTexture(Ogre::TexturePtr& texture);
     340
     341
     342        /*!
     343        \brief
     344        Set the size of the display in pixels.
     345
     346        You do not have to call this method under normal operation as the system
     347        will automatically extract the size from the current view port.
     348
     349        \note
     350        This method will cause the EventDisplaySizeChanged event to fire if the
     351        display size has changed.
     352
     353        \param sz
     354        Size object describing the size of the display.
     355
     356        \return
     357        Nothing.
     358        */
     359        void    setDisplaySize(const Size& sz);
    360360
    361361
    362362private:
    363     /************************************************************************
    364         Implementation Constants
    365     ************************************************************************/
    366     static const size_t    VERTEX_PER_QUAD;                                              //!< number of vertices per quad
    367     static const size_t    VERTEX_PER_TRIANGLE;                                  //!< number of vertices for a triangle
     363        /************************************************************************
     364                Implementation Constants
     365        ************************************************************************/
     366        static const size_t    VERTEX_PER_QUAD;                                          //!< number of vertices per quad
     367        static const size_t    VERTEX_PER_TRIANGLE;                                      //!< number of vertices for a triangle
    368368    static const size_t    VERTEXBUFFER_INITIAL_CAPACITY;                //!< initial capacity of the allocated vertex buffer
    369369    static const size_t    UNDERUSED_FRAME_THRESHOLD;            //!< number of frames to wait before shrinking buffer
    370370
    371     /*************************************************************************
    372         Implementation Structs & classes
    373     *************************************************************************/
    374     /*!
    375     \brief
    376         structure used for all vertices.
    377     */
    378     struct QuadVertex {
    379         float x, y, z;                  //!< The position for the vertex.
    380         Ogre::RGBA diffuse;             //!< colour of the vertex
    381         float tu1, tv1;                 //!< texture coordinates
    382     };
    383 
    384     /*!
    385     \brief
    386         structure holding details about a quad to be drawn
    387     */
    388     struct QuadInfo
    389     {
    390         Ogre::TexturePtr                texture;
    391         Rect                            position;
    392         float                           z;
    393         Rect                            texPosition;
     371        /*************************************************************************
     372            Implementation Structs & classes
     373        *************************************************************************/
     374        /*!
     375        \brief
     376                structure used for all vertices.
     377        */
     378        struct QuadVertex {
     379                float x, y, z;                  //!< The position for the vertex.
     380                Ogre::RGBA diffuse;             //!< colour of the vertex
     381                float tu1, tv1;                 //!< texture coordinates
     382        };
     383
     384        /*!
     385        \brief
     386                structure holding details about a quad to be drawn
     387        */
     388        struct QuadInfo
     389        {
     390                Ogre::TexturePtr                texture;
     391                Rect                            position;
     392                float                           z;
     393                Rect                            texPosition;
    394394        uint32                  topLeftCol;
    395395        uint32                  topRightCol;
     
    399399        QuadSplitMode           splitMode;
    400400
    401         bool operator<(const QuadInfo& other) const
    402         {
    403             // this is intentionally reversed.
    404             return z > other.z;
    405         }
    406     };
    407 
    408 
    409     /*************************************************************************
    410         Implementation Methods
    411     *************************************************************************/
    412     // setup states etc
    413     void        initRenderStates(void);
    414 
    415     // sort quads list according to texture
    416     void        sortQuads(void);
    417 
    418     // render a quad directly to the display
    419     void        renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
    420 
    421     // convert colour value to whatever the Ogre render system is expecting.
     401                bool operator<(const QuadInfo& other) const
     402                {
     403                        // this is intentionally reversed.
     404                        return z > other.z;
     405                }
     406        };
     407
     408
     409        /*************************************************************************
     410            Implementation Methods
     411        *************************************************************************/
     412        // setup states etc
     413        void    initRenderStates(void);
     414
     415        // sort quads list according to texture
     416        void    sortQuads(void);
     417
     418        // render a quad directly to the display
     419        void    renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
     420
     421        // convert colour value to whatever the Ogre render system is expecting.
    422422    uint32    colourToOgre(const colour& col) const;
    423423
    424     // perform main work of the constructor.  This does everything except the final hook into the render system.
    425     void        constructor_impl(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads);
    426 
    427 
    428     /*************************************************************************
    429         Implementation Data
    430     *************************************************************************/
    431     Rect                                d_display_area;
    432 
    433     typedef std::multiset<QuadInfo>             QuadList;
    434     QuadList d_quadlist;
    435     bool         d_queueing;            //!< setting for queueing control.
    436 
    437     // Ogre specific bits.
    438     Ogre::Root*                                 d_ogre_root;            //!< pointer to the Ogre root object that we attach to
    439     Ogre::RenderSystem*                 d_render_sys;           //!< Pointer to the render system for Ogre.
    440     Ogre::uint8 d_queue_id;                     //!< ID of the queue that we are hooked into
    441     Ogre::TexturePtr                    d_currTexture;          //!< currently set texture;
    442     Ogre::RenderOperation               d_render_op;            //!< Ogre render operation we use to do our stuff.
    443     Ogre::HardwareVertexBufferSharedPtr d_buffer;       //!< vertex buffer to queue sprite rendering
     424        // perform main work of the constructor.  This does everything except the final hook into the render system.
     425        void    constructor_impl(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads);
     426
     427
     428        /*************************************************************************
     429            Implementation Data
     430        *************************************************************************/
     431        Rect                            d_display_area;
     432
     433        typedef std::multiset<QuadInfo>         QuadList;
     434        QuadList d_quadlist;
     435        bool     d_queueing;            //!< setting for queueing control.
     436
     437        // Ogre specific bits.
     438        Ogre::Root*                                     d_ogre_root;            //!< pointer to the Ogre root object that we attach to
     439        Ogre::RenderSystem*                     d_render_sys;           //!< Pointer to the render system for Ogre.
     440        Ogre::uint8     d_queue_id;                     //!< ID of the queue that we are hooked into
     441        Ogre::TexturePtr                        d_currTexture;          //!< currently set texture;
     442        Ogre::RenderOperation           d_render_op;            //!< Ogre render operation we use to do our stuff.
     443        Ogre::HardwareVertexBufferSharedPtr     d_buffer;       //!< vertex buffer to queue sprite rendering
    444444    size_t d_underused_framecount;                  //!< Number of frames elapsed since buffer utilization was above half the capacity
    445445    Ogre::RenderOperation               d_direct_render_op;             //!< Renderop for cursor
    446     Ogre::HardwareVertexBufferSharedPtr d_direct_buffer;        //!< Renderop for cursor
    447     Ogre::SceneManager*                 d_sceneMngr;            //!< The scene manager we are hooked into.
    448     Ogre::LayerBlendModeEx              d_colourBlendMode;      //!< Controls colour blending mode used.
    449     Ogre::LayerBlendModeEx              d_alphaBlendMode;       //!< Controls alpha blending mode used.
    450     Ogre::TextureUnitState::UVWAddressingMode d_uvwAddressMode;
    451 
    452     CEGUIRQListener*                    d_ourlistener;
    453     bool                                                d_post_queue;           //!< true if we render after everything else in our queue.
    454     size_t                                              d_bufferPos;            //!< index into buffer where next vertex should be put.
    455     bool                                                d_sorted;                       //!< true when data in quad list is sorted.
    456     Point                                               d_texelOffset;          //!< Offset required for proper texel mapping.
    457 
    458     std::list<OgreCEGUITexture*> d_texturelist;         //!< List used to track textures.
     446        Ogre::HardwareVertexBufferSharedPtr     d_direct_buffer;        //!< Renderop for cursor
     447        Ogre::SceneManager*                     d_sceneMngr;            //!< The scene manager we are hooked into.
     448        Ogre::LayerBlendModeEx          d_colourBlendMode;      //!< Controls colour blending mode used.
     449        Ogre::LayerBlendModeEx          d_alphaBlendMode;       //!< Controls alpha blending mode used.
     450        Ogre::TextureUnitState::UVWAddressingMode d_uvwAddressMode;
     451
     452        CEGUIRQListener*                        d_ourlistener;
     453        bool                                            d_post_queue;           //!< true if we render after everything else in our queue.
     454        size_t                                          d_bufferPos;            //!< index into buffer where next vertex should be put.
     455        bool                                            d_sorted;                       //!< true when data in quad list is sorted.
     456        Point                                           d_texelOffset;          //!< Offset required for proper texel mapping.
     457
     458        std::list<OgreCEGUITexture*> d_texturelist;             //!< List used to track textures.
    459459};
    460460
  • code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUIResourceProvider.cpp

    r2569 r2602  
    11/************************************************************************
    2     filename:   OgreCEGUIResourceProvider.cpp
    3     created:    8/7/2004
    4     author:             James '_mental_' O'Sullivan
     2        filename:       OgreCEGUIResourceProvider.cpp
     3        created:        8/7/2004
     4        author:         James '_mental_' O'Sullivan
    55
    6     purpose:    Implements the Resource Provider common functionality
     6        purpose:        Implements the Resource Provider common functionality
    77*************************************************************************/
    88/*************************************************************************
     
    7070            Ogre::ResourceGroupManager::getSingleton().openResource(filename.c_str(), orpGroup.c_str());
    7171
    72         if (input.isNull())
    73         {
     72                if (input.isNull())
     73                {
    7474            throw InvalidRequestException((utf8*)
    7575                "OgreCEGUIResourceProvider::loadRawDataContainer - Unable to open resource file '" + filename + (utf8*)"' in resource group '" + orpGroup + (utf8*)"'.");
    7676        }
    7777
    78         Ogre::String buf = input->getAsString();
    79         const size_t memBuffSize = buf.length();
     78                Ogre::String buf = input->getAsString();
     79                const size_t memBuffSize = buf.length();
    8080
    8181        unsigned char* mem = new unsigned char[memBuffSize];
     
    8686    }
    8787
    88     void OgreCEGUIResourceProvider::unloadRawDataContainer(RawDataContainer& data)
    89     {
    90         if (data.getDataPtr())
    91         {
    92             delete[] data.getDataPtr();
    93             data.setData(0);
    94             data.setSize(0);
    95         }
    96     }
     88        void OgreCEGUIResourceProvider::unloadRawDataContainer(RawDataContainer& data)
     89        {
     90                if (data.getDataPtr())
     91                {
     92                        delete[] data.getDataPtr();
     93                        data.setData(0);
     94                        data.setSize(0);
     95                }
     96        }
    9797} // End of  CEGUI namespace section
  • code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUIResourceProvider.h

    r2569 r2602  
    11/************************************************************************
    2     filename:   CEGUIOgreResourceProvider.h
    3     created:    8/7/2004
    4     author:             James '_mental_' O'Sullivan
    5    
    6     purpose:    Defines abstract base class for CEGUIData objects
     2        filename:       CEGUIOgreResourceProvider.h
     3        created:        8/7/2004
     4        author:         James '_mental_' O'Sullivan
     5       
     6        purpose:        Defines abstract base class for CEGUIData objects
    77*************************************************************************/
    88/*************************************************************************
     
    3636{
    3737public:
    38     /*************************************************************************
    39         Construction and Destruction
    40     *************************************************************************/
    41     OgreCEGUIResourceProvider();
     38        /*************************************************************************
     39                Construction and Destruction
     40        *************************************************************************/
     41        OgreCEGUIResourceProvider();
    4242
    43     ~OgreCEGUIResourceProvider(void) {}
     43        ~OgreCEGUIResourceProvider(void) {}
    4444
    4545//    void loadInputSourceContainer(const String& filename, InputSourceContainer& output);
  • code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUITexture.cpp

    r2569 r2602  
    11/************************************************************************
    2     filename:   OgreCEGUITexture.cpp
    3     created:    11/5/2004
    4     author:             Paul D Turner
    5    
    6     purpose:    Implementation of Texture using Ogre engine
     2        filename:       OgreCEGUITexture.cpp
     3        created:        11/5/2004
     4        author:         Paul D Turner
     5       
     6        purpose:        Implementation of Texture using Ogre engine
    77*************************************************************************/
    88/*************************************************************************
     
    3636{
    3737/*************************************************************************
    38     Static data definition / initialisation
     38        Static data definition / initialisation
    3939*************************************************************************/
    4040uint32 OgreCEGUITexture::d_texturenumber                = 0;
     
    4242
    4343/*************************************************************************
    44     Constructor
     44        Constructor
    4545*************************************************************************/
    4646OgreCEGUITexture::OgreCEGUITexture(Renderer* owner) :
    47     Texture(owner)
    48 {
    49     d_ogre_texture.setNull();
    50     d_isLinked = false;
    51 }
    52 
    53 
    54 /*************************************************************************
    55     Destructor
     47        Texture(owner)
     48{
     49        d_ogre_texture.setNull();
     50        d_isLinked = false;
     51}
     52
     53
     54/*************************************************************************
     55        Destructor
    5656*************************************************************************/
    5757OgreCEGUITexture::~OgreCEGUITexture(void)
    5858{
    59     freeOgreTexture();
    60 }
    61 
    62 
    63 /*************************************************************************
    64     Loads the specified image file into the texture.  The texture is
    65     resized as required to hold the image.     
     59        freeOgreTexture();
     60}
     61
     62
     63/*************************************************************************
     64        Loads the specified image file into the texture.  The texture is
     65        resized as required to hold the image. 
    6666*************************************************************************/
    6767void OgreCEGUITexture::loadFromFile(const String& filename, const String& resourceGroup)
    6868{
    69     using namespace Ogre;
    70 
    71     // unload old ogre texture
    72     freeOgreTexture();
    73 
    74     // create / load a new ogre texture from the specified image
    75     try
    76     {
    77         TextureManager& textureManager = TextureManager::getSingleton();
    78 
    79         // see if texture already exists
    80         Ogre::TexturePtr ogreTexture = (Ogre::TexturePtr)textureManager.getByName(filename.c_str());
    81 
    82         if (!ogreTexture.isNull())
    83         {
    84             // texture already exists, so create a 'linked' texture (ensures texture is not destroyed twice)
    85             d_ogre_texture = ogreTexture;
    86             d_isLinked = true;
    87         }
    88         // texture does not already exist, so load it in
    89         else
    90         {
     69        using namespace Ogre;
     70
     71        // unload old ogre texture
     72        freeOgreTexture();
     73
     74        // create / load a new ogre texture from the specified image
     75        try
     76        {
     77                TextureManager& textureManager = TextureManager::getSingleton();
     78
     79                // see if texture already exists
     80                Ogre::TexturePtr ogreTexture = (Ogre::TexturePtr)textureManager.getByName(filename.c_str());
     81
     82                if (!ogreTexture.isNull())
     83                {
     84                        // texture already exists, so create a 'linked' texture (ensures texture is not destroyed twice)
     85                        d_ogre_texture = ogreTexture;
     86                        d_isLinked = true;
     87                }
     88                // texture does not already exist, so load it in
     89                else
     90                {
    9191            String orpGroup;
    9292            if (resourceGroup.empty())
     
    100100            }
    101101
    102             d_ogre_texture = TextureManager::getSingleton().load(filename.c_str(), orpGroup.c_str(), TEX_TYPE_2D, 0, 1.0f);
    103             d_isLinked = false;
    104         }
    105 
    106     }
    107     catch(Ogre::Exception e)
    108     {
    109         throw RendererException((utf8*)"Failed to create Texture object from file '" + filename + "'. Additional Information:\n" + e.getFullDescription().c_str());
    110     }
    111 
    112     // if we got a pointer cache some details
    113     if (!d_ogre_texture.isNull())
    114     {
    115         d_width         = d_ogre_texture->getWidth();
    116         d_height        = d_ogre_texture->getHeight();
    117     }
    118     // no texture from image so throw.
    119     else
    120     {
    121         throw RendererException((utf8*)"Failed to create Texture object from file '" + filename + "'.  Ogre returned a NULL pointer.");
    122     }
    123 
    124 }
    125 
    126 
    127 /*************************************************************************
    128     Loads (copies) an image in memory into the texture.  The texture is
    129     resized as required to hold the image.     
     102                        d_ogre_texture = TextureManager::getSingleton().load(filename.c_str(), orpGroup.c_str(), TEX_TYPE_2D, 0, 1.0f);
     103                        d_isLinked = false;
     104                }
     105
     106        }
     107        catch(Ogre::Exception e)
     108        {
     109                throw RendererException((utf8*)"Failed to create Texture object from file '" + filename + "'. Additional Information:\n" + e.getFullDescription().c_str());
     110        }
     111
     112        // if we got a pointer cache some details
     113        if (!d_ogre_texture.isNull())
     114        {
     115                d_width         = d_ogre_texture->getWidth();
     116                d_height        = d_ogre_texture->getHeight();
     117        }
     118        // no texture from image so throw.
     119        else
     120        {
     121                throw RendererException((utf8*)"Failed to create Texture object from file '" + filename + "'.  Ogre returned a NULL pointer.");
     122        }
     123
     124}
     125
     126
     127/*************************************************************************
     128        Loads (copies) an image in memory into the texture.  The texture is
     129        resized as required to hold the image. 
    130130*************************************************************************/
    131131
     
    144144void OgreCEGUITexture::loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight, PixelFormat pixelFormat)
    145145{
    146     using namespace Ogre;
    147 
    148     // get rid of old texture
    149     freeOgreTexture();
    150 
    151     // wrap input buffer with an Ogre DataChunk
     146        using namespace Ogre;
     147
     148        // get rid of old texture
     149        freeOgreTexture();
     150
     151        // wrap input buffer with an Ogre DataChunk
    152152    uint32 bytesize = ((buffWidth * sizeof(uint32)) * buffHeight);
    153153
     
    161161    DataStreamPtr odc(new MemoryDataStream(static_cast<void*>(swappedBuffer), bytesize, false));
    162162#else
    163     DataStreamPtr odc(new MemoryDataStream(const_cast<void*>(buffPtr), bytesize, false));
     163        DataStreamPtr odc(new MemoryDataStream(const_cast<void*>(buffPtr), bytesize, false));
    164164#endif
    165165
    166     // get pixel type for the target texture - the elements here might look wrong, but is just
    167     // differences in definition (at the core level, between GL and D3D).
    168     Ogre::PixelFormat targetFmt =
    169         (pixelFormat == PF_RGBA) ? Ogre::PF_A8R8G8B8 : Ogre::PF_R8G8B8;
    170 
    171     // try to create a Ogre::Texture from the input data
    172     d_ogre_texture = TextureManager::getSingleton().loadRawData(getUniqueName(), "General", odc, buffWidth, buffHeight, targetFmt , TEX_TYPE_2D, 0, 1.0f);
    173 
    174     // if we got a pointer cache some details
    175     if (!d_ogre_texture.isNull())
    176     {
    177         d_width         = d_ogre_texture->getWidth();
    178         d_height        = d_ogre_texture->getHeight();
    179     }
    180     // no texture from memory so throw.
    181     else
    182     {
    183         throw RendererException((utf8*)"Failed to create Texture object from memory:  Ogre returned a NULL Ogre::Texture pointer.");
    184     }
    185 
    186 }
    187 
    188 
    189 /*************************************************************************
    190     set the size of the internal Ogre texture.  Previous Ogre texture
    191     is lost.   
     166        // get pixel type for the target texture - the elements here might look wrong, but is just
     167        // differences in definition (at the core level, between GL and D3D).
     168        Ogre::PixelFormat targetFmt =
     169                (pixelFormat == PF_RGBA) ? Ogre::PF_A8R8G8B8 : Ogre::PF_R8G8B8;
     170
     171        // try to create a Ogre::Texture from the input data
     172        d_ogre_texture = TextureManager::getSingleton().loadRawData(getUniqueName(), "General", odc, buffWidth, buffHeight, targetFmt , TEX_TYPE_2D, 0, 1.0f);
     173
     174        // if we got a pointer cache some details
     175        if (!d_ogre_texture.isNull())
     176        {
     177                d_width         = d_ogre_texture->getWidth();
     178                d_height        = d_ogre_texture->getHeight();
     179        }
     180        // no texture from memory so throw.
     181        else
     182        {
     183                throw RendererException((utf8*)"Failed to create Texture object from memory:  Ogre returned a NULL Ogre::Texture pointer.");
     184        }
     185
     186}
     187
     188
     189/*************************************************************************
     190        set the size of the internal Ogre texture.  Previous Ogre texture
     191        is lost.       
    192192*************************************************************************/
    193193void OgreCEGUITexture::setOgreTextureSize(uint size)
    194194{
    195     using namespace Ogre;
    196 
    197     // unload any current Ogre::Texture
    198     freeOgreTexture();
    199 
    200     // Try to create an empty texture of the given size
    201     d_ogre_texture = TextureManager::getSingleton().createManual(getUniqueName(), "General", TEX_TYPE_2D, size, size, 0, PF_A8R8G8B8, TU_DEFAULT);
    202 
    203     // if we got a pointer cache some details
    204     if (!d_ogre_texture.isNull())
    205     {
    206         d_width         = d_ogre_texture->getWidth();
    207         d_height        = d_ogre_texture->getHeight();
    208     }
    209     // no texture so throw.
    210     else
    211     {
    212         throw RendererException((utf8*)"Failed to create texture of specified size: Ogre::Texture creation failed.");
    213     }
    214 
    215 }
    216 
    217 
    218 /*************************************************************************
    219     safely free Ogre::Texture texture (can be called multiple times with
    220     no ill effect)
     195        using namespace Ogre;
     196
     197        // unload any current Ogre::Texture
     198        freeOgreTexture();
     199
     200        // Try to create an empty texture of the given size
     201        d_ogre_texture = TextureManager::getSingleton().createManual(getUniqueName(), "General", TEX_TYPE_2D, size, size, 0, PF_A8R8G8B8, TU_DEFAULT);
     202
     203        // if we got a pointer cache some details
     204        if (!d_ogre_texture.isNull())
     205        {
     206                d_width         = d_ogre_texture->getWidth();
     207                d_height        = d_ogre_texture->getHeight();
     208        }
     209        // no texture so throw.
     210        else
     211        {
     212                throw RendererException((utf8*)"Failed to create texture of specified size: Ogre::Texture creation failed.");
     213        }
     214
     215}
     216
     217
     218/*************************************************************************
     219        safely free Ogre::Texture texture (can be called multiple times with
     220        no ill effect)
    221221*************************************************************************/
    222222void OgreCEGUITexture::freeOgreTexture(void)
    223223{
    224     if ((!d_ogre_texture.isNull()) && !d_isLinked)
    225     {
    226         Ogre::TextureManager::getSingleton().remove(d_ogre_texture->getHandle());
    227     }
    228     d_ogre_texture.setNull();
    229 }
    230 
    231 
    232 /*************************************************************************
    233     return a Ogre::string that contains a unique name. 
     224        if ((!d_ogre_texture.isNull()) && !d_isLinked)
     225        {
     226                Ogre::TextureManager::getSingleton().remove(d_ogre_texture->getHandle());
     227        }
     228        d_ogre_texture.setNull();
     229}
     230
     231
     232/*************************************************************************
     233        return a Ogre::string that contains a unique name.     
    234234*************************************************************************/
    235235Ogre::String OgreCEGUITexture::getUniqueName(void)
    236236{
    237     Ogre::String str;
     237        Ogre::String str;
    238238
    239239#ifdef CEGUI_USEOLDOGRESTRING
    240     str << "_cegui_ogre_" << d_texturenumber;
     240        str << "_cegui_ogre_" << d_texturenumber;
    241241#else
    242     Ogre::StringUtil::StrStreamType strstream;
    243     strstream << "_cegui_ogre_" << d_texturenumber;
    244     str = strstream.str();
     242        Ogre::StringUtil::StrStreamType strstream;
     243        strstream << "_cegui_ogre_" << d_texturenumber;
     244        str = strstream.str();
    245245#endif
    246246
    247     ++d_texturenumber;
    248 
    249     return str;
    250 }
    251 
    252 
    253 /*************************************************************************
    254     Set the internal Ogre::Texture object.
     247        ++d_texturenumber;
     248
     249        return str;
     250}
     251
     252
     253/*************************************************************************
     254        Set the internal Ogre::Texture object.
    255255*************************************************************************/
    256256void OgreCEGUITexture::setOgreTexture(Ogre::TexturePtr& texture)
    257257{
    258     freeOgreTexture();
    259 
    260     d_ogre_texture = texture;
    261     d_width      = d_ogre_texture->getWidth();
    262     d_height = d_ogre_texture->getHeight();
    263     d_isLinked = true;
     258        freeOgreTexture();
     259
     260        d_ogre_texture = texture;
     261        d_width  = d_ogre_texture->getWidth();
     262        d_height = d_ogre_texture->getHeight();
     263        d_isLinked = true;
    264264}
    265265
  • code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUITexture.h

    r2569 r2602  
    11/************************************************************************
    2     filename:   OgreCEGUITexture.h
    3     created:    11/5/2004
    4     author:             Paul D Turner
    5    
    6     purpose:    Interface to Texture implemented via Ogre engine
     2        filename:       OgreCEGUITexture.h
     3        created:        11/5/2004
     4        author:         Paul D Turner
     5       
     6        purpose:        Interface to Texture implemented via Ogre engine
    77*************************************************************************/
    88/*************************************************************************
     
    3737/*!
    3838\brief
    39     Texture class that is created by OgreCEGUIRenderer objects
     39        Texture class that is created by OgreCEGUIRenderer objects
    4040*/
    4141class _OgrePrivate OgreCEGUITexture : public Texture
    4242{
    4343private:
    44     /*************************************************************************
    45         Friends (to allow construction and destruction)
    46     *************************************************************************/
    47     friend      Texture* OgreCEGUIRenderer::createTexture(void);
    48     friend      Texture* OgreCEGUIRenderer::createTexture(const String& filename, const String& resourceGroup);
    49     friend      Texture* OgreCEGUIRenderer::createTexture(float size);
    50     friend      void     OgreCEGUIRenderer::destroyTexture(Texture* texture);
     44        /*************************************************************************
     45                Friends (to allow construction and destruction)
     46        *************************************************************************/
     47        friend  Texture* OgreCEGUIRenderer::createTexture(void);
     48        friend  Texture* OgreCEGUIRenderer::createTexture(const String& filename, const String& resourceGroup);
     49        friend  Texture* OgreCEGUIRenderer::createTexture(float size);
     50        friend  void     OgreCEGUIRenderer::destroyTexture(Texture* texture);
    5151
    5252
    53     /*************************************************************************
    54         Construction & Destruction (by Renderer object only)
    55     *************************************************************************/
    56     OgreCEGUITexture(Renderer* owner);
    57     virtual ~OgreCEGUITexture(void);
     53        /*************************************************************************
     54                Construction & Destruction (by Renderer object only)
     55        *************************************************************************/
     56        OgreCEGUITexture(Renderer* owner);
     57        virtual ~OgreCEGUITexture(void);
    5858
    5959public:
    60     /*!
    61     \brief
    62         Returns the current pixel width of the texture
     60        /*!
     61        \brief
     62                Returns the current pixel width of the texture
    6363
    64     \return
    65         ushort value that is the current width of the texture in pixels
    66     */
    67     virtual     ushort  getWidth(void) const            {return d_width;}
     64        \return
     65                ushort value that is the current width of the texture in pixels
     66        */
     67        virtual ushort  getWidth(void) const            {return d_width;}
    6868
    6969
    70     /*!
    71     \brief
    72         Returns the current pixel height of the texture
     70        /*!
     71        \brief
     72                Returns the current pixel height of the texture
    7373
    74     \return
    75         ushort value that is the current height of the texture in pixels
    76     */
    77     virtual     ushort  getHeight(void) const           {return d_height;}
     74        \return
     75                ushort value that is the current height of the texture in pixels
     76        */
     77        virtual ushort  getHeight(void) const           {return d_height;}
    7878
    7979
    80     /*!
    81     \brief
    82         Loads the specified image file into the texture.  The texture is resized as required to hold the image.
     80        /*!
     81        \brief
     82                Loads the specified image file into the texture.  The texture is resized as required to hold the image.
    8383
    84     \param filename
    85         The filename of the image file that is to be loaded into the texture
     84        \param filename
     85                The filename of the image file that is to be loaded into the texture
    8686
    87     \return
    88         Nothing.
    89     */
    90     virtual void        loadFromFile(const String& filename, const String& resourceGroup);
     87        \return
     88                Nothing.
     89        */
     90        virtual void    loadFromFile(const String& filename, const String& resourceGroup);
    9191
    9292
    93     /*!
    94     \brief
    95         Loads (copies) an image in memory into the texture.  The texture is resized as required to hold the image.
    96    
    97     \param buffPtr
    98         Pointer to the buffer containing the image data
    99    
    100     \param buffWidth
    101         Width of the buffer (in pixels as specified by \a pixelFormat )
    102    
    103     \param buffHeight
    104         Height of the buffer (in pixels as specified by \a pixelFormat )
    105    
    106     \param pixelFormat
    107     PixelFormat value describing the format contained in \a buffPtr
    108    
    109     \return
    110         Nothing.
    111     */
    112     virtual void        loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight, PixelFormat pixelFormat);
     93        /*!
     94        \brief
     95                Loads (copies) an image in memory into the texture.  The texture is resized as required to hold the image.
     96       
     97        \param buffPtr
     98                Pointer to the buffer containing the image data
     99       
     100        \param buffWidth
     101                Width of the buffer (in pixels as specified by \a pixelFormat )
     102       
     103        \param buffHeight
     104                Height of the buffer (in pixels as specified by \a pixelFormat )
     105       
     106        \param pixelFormat
     107        PixelFormat value describing the format contained in \a buffPtr
     108       
     109        \return
     110                Nothing.
     111        */
     112        virtual void    loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight, PixelFormat pixelFormat);
    113113
    114114
    115     /*!
    116     \brief
    117         Return a pointer to the internal Ogre::Texture object
     115        /*!
     116        \brief
     117                Return a pointer to the internal Ogre::Texture object
    118118
    119     \return
    120         Pointer to the Ogre::Texture object currently being used by this Texture object
    121     */
    122     Ogre::TexturePtr    getOgreTexture(void) const              {return d_ogre_texture;}
     119        \return
     120                Pointer to the Ogre::Texture object currently being used by this Texture object
     121        */
     122        Ogre::TexturePtr        getOgreTexture(void) const              {return d_ogre_texture;}
    123123
    124124
    125     /*!
    126     \brief
    127         set the size of the internal Ogre texture.  Previous Ogre texture is lost.
     125        /*!
     126        \brief
     127                set the size of the internal Ogre texture.  Previous Ogre texture is lost.
    128128
    129     \param size
    130         pixel size of the new internal texture.  This will be rounded up to a power of 2.
     129        \param size
     130                pixel size of the new internal texture.  This will be rounded up to a power of 2.
    131131
    132     \return
    133         Nothing.
    134     */
    135     void        setOgreTextureSize(uint size);
     132        \return
     133                Nothing.
     134        */
     135        void    setOgreTextureSize(uint size);
    136136
    137137
    138     /*!
    139     \brief
    140         Set the internal Ogre::TexturePtr object.
     138        /*!
     139        \brief
     140                Set the internal Ogre::TexturePtr object.
    141141
    142     \param texture
    143         Reference to an Ogre::TexturePtr object that is to be used by this Texture object.
     142        \param texture
     143                Reference to an Ogre::TexturePtr object that is to be used by this Texture object.
    144144
    145     \return
    146         Nothing.
    147     */
    148     void        setOgreTexture(Ogre::TexturePtr& texture);
     145        \return
     146                Nothing.
     147        */
     148        void    setOgreTexture(Ogre::TexturePtr& texture);
    149149
    150150
    151151private:
    152     /*************************************************************************
    153         Implementation Functions
    154     *************************************************************************/
    155     // safely free Ogre::Texture texture (can be called multiple times with no ill effect)
    156     void        freeOgreTexture(void);
     152        /*************************************************************************
     153                Implementation Functions
     154        *************************************************************************/
     155        // safely free Ogre::Texture texture (can be called multiple times with no ill effect)
     156        void    freeOgreTexture(void);
    157157
    158     // return a Ogre::string that contains a unique name.
    159     Ogre::String        getUniqueName(void);
     158        // return a Ogre::string that contains a unique name.
     159        Ogre::String    getUniqueName(void);
    160160
    161161
    162     /*************************************************************************
    163         Implementation Data
    164     *************************************************************************/
    165     static      uint32          d_texturenumber;        //!< Counter used to provide unique texture names.
     162        /*************************************************************************
     163                Implementation Data
     164        *************************************************************************/
     165        static  uint32          d_texturenumber;        //!< Counter used to provide unique texture names.
    166166
    167     Ogre::TexturePtr            d_ogre_texture;         //!< The 'real' texture.
     167        Ogre::TexturePtr                d_ogre_texture;         //!< The 'real' texture.
    168168
    169     ushort                                      d_width;                        //!< cached width of the texture
    170     ushort                                      d_height;                       //!< cached height of the texture
     169        ushort                                  d_width;                        //!< cached width of the texture
     170        ushort                                  d_height;                       //!< cached height of the texture
    171171
    172     bool        d_isLinked;             //!< True if we are linked to a texture we did not actually create.
     172        bool    d_isLinked;             //!< True if we are linked to a texture we did not actually create.
    173173};
    174174
Note: See TracChangeset for help on using the changeset viewer.