00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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();
00038 screensize=device->getVideoModeList()->getDesktopResolution();
00039 bSorted=false;
00040 bQueuingEnabled=true;
00041 eventpusher=new EventPusher(device->getCursorControl());
00042
00043
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
00058
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
00092
00093
00094
00095
00096
00097
00098
00099
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 }