GraphicsApi.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "GraphicsApi.h"
  2. #include "Image.h"
  3. #include "Model3D.h"
  4. #include "Model3DList.h"
  5. #include "Window.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. NativeWindow* 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->getBodySize() : Point(0, 0);
  32. #endif
  33. this->backBufferSize = backBufferSize;
  34. this->fullScreen = fullScreen;
  35. }
  36. void GraphicsApi::beginFrame(bool fill2D, bool fill3D, int fillColor) {}
  37. void GraphicsApi::renderKamera(Cam3D* zKamera) {}
  38. void GraphicsApi::renderKamera(Cam3D* zKamera, Texture* zTarget) {}
  39. Texture* GraphicsApi::createOrGetTexture(
  40. const char* name, Image* b, TextureDirection dir)
  41. {
  42. if (b) b->release();
  43. return 0;
  44. }
  45. GraphicApiType GraphicsApi::getTyp() const
  46. {
  47. return typ;
  48. }
  49. Vec2<int> GraphicsApi::getBackBufferSize() const
  50. {
  51. return backBufferSize;
  52. }
  53. bool GraphicsApi::isFullScreen() const
  54. {
  55. return fullScreen;
  56. }
  57. // returns the specified model without increased reference counter
  58. Model3DData* GraphicsApi::zModel(const char* name)
  59. {
  60. rwLock.lockRead();
  61. Model3DData* data = modelList->zModel(name);
  62. rwLock.unlockRead();
  63. return data;
  64. }
  65. // returns the specified model with increased reference counter
  66. Model3DData* GraphicsApi::getModel(const char* name)
  67. {
  68. rwLock.lockRead();
  69. Model3DData* data = modelList->getModel(name);
  70. rwLock.unlockRead();
  71. return data;
  72. }
  73. // creates a new empty Model3DData object if the model does not exist yet
  74. Model3DData* GraphicsApi::createModel(const char* name)
  75. {
  76. rwLock.lockRead();
  77. if (modelList->hasModel(name))
  78. {
  79. rwLock.unlockRead();
  80. return 0;
  81. }
  82. Model3DData* model = new Model3DData(nextModelId++);
  83. rwLock.lockWrite();
  84. modelList->addModel(model, name);
  85. rwLock.unlockWrite();
  86. rwLock.unlockRead();
  87. return dynamic_cast<Model3DData*>(model->getThis());
  88. }
  89. // check if a model exists
  90. bool GraphicsApi::hasModel(const char* name)
  91. {
  92. rwLock.lockRead();
  93. bool res = modelList->hasModel(name);
  94. rwLock.unlockRead();
  95. return res;
  96. }
  97. bool Framework::GraphicsApi::renderGuiBefore3D() const
  98. {
  99. return false;
  100. }