- Timestamp:
- Jan 29, 2009, 7:12:27 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUIRenderer.h
r2569 r2602 1 1 /************************************************************************ 2 3 4 5 6 2 filename: OgreCEGUIRenderer.h 3 created: 11/5/2004 4 author: Paul D Turner 5 6 purpose: Interface for main Ogre GUI renderer class 7 7 *************************************************************************/ 8 8 /************************************************************************* … … 25 25 *************************************************************************/ 26 26 /************************************************************************* 27 27 This file contains code that is specific to Ogre (http://www.ogre3d.org) 28 28 *************************************************************************/ 29 29 #ifndef _OgreCEGUIRenderer_h_ … … 59 59 { 60 60 /************************************************************************* 61 61 Forward refs 62 62 *************************************************************************/ 63 63 class OgreCEGUITexture; … … 67 67 /*! 68 68 \brief 69 69 RenderQueueListener based class used to hook into the ogre rendering system 70 70 */ 71 71 class _OgrePrivate CEGUIRQListener : public Ogre::RenderQueueListener 72 72 { 73 73 public: 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 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;} 89 89 90 90 private: 91 92 93 94 95 96 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. 97 97 }; 98 98 … … 100 100 /*! 101 101 \brief 102 102 Renderer class to interface with Ogre engine. 103 103 */ 104 104 class OGRE_GUIRENDERER_API OgreCEGUIRenderer : public Renderer 105 105 { 106 106 public: 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 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); 198 198 199 199 // create an OGRE resource provider. 200 200 virtual ResourceProvider* createResourceProvider(void); 201 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 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); 360 360 361 361 362 362 private: 363 364 365 366 367 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 368 368 static const size_t VERTEXBUFFER_INITIAL_CAPACITY; //!< initial capacity of the allocated vertex buffer 369 369 static const size_t UNDERUSED_FRAME_THRESHOLD; //!< number of frames to wait before shrinking buffer 370 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 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; 394 394 uint32 topLeftCol; 395 395 uint32 topRightCol; … … 399 399 QuadSplitMode splitMode; 400 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 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. 422 422 uint32 colourToOgre(const colour& col) const; 423 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 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 444 444 size_t d_underused_framecount; //!< Number of frames elapsed since buffer utilization was above half the capacity 445 445 Ogre::RenderOperation d_direct_render_op; //!< Renderop for cursor 446 447 448 449 450 451 452 453 454 455 456 457 458 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. 459 459 }; 460 460
Note: See TracChangeset
for help on using the changeset viewer.