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

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 /************************************************************************/
00044         IrrlichtRenderer::~IrrlichtRenderer()
00045         {
00046                 delete eventpusher;
00047         };
00048 /************************************************************************/
00049         void IrrlichtRenderer::addQuad(const Rect& dest_rect, float z, const Texture* tex, 
00050                 const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode)
00051         {
00052 
00053                 /* 
00054                 irrlicht doesn't support for drawing mode selection 
00055                 so 'quad_split_mode' is neglected at the moment
00056                 */
00057 
00058                 irr::u32 tex_height=tex->getHeight();
00059                 irr::u32 tex_width=tex->getWidth();
00060 
00061                 dummyQuad.src.UpperLeftCorner.X=texture_rect.d_left*tex_width;
00062                 dummyQuad.src.UpperLeftCorner.Y=texture_rect.d_top*tex_height;
00063                 dummyQuad.src.LowerRightCorner.X=texture_rect.d_right*tex_width;
00064                 dummyQuad.src.LowerRightCorner.Y=texture_rect.d_bottom*tex_height;
00065 
00066                 dummyQuad.dst.UpperLeftCorner.X=dest_rect.d_left;
00067                 dummyQuad.dst.UpperLeftCorner.Y=dest_rect.d_top;
00068                 dummyQuad.dst.LowerRightCorner.X=dest_rect.d_right;
00069                 dummyQuad.dst.LowerRightCorner.Y=dest_rect.d_bottom;
00070 
00071                 dummyQuad.z=z;
00072                 dummyQuad.colours=colours;
00073                 dummyQuad.tex=(IrrlichtTexture*)tex;
00074                 
00075                 if(bQueuingEnabled)
00076                 {
00077                         renderlist.push_back(dummyQuad);
00078                         bSorted=false;
00079                 }
00080                 else
00081                 {
00082                         doRender(dummyQuad);
00083                 }
00084         }
00085 /************************************************************************/
00086         void IrrlichtRenderer::print(RenderQuad& quad)
00087         {
00088                 //char buf[255];
00089                 //irr::video::ITexture* texture=((IrrlichtTexture*)quad.tex)->getTexture();
00090                 //sprintf(buf,"renderquad(dst(%d,%d-%d,%d) src(%d,%d-%d,%d) tex(%x-%d,%d))",
00091                 //      quad.dst.UpperLeftCorner.X,quad.dst.UpperLeftCorner.Y,
00092                 //      quad.dst.LowerRightCorner.X,quad.dst.LowerRightCorner.Y,
00093                 //      quad.src.UpperLeftCorner.X,quad.src.UpperLeftCorner.Y,
00094                 //      quad.src.LowerRightCorner.X,quad.src.LowerRightCorner.Y,
00095                 //      (unsigned long)texture,texture->getSize().Width,texture->getSize().Height);
00096                 //device->getLogger()->log(buf,irr::ELL_INFORMATION);
00097         }
00098 /************************************************************************/
00099         void IrrlichtRenderer::sortQuads(void)
00100         {
00101                 if (!bSorted)
00102                 {
00103                         std::stable_sort(renderlist.begin(),renderlist.end(), quadsorter());
00104                         bSorted = true;
00105                 }
00106         }
00107 /************************************************************************/
00108         void IrrlichtRenderer::doRender(void)
00109         {
00110                 sortQuads();
00111                 std::vector<RenderQuad>::iterator iter=renderlist.begin();
00112                 for(;iter!=renderlist.end();++iter) doRender( (*iter) );
00113         }
00114 /************************************************************************/
00115         void IrrlichtRenderer::doRender(RenderQuad& quad)
00116         {
00117                 irr::video::ITexture* texture=((IrrlichtTexture*)quad.tex)->getTexture();
00118                 colors[0].color=quad.colours.d_top_left.getARGB();
00119                 colors[1].color=quad.colours.d_bottom_left.getARGB();
00120                 colors[2].color=quad.colours.d_bottom_right.getARGB();
00121                 colors[3].color=quad.colours.d_top_right.getARGB();
00122                 driver->draw2DImage(texture,quad.dst,quad.src,0,colors,true);
00123         }
00124 /************************************************************************/
00125         irr::video::SColor IrrlichtRenderer::toIrrlichtColor(CEGUI::ulong cecolor)
00126         {
00127                 return irr::video::SColor(
00128                         ((cecolor >> 24) ) , 
00129                         (((cecolor & 0x00FF0000) >> 16) ) ,
00130                         (((cecolor & 0x0000FF00) >> 8) ) ,
00131                         ((cecolor & 0x000000FF) )
00132                         );
00133         }
00134 /************************************************************************/
00135         void IrrlichtRenderer::clearRenderList(void)
00136         {
00137                 renderlist.resize(0);
00138         }
00139 /************************************************************************/
00140         void IrrlichtRenderer::setQueueingEnabled(bool setting)
00141         {
00142                 bQueuingEnabled=setting;
00143         }
00144 /************************************************************************/
00145         Texture* IrrlichtRenderer::createTexture(void)
00146         {
00147                 IrrlichtTexture* t=new IrrlichtTexture(this,device);
00148                 textures.push_back(t);
00149                 return t;
00150         }
00151 /************************************************************************/
00152         Texture* IrrlichtRenderer::createTexture(const String& filename, const String& resourceGroup)
00153         {
00154                 IrrlichtTexture* t=(IrrlichtTexture*)createTexture();
00155                 t->loadFromFile(filename, resourceGroup);
00156                 return t;
00157         }
00158 /************************************************************************/      
00159         Texture* IrrlichtRenderer::createTexture(float size)
00160         {
00161                 IrrlichtTexture* t=(IrrlichtTexture*)createTexture();
00162                 return t;
00163         }
00164 /************************************************************************/
00165         void IrrlichtRenderer::destroyTexture(Texture* texture)
00166         {
00167                 std::vector<IrrlichtTexture*>::iterator iter=textures.begin();
00168                 for(;iter!=textures.end();++iter)
00169                 {
00170                         IrrlichtTexture* t=(*iter);
00171                         if(t==texture)
00172                         {
00173                                 delete t;
00174                                 textures.erase(iter);
00175                                 return;
00176                         }
00177                 }
00178         }
00179 /************************************************************************/
00180         void IrrlichtRenderer::destroyAllTextures(void)
00181         {
00182                 std::vector<IrrlichtTexture*>::iterator iter=textures.begin();
00183                 for(;iter!=textures.end();)
00184                 {
00185                         IrrlichtTexture* t=(*iter);
00186                         delete t;
00187                         iter=textures.erase(iter);
00188                 }
00189         }
00190 /************************************************************************/
00191         bool IrrlichtRenderer::isQueueingEnabled(void) const
00192         {
00193                 return bQueuingEnabled;
00194         }
00195 /************************************************************************/
00196         float IrrlichtRenderer::getWidth(void) const
00197         {
00198                 return resolution.Width;
00199         }
00200 /************************************************************************/
00201         float IrrlichtRenderer::getHeight(void) const
00202         {
00203                 return resolution.Height;
00204         }
00205 /************************************************************************/
00206         Size IrrlichtRenderer::getSize(void) const
00207         {
00208                 return Size(resolution.Width,resolution.Height);
00209         }
00210 /************************************************************************/
00211         Rect IrrlichtRenderer::getRect(void) const
00212         {
00213                 return Rect(0,0,resolution.Width,resolution.Height);
00214         }
00215 /************************************************************************/
00216         uint IrrlichtRenderer::getMaxTextureSize(void) const
00217         {
00218                 return 2048;
00219         }
00220 /************************************************************************/
00221         uint IrrlichtRenderer::getHorzScreenDPI(void) const
00222         {
00223                 return 96;
00224         }
00225 /************************************************************************/
00226         uint IrrlichtRenderer::getVertScreenDPI(void) const
00227         {
00228                 return 96;
00229         }
00230 /************************************************************************/
00234         ResourceProvider* IrrlichtRenderer::createResourceProvider(void)
00235         {
00236                 if(d_resourceProvider==0)
00237                 {
00238                         if(bWithIrrlichtResourceProvicer)
00239                         {
00240                                 d_resourceProvider = new IrrlichtResourceProvider(device->getFileSystem());
00241                         }
00242                         else
00243                         {
00244                                 d_resourceProvider = new DefaultResourceProvider();
00245                         }
00246                 }
00247                 return d_resourceProvider;
00248         }
00249 
00251         bool IrrlichtRenderer::OnEvent(irr::SEvent& event)
00252         {
00253                 return eventpusher->OnEvent(event);
00254         }
00255 }

Generated on Wed Feb 16 12:41:08 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1