- Timestamp:
- Jan 29, 2009, 7:12:27 PM (16 years ago)
- Location:
- code/branches/buildsystem2/src/ogreceguirenderer
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUIRenderer.cpp
r2569 r2602 1 1 /************************************************************************ 2 3 4 5 6 2 filename: OgreCEGUIRenderer.cpp 3 created: 11/5/2004 4 author: Paul D Turner 5 6 purpose: Implementation of Renderer class for Ogre engine 7 7 *************************************************************************/ 8 8 /************************************************************************* … … 44 44 { 45 45 /************************************************************************* 46 46 Constants definitions 47 47 *************************************************************************/ 48 48 const size_t OgreCEGUIRenderer::VERTEX_PER_QUAD = 6; … … 52 52 53 53 /************************************************************************* 54 54 Utility function to create a render operation and vertex buffer to render quads 55 55 *************************************************************************/ 56 56 static void createQuadRenderOp(Ogre::RenderOperation &d_render_op, … … 59 59 using namespace Ogre; 60 60 // Create and initialise the Ogre specific parts required for use in rendering later. 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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, 75 75 HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, false); 76 76 77 78 79 80 81 82 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; 83 83 } 84 84 … … 92 92 93 93 /************************************************************************* 94 94 Constructor 95 95 *************************************************************************/ 96 96 OgreCEGUIRenderer::OgreCEGUIRenderer(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads) 97 97 { 98 99 } 100 101 102 /************************************************************************* 103 98 constructor_impl(window, queue_id, post_queue, max_quads); 99 } 100 101 102 /************************************************************************* 103 Constructor (specifying scene manager) 104 104 *************************************************************************/ 105 105 OgreCEGUIRenderer::OgreCEGUIRenderer(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads, Ogre::SceneManager* scene_manager) 106 106 { 107 108 109 110 111 } 112 113 114 /************************************************************************* 115 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 116 116 *************************************************************************/ 117 117 OgreCEGUIRenderer::~OgreCEGUIRenderer(void) 118 118 { 119 120 121 122 123 124 125 126 127 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); 128 128 destroyQuadRenderOp(d_direct_render_op, d_direct_buffer); 129 129 130 131 } 132 133 134 /************************************************************************* 135 130 destroyAllTextures(); 131 } 132 133 134 /************************************************************************* 135 add's a quad to the list to be rendered 136 136 *************************************************************************/ 137 137 void OgreCEGUIRenderer::addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode) 138 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 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 } 178 178 } 179 179 … … 186 186 { 187 187 // 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 { 197 190 /// Quad list needs to be sorted and thus the vertex buffer rebuilt. If not, we can 198 191 /// reuse the vertex buffer resulting in a nice speed gain. … … 319 312 /// Render the buffer 320 313 d_bufferPos = 0; 321 314 bool first = true; 322 315 323 316 // Iterate over each quad in the list and render it … … 332 325 const QuadInfo& quad = (*i); 333 326 if (d_currTexture != quad.texture) 334 327 { 335 328 /// If it has a different texture, render this quad in next operation 336 337 338 339 329 /// also need to reset render states 330 first = true; 331 break; 332 } 340 333 d_bufferPos += VERTEX_PER_QUAD; 341 334 } … … 343 336 /// Set texture, and do the render 344 337 d_render_sys->_setTexture(0, true, d_currTexture); 345 346 347 348 349 338 if (first) 339 { 340 initRenderStates(); 341 first = false; 342 } 350 343 d_render_sys->_render(d_render_op); 351 344 } 352 345 353 346 } 354 347 /// Count frames to check if utilization of vertex buffer was below half the capacity for 500,000 frames 355 348 if(d_bufferPos < d_buffer->getNumVertices()/2) … … 361 354 362 355 /************************************************************************* 363 356 clear the queue 364 357 *************************************************************************/ 365 358 void OgreCEGUIRenderer::clearRenderList(void) 366 359 { 367 368 369 } 370 371 372 /************************************************************************* 373 360 d_sorted = true; 361 d_quadlist.clear(); 362 } 363 364 365 /************************************************************************* 366 create an empty texture 374 367 *************************************************************************/ 375 368 Texture* OgreCEGUIRenderer::createTexture(void) 376 369 { 377 378 379 380 } 381 382 383 /************************************************************************* 384 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. 385 378 *************************************************************************/ 386 379 Texture* OgreCEGUIRenderer::createTexture(const String& filename, const String& resourceGroup) 387 380 { 388 389 390 391 392 } 393 394 395 /************************************************************************* 396 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 397 390 *************************************************************************/ 398 391 Texture* OgreCEGUIRenderer::createTexture(float size) 399 392 { 400 401 402 403 404 } 405 406 407 /************************************************************************* 408 393 OgreCEGUITexture* tex = (OgreCEGUITexture*)createTexture(); 394 tex->setOgreTextureSize((uint)size); 395 396 return tex; 397 } 398 399 400 /************************************************************************* 401 destroy the given texture 409 402 *************************************************************************/ 410 403 void OgreCEGUIRenderer::destroyTexture(Texture* texture) 411 404 { 412 413 414 415 416 417 418 419 } 420 421 422 /************************************************************************* 423 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 424 417 *************************************************************************/ 425 418 void OgreCEGUIRenderer::destroyAllTextures(void) 426 419 { 427 428 429 430 431 } 432 433 434 /************************************************************************* 435 420 while (!d_texturelist.empty()) 421 { 422 destroyTexture(*(d_texturelist.begin())); 423 } 424 } 425 426 427 /************************************************************************* 428 setup states etc 436 429 *************************************************************************/ 437 430 void OgreCEGUIRenderer::initRenderStates(void) 438 431 { 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 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); 471 464 } 472 465 … … 474 467 475 468 /************************************************************************* 476 469 sort quads list according to texture 477 470 *************************************************************************/ 478 471 void OgreCEGUIRenderer::sortQuads(void) 479 472 { 480 481 482 483 473 if (!d_sorted) 474 { 475 d_sorted = true; 476 } 484 477 485 478 } … … 490 483 void OgreCEGUIRenderer::renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode) 491 484 { 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. 519 506 uint32 topLeftCol = colourToOgre(colours.d_bottom_left); 520 507 uint32 topRightCol = colourToOgre(colours.d_bottom_right); … … 522 509 uint32 bottomRightCol= colourToOgre(colours.d_top_right); 523 510 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 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(); 611 598 612 599 // 613 614 615 616 617 618 619 620 621 } 622 623 /************************************************************************* 624 625 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. 626 613 *************************************************************************/ 627 614 uint32 OgreCEGUIRenderer::colourToOgre(const colour& col) const 628 615 { 629 616 Ogre::ColourValue cv(col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()); 630 617 631 618 uint32 final; 632 633 634 635 } 636 637 638 /************************************************************************* 639 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. 640 627 *************************************************************************/ 641 628 void OgreCEGUIRenderer::setTargetSceneManager(Ogre::SceneManager* scene_manager) 642 629 { 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 } 658 659 660 /************************************************************************* 661 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. 662 649 *************************************************************************/ 663 650 void OgreCEGUIRenderer::setTargetRenderQueue(Ogre::uint8 queue_id, bool post_queue) 664 651 { 665 666 667 668 669 670 671 672 673 674 } 675 676 677 /************************************************************************* 678 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 679 666 *************************************************************************/ 680 667 void OgreCEGUIRenderer::constructor_impl(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads) 681 668 { 682 683 684 685 686 687 688 689 690 691 692 693 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(); 694 681 // set ID string 695 682 d_identifierString = "CEGUI::OgreRenderer - Official Ogre based renderer module for CEGUI"; 696 683 697 684 // Create and initialise the Ogre specific parts required for use in rendering later. 698 685 // Main GUI 699 686 createQuadRenderOp(d_render_op, d_buffer, VERTEXBUFFER_INITIAL_CAPACITY); … … 703 690 createQuadRenderOp(d_direct_render_op, d_direct_buffer, VERTEX_PER_QUAD); 704 691 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 } 732 733 734 /************************************************************************* 735 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 736 723 *************************************************************************/ 737 724 Texture* OgreCEGUIRenderer::createTexture(Ogre::TexturePtr& texture) 738 725 { 739 740 741 742 743 744 745 746 747 748 } 749 750 /************************************************************************* 751 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 752 739 *************************************************************************/ 753 740 ResourceProvider* OgreCEGUIRenderer::createResourceProvider(void) … … 762 749 void OgreCEGUIRenderer::setDisplaySize(const Size& sz) 763 750 { 764 765 766 767 768 769 770 771 772 } 773 774 /************************************************************************* 775 776 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 777 764 *************************************************************************/ 778 765 void CEGUIRQListener::renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, 779 780 { 781 782 783 784 766 bool& skipThisQueue) 767 { 768 if ((!d_post_queue) && (d_queue_id == id)) 769 { 770 CEGUI::System::getSingleton().renderGUI(); 771 } 785 772 786 773 } … … 793 780 void CEGUIRQListener::renderQueueEnded(Ogre::uint8 id, const Ogre::String& invocation, bool& repeatThisQueue) 794 781 { 795 796 797 798 782 if ((d_post_queue) && (d_queue_id == id)) 783 { 784 CEGUI::System::getSingleton().renderGUI(); 785 } 799 786 800 787 } -
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 -
code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUIResourceProvider.cpp
r2569 r2602 1 1 /************************************************************************ 2 3 4 2 filename: OgreCEGUIResourceProvider.cpp 3 created: 8/7/2004 4 author: James '_mental_' O'Sullivan 5 5 6 6 purpose: Implements the Resource Provider common functionality 7 7 *************************************************************************/ 8 8 /************************************************************************* … … 70 70 Ogre::ResourceGroupManager::getSingleton().openResource(filename.c_str(), orpGroup.c_str()); 71 71 72 73 72 if (input.isNull()) 73 { 74 74 throw InvalidRequestException((utf8*) 75 75 "OgreCEGUIResourceProvider::loadRawDataContainer - Unable to open resource file '" + filename + (utf8*)"' in resource group '" + orpGroup + (utf8*)"'."); 76 76 } 77 77 78 79 78 Ogre::String buf = input->getAsString(); 79 const size_t memBuffSize = buf.length(); 80 80 81 81 unsigned char* mem = new unsigned char[memBuffSize]; … … 86 86 } 87 87 88 89 90 91 92 93 94 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 } 97 97 } // End of CEGUI namespace section -
code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUIResourceProvider.h
r2569 r2602 1 1 /************************************************************************ 2 3 4 5 6 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 7 7 *************************************************************************/ 8 8 /************************************************************************* … … 36 36 { 37 37 public: 38 39 40 41 38 /************************************************************************* 39 Construction and Destruction 40 *************************************************************************/ 41 OgreCEGUIResourceProvider(); 42 42 43 43 ~OgreCEGUIResourceProvider(void) {} 44 44 45 45 // void loadInputSourceContainer(const String& filename, InputSourceContainer& output); -
code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUITexture.cpp
r2569 r2602 1 1 /************************************************************************ 2 3 4 5 6 2 filename: OgreCEGUITexture.cpp 3 created: 11/5/2004 4 author: Paul D Turner 5 6 purpose: Implementation of Texture using Ogre engine 7 7 *************************************************************************/ 8 8 /************************************************************************* … … 36 36 { 37 37 /************************************************************************* 38 38 Static data definition / initialisation 39 39 *************************************************************************/ 40 40 uint32 OgreCEGUITexture::d_texturenumber = 0; … … 42 42 43 43 /************************************************************************* 44 44 Constructor 45 45 *************************************************************************/ 46 46 OgreCEGUITexture::OgreCEGUITexture(Renderer* owner) : 47 48 { 49 50 51 } 52 53 54 /************************************************************************* 55 47 Texture(owner) 48 { 49 d_ogre_texture.setNull(); 50 d_isLinked = false; 51 } 52 53 54 /************************************************************************* 55 Destructor 56 56 *************************************************************************/ 57 57 OgreCEGUITexture::~OgreCEGUITexture(void) 58 58 { 59 60 } 61 62 63 /************************************************************************* 64 65 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. 66 66 *************************************************************************/ 67 67 void OgreCEGUITexture::loadFromFile(const String& filename, const String& resourceGroup) 68 68 { 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 { 91 91 String orpGroup; 92 92 if (resourceGroup.empty()) … … 100 100 } 101 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 } 125 126 127 /************************************************************************* 128 129 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. 130 130 *************************************************************************/ 131 131 … … 144 144 void OgreCEGUITexture::loadFromMemory(const void* buffPtr, uint buffWidth, uint buffHeight, PixelFormat pixelFormat) 145 145 { 146 147 148 149 150 151 146 using namespace Ogre; 147 148 // get rid of old texture 149 freeOgreTexture(); 150 151 // wrap input buffer with an Ogre DataChunk 152 152 uint32 bytesize = ((buffWidth * sizeof(uint32)) * buffHeight); 153 153 … … 161 161 DataStreamPtr odc(new MemoryDataStream(static_cast<void*>(swappedBuffer), bytesize, false)); 162 162 #else 163 163 DataStreamPtr odc(new MemoryDataStream(const_cast<void*>(buffPtr), bytesize, false)); 164 164 #endif 165 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 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. 192 192 *************************************************************************/ 193 193 void OgreCEGUITexture::setOgreTextureSize(uint size) 194 194 { 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 } 216 217 218 /************************************************************************* 219 220 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) 221 221 *************************************************************************/ 222 222 void OgreCEGUITexture::freeOgreTexture(void) 223 223 { 224 225 226 227 228 229 } 230 231 232 /************************************************************************* 233 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. 234 234 *************************************************************************/ 235 235 Ogre::String OgreCEGUITexture::getUniqueName(void) 236 236 { 237 237 Ogre::String str; 238 238 239 239 #ifdef CEGUI_USEOLDOGRESTRING 240 240 str << "_cegui_ogre_" << d_texturenumber; 241 241 #else 242 243 244 242 Ogre::StringUtil::StrStreamType strstream; 243 strstream << "_cegui_ogre_" << d_texturenumber; 244 str = strstream.str(); 245 245 #endif 246 246 247 248 249 250 } 251 252 253 /************************************************************************* 254 247 ++d_texturenumber; 248 249 return str; 250 } 251 252 253 /************************************************************************* 254 Set the internal Ogre::Texture object. 255 255 *************************************************************************/ 256 256 void OgreCEGUITexture::setOgreTexture(Ogre::TexturePtr& texture) 257 257 { 258 259 260 261 262 263 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; 264 264 } 265 265 -
code/branches/buildsystem2/src/ogreceguirenderer/OgreCEGUITexture.h
r2569 r2602 1 1 /************************************************************************ 2 3 4 5 6 2 filename: OgreCEGUITexture.h 3 created: 11/5/2004 4 author: Paul D Turner 5 6 purpose: Interface to Texture implemented via Ogre engine 7 7 *************************************************************************/ 8 8 /************************************************************************* … … 37 37 /*! 38 38 \brief 39 39 Texture class that is created by OgreCEGUIRenderer objects 40 40 */ 41 41 class _OgrePrivate OgreCEGUITexture : public Texture 42 42 { 43 43 private: 44 45 46 47 48 49 50 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); 51 51 52 52 53 54 55 56 57 53 /************************************************************************* 54 Construction & Destruction (by Renderer object only) 55 *************************************************************************/ 56 OgreCEGUITexture(Renderer* owner); 57 virtual ~OgreCEGUITexture(void); 58 58 59 59 public: 60 61 62 60 /*! 61 \brief 62 Returns the current pixel width of the texture 63 63 64 65 66 67 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;} 68 68 69 69 70 71 72 70 /*! 71 \brief 72 Returns the current pixel height of the texture 73 73 74 75 76 77 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;} 78 78 79 79 80 81 82 80 /*! 81 \brief 82 Loads the specified image file into the texture. The texture is resized as required to hold the image. 83 83 84 85 84 \param filename 85 The filename of the image file that is to be loaded into the texture 86 86 87 88 89 90 87 \return 88 Nothing. 89 */ 90 virtual void loadFromFile(const String& filename, const String& resourceGroup); 91 91 92 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 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); 113 113 114 114 115 116 117 115 /*! 116 \brief 117 Return a pointer to the internal Ogre::Texture object 118 118 119 120 121 122 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;} 123 123 124 124 125 126 127 125 /*! 126 \brief 127 set the size of the internal Ogre texture. Previous Ogre texture is lost. 128 128 129 130 129 \param size 130 pixel size of the new internal texture. This will be rounded up to a power of 2. 131 131 132 133 134 135 132 \return 133 Nothing. 134 */ 135 void setOgreTextureSize(uint size); 136 136 137 137 138 139 140 138 /*! 139 \brief 140 Set the internal Ogre::TexturePtr object. 141 141 142 143 142 \param texture 143 Reference to an Ogre::TexturePtr object that is to be used by this Texture object. 144 144 145 146 147 148 145 \return 146 Nothing. 147 */ 148 void setOgreTexture(Ogre::TexturePtr& texture); 149 149 150 150 151 151 private: 152 153 154 155 156 152 /************************************************************************* 153 Implementation Functions 154 *************************************************************************/ 155 // safely free Ogre::Texture texture (can be called multiple times with no ill effect) 156 void freeOgreTexture(void); 157 157 158 159 158 // return a Ogre::string that contains a unique name. 159 Ogre::String getUniqueName(void); 160 160 161 161 162 163 164 165 162 /************************************************************************* 163 Implementation Data 164 *************************************************************************/ 165 static uint32 d_texturenumber; //!< Counter used to provide unique texture names. 166 166 167 167 Ogre::TexturePtr d_ogre_texture; //!< The 'real' texture. 168 168 169 170 169 ushort d_width; //!< cached width of the texture 170 ushort d_height; //!< cached height of the texture 171 171 172 172 bool d_isLinked; //!< True if we are linked to a texture we did not actually create. 173 173 }; 174 174
Note: See TracChangeset
for help on using the changeset viewer.