GraphicsApi.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "GraphicsApi.h"
  2. #include "Fenster.h"
  3. #include "Bild.h"
  4. #include "Model3DList.h"
  5. #include "Model3D.h"
  6. using namespace Framework;
  7. GraphicsApi::GraphicsApi( GraphicApiType typ )
  8. : ReferenceCounter()
  9. {
  10. this->typ = typ;
  11. fenster = 0;
  12. backBufferSize = Vec2<int>( 0, 0 );
  13. fullScreen = 0;
  14. nextModelId = 0;
  15. modelList = new Model3DList();
  16. }
  17. GraphicsApi::~GraphicsApi()
  18. {
  19. #ifdef _WIN32
  20. modelList->release();
  21. if( fenster )
  22. fenster->release();
  23. #endif
  24. }
  25. void GraphicsApi::initialize( WFenster* fenster, Vec2<int> backBufferSize, bool fullScreen )
  26. {
  27. #ifdef _WIN32
  28. if( this->fenster )
  29. this->fenster->release();
  30. this->fenster = fenster;
  31. if( !backBufferSize.x || !backBufferSize.y )
  32. backBufferSize = fenster ? fenster->getKörperGröße() : Punkt( 0, 0 );
  33. #endif
  34. this->backBufferSize = backBufferSize;
  35. this->fullScreen = fullScreen;
  36. }
  37. void GraphicsApi::setBackBufferSize( Vec2< int > size )
  38. {
  39. backBufferSize = size;
  40. update();
  41. }
  42. void GraphicsApi::setFullScreen( bool fullScreen )
  43. {
  44. this->fullScreen = fullScreen;
  45. update();
  46. }
  47. void GraphicsApi::beginFrame( bool fill2D, bool fill3D, int fillColor )
  48. {}
  49. void GraphicsApi::renderKamera( Kam3D* zKamera )
  50. {}
  51. Textur* GraphicsApi::createOrGetTextur( const char* name, Bild* b )
  52. {
  53. if( b )
  54. b->release();
  55. return 0;
  56. }
  57. GraphicApiType GraphicsApi::getTyp() const
  58. {
  59. return typ;
  60. }
  61. Vec2< int > GraphicsApi::getBackBufferSize() const
  62. {
  63. return backBufferSize;
  64. }
  65. bool GraphicsApi::isFullScreen() const
  66. {
  67. return fullScreen;
  68. }
  69. // returns the specified model without increased reference counter
  70. Model3DData* GraphicsApi::zModel( const char* name )
  71. {
  72. cs.lock();
  73. Model3DData* data = modelList->zModel( name );
  74. cs.unlock();
  75. return data;
  76. }
  77. // returns the specified model with increased reference counter
  78. Model3DData* GraphicsApi::getModel( const char* name )
  79. {
  80. cs.lock();
  81. Model3DData* data = modelList->getModel( name );
  82. cs.unlock();
  83. return data;
  84. }
  85. // creates a new empty Model3DData object if the model does not exist yet
  86. Model3DData* GraphicsApi::createModel( const char* name )
  87. {
  88. cs.lock();
  89. if( modelList->hatModel( name ) )
  90. {
  91. cs.unlock();
  92. return 0;
  93. }
  94. Model3DData* model = new Model3DData( createVertexBuffer(), createIndexBuffer(), nextModelId++ );
  95. modelList->addModel( model, name );
  96. cs.unlock();
  97. return dynamic_cast<Model3DData*>(model->getThis());
  98. }
  99. // check if a model exists
  100. bool GraphicsApi::hasModel( const char* name )
  101. {
  102. cs.lock();
  103. bool res = modelList->hatModel( name );
  104. cs.unlock();
  105. return res;
  106. }