Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

irrlichtrenderer.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       irrlichtrenderer.cpp
00003         created:        20/7/2004
00004         author:         Thomas Suter
00005 *************************************************************************/
00006 /*************************************************************************
00007     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00008     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 *************************************************************************/
00024 #include "renderers/IrrlichtRenderer/irrlichtrenderer.h"
00025 #include "IrrlichtEventPusher.h"
00026 #include "CEGUIDefaultResourceProvider.h"
00027 #include <sstream>
00028 
00029 namespace CEGUI
00030 {
00031 /************************************************************************/
00032         IrrlichtRenderer::IrrlichtRenderer(irr::IrrlichtDevice* dev, bool bWithIrrlichtResourceProvicer): Renderer(),device(dev)
00033         {
00034                 this->bWithIrrlichtResourceProvicer=bWithIrrlichtResourceProvicer;
00035                 d_resourceProvider=0;
00036                 driver=device->getVideoDriver();
00037                 resolution=driver->getScreenSize(); // @todo use active viewport!!
00038                 screensize=device->getVideoModeList()->getDesktopResolution();
00039                 bSorted=false;
00040                 bQueuingEnabled=true;
00041                 eventpusher=new EventPusher(device->getCursorControl());
00042 
00043         // set ID string
00044         d_identifierString = "CEGUI::IrrlichtRenderer - Official Irrlicht based renderer module for CEGUI";
00045         }
00046 /************************************************************************/
00047         IrrlichtRenderer::~IrrlichtRenderer()
00048         {
00049                 delete eventpusher;
00050         };
00051 /************************************************************************/
00052         void IrrlichtRenderer::addQuad(const Rect& dest_rect, float z, const Texture* tex, 
00053                 const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode)
00054         {
00055 
00056                 /* 
00057                 irrlicht doesn't support for drawing mode selection 
00058                 so 'quad_split_mode' is neglected at the moment
00059                 */
00060 
00061                 irr::u32 tex_height=tex->getHeight();
00062                 irr::u32 tex_width=tex->getWidth();
00063 
00064                 dummyQuad.src.UpperLeftCorner.X=texture_rect.d_left*tex_width;
00065                 dummyQuad.src.UpperLeftCorner.Y=(texture_rect.d_top)*tex_height-1;
00066                 dummyQuad.src.LowerRightCorner.X=texture_rect.d_right*tex_width;
00067                 dummyQuad.src.LowerRightCorner.Y=texture_rect.d_bottom*tex_height-1;
00068 
00069                 dummyQuad.dst.UpperLeftCorner.X=dest_rect.d_left;
00070                 dummyQuad.dst.UpperLeftCorner.Y=dest_rect.d_top-1;
00071                 dummyQuad.dst.LowerRightCorner.X=dest_rect.d_right;
00072                 dummyQuad.dst.LowerRightCorner.Y=dest_rect.d_bottom-1;
00073 
00074                 dummyQuad.z=z;
00075                 dummyQuad.colours=colours;
00076                 dummyQuad.tex=(IrrlichtTexture*)tex;
00077                 
00078                 if(bQueuingEnabled)
00079                 {
00080                         renderlist.push_back(dummyQuad);
00081                         bSorted=false;
00082                 }
00083                 else
00084                 {
00085                         doRender(dummyQuad);
00086                 }
00087         }
00088 /************************************************************************/
00089         void IrrlichtRenderer::print(RenderQuad& quad)
00090         {
00091                 //char buf[255];
00092                 //irr::video::ITexture* texture=((IrrlichtTexture*)quad.tex)->getTexture();
00093                 //sprintf(buf,"renderquad(dst(%d,%d-%d,%d) src(%d,%d-%d,%d) tex(%x-%d,%d))",
00094                 //      quad.dst.UpperLeftCorner.X,quad.dst.UpperLeftCorner.Y,
00095                 //      quad.dst.LowerRightCorner.X,quad.dst.LowerRightCorner.Y,
00096                 //      quad.src.UpperLeftCorner.X,quad.src.UpperLeftCorner.Y,
00097                 //      quad.src.LowerRightCorner.X,quad.src.LowerRightCorner.Y,
00098                 //      (unsigned long)texture,texture->getSize().Width,texture->getSize().Height);
00099                 //device->getLogger()->log(buf,irr::ELL_INFORMATION);
00100         }
00101 /************************************************************************/
00102         void IrrlichtRenderer::sortQuads(void)
00103         {
00104                 if (!bSorted)
00105                 {
00106                         std::stable_sort(renderlist.begin(),renderlist.end(), quadsorter());
00107                         bSorted = true;
00108                 }
00109         }
00110 /************************************************************************/
00111         void IrrlichtRenderer::doRender(void)
00112         {
00113                 sortQuads();
00114                 std::vector<RenderQuad>::iterator iter=renderlist.begin();
00115                 for(;iter!=renderlist.end();++iter) doRender( (*iter) );
00116         }
00117 /************************************************************************/
00118         void IrrlichtRenderer::doRender(RenderQuad& quad)
00119         {
00120                 irr::video::ITexture* texture=((IrrlichtTexture*)quad.tex)->getTexture();
00121                 colors[0].color=quad.colours.d_top_left.getARGB();
00122                 colors[1].color=quad.colours.d_bottom_left.getARGB();
00123                 colors[2].color=quad.colours.d_bottom_right.getARGB();
00124                 colors[3].color=quad.colours.d_top_right.getARGB();
00125                 driver->draw2DImage(texture,quad.dst,quad.src,0,colors,true);
00126         }
00127 /************************************************************************/
00128         irr::video::SColor IrrlichtRenderer::toIrrlichtColor(CEGUI::ulong cecolor)
00129         {
00130                 return irr::video::SColor(
00131                         ((cecolor >> 24) ) , 
00132                         (((cecolor & 0x00FF0000) >> 16) ) ,
00133                         (((cecolor & 0x0000FF00) >> 8) ) ,
00134                         ((cecolor & 0x000000FF) )
00135                         );
00136         }
00137 /************************************************************************/
00138         void IrrlichtRenderer::clearRenderList(void)
00139         {
00140                 renderlist.resize(0);
00141         }
00142 /************************************************************************/
00143         void IrrlichtRenderer::setQueueingEnabled(bool setting)
00144         {
00145                 bQueuingEnabled=setting;
00146         }
00147 /************************************************************************/
00148         Texture* IrrlichtRenderer::createTexture(void)
00149         {
00150                 IrrlichtTexture* t=new IrrlichtTexture(this,device);
00151                 textures.push_back(t);
00152                 return t;
00153         }
00154 /************************************************************************/
00155         Texture* IrrlichtRenderer::createTexture(const String& filename, const String& resourceGroup)
00156         {
00157                 IrrlichtTexture* t=(IrrlichtTexture*)createTexture();
00158                 t->loadFromFile(filename, resourceGroup);
00159                 return t;
00160         }
00161 /************************************************************************/      
00162         Texture* IrrlichtRenderer::createTexture(float size)
00163         {
00164                 IrrlichtTexture* t=(IrrlichtTexture*)createTexture();
00165                 return t;
00166         }
00167 /************************************************************************/
00168         void IrrlichtRenderer::destroyTexture(Texture* texture)
00169         {
00170                 std::vector<IrrlichtTexture*>::iterator iter=textures.begin();
00171                 for(;iter!=textures.end();++iter)
00172                 {
00173                         IrrlichtTexture* t=(*iter);
00174                         if(t==texture)
00175                         {
00176                                 delete t;
00177                                 textures.erase(iter);
00178                                 return;
00179                         }
00180                 }
00181         }
00182 /************************************************************************/
00183         void IrrlichtRenderer::destroyAllTextures(void)
00184         {
00185                 std::vector<IrrlichtTexture*>::iterator iter=textures.begin();
00186                 for(;iter!=textures.end();)
00187                 {
00188                         IrrlichtTexture* t=(*iter);
00189                         delete t;
00190                         iter=textures.erase(iter);
00191                 }
00192         }
00193 /************************************************************************/
00194         bool IrrlichtRenderer::isQueueingEnabled(void) const
00195         {
00196                 return bQueuingEnabled;
00197         }
00198 /************************************************************************/
00199         float IrrlichtRenderer::getWidth(void) const
00200         {
00201                 return resolution.Width;
00202         }
00203 /************************************************************************/
00204         float IrrlichtRenderer::getHeight(void) const
00205         {
00206                 return resolution.Height;
00207         }
00208 /************************************************************************/
00209         Size IrrlichtRenderer::getSize(void) const
00210         {
00211                 return Size(resolution.Width,resolution.Height);
00212         }
00213 /************************************************************************/
00214         Rect IrrlichtRenderer::getRect(void) const
00215         {
00216                 return Rect(0,0,resolution.Width,resolution.Height);
00217         }
00218 /************************************************************************/
00219         uint IrrlichtRenderer::getMaxTextureSize(void) const
00220         {
00221                 return 2048;
00222         }
00223 /************************************************************************/
00224         uint IrrlichtRenderer::getHorzScreenDPI(void) const
00225         {
00226                 return 96;
00227         }
00228 /************************************************************************/
00229         uint IrrlichtRenderer::getVertScreenDPI(void) const
00230         {
00231                 return 96;
00232         }
00233 /************************************************************************/
00237         ResourceProvider* IrrlichtRenderer::createResourceProvider(void)
00238         {
00239                 if(d_resourceProvider==0)
00240                 {
00241                         if(bWithIrrlichtResourceProvicer)
00242                         {
00243                                 d_resourceProvider = new IrrlichtResourceProvider(device->getFileSystem());
00244                         }
00245                         else
00246                         {
00247                                 d_resourceProvider = new DefaultResourceProvider();
00248                         }
00249                 }
00250                 return d_resourceProvider;
00251         }
00252 
00254         bool IrrlichtRenderer::OnEvent(irr::SEvent& event)
00255         {
00256                 return eventpusher->OnEvent(event);
00257         }
00258 }

Generated on Wed Sep 7 09:56:35 2005 for Crazy Eddies GUI System by  doxygen 1.4.3