GraphicsApi.cpp 2.6 KB

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