GraphicsApi.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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(const char* name, Image* b)
  40. {
  41. if (b) b->release();
  42. return 0;
  43. }
  44. GraphicApiType GraphicsApi::getTyp() const
  45. {
  46. return typ;
  47. }
  48. Vec2<int> GraphicsApi::getBackBufferSize() const
  49. {
  50. return backBufferSize;
  51. }
  52. bool GraphicsApi::isFullScreen() const
  53. {
  54. return fullScreen;
  55. }
  56. // returns the specified model without increased reference counter
  57. Model3DData* GraphicsApi::zModel(const char* name)
  58. {
  59. rwLock.lockRead();
  60. Model3DData* data = modelList->zModel(name);
  61. rwLock.unlockRead();
  62. return data;
  63. }
  64. // returns the specified model with increased reference counter
  65. Model3DData* GraphicsApi::getModel(const char* name)
  66. {
  67. rwLock.lockRead();
  68. Model3DData* data = modelList->getModel(name);
  69. rwLock.unlockRead();
  70. return data;
  71. }
  72. // creates a new empty Model3DData object if the model does not exist yet
  73. Model3DData* GraphicsApi::createModel(const char* name)
  74. {
  75. rwLock.lockRead();
  76. if (modelList->hasModel(name))
  77. {
  78. rwLock.unlockRead();
  79. return 0;
  80. }
  81. Model3DData* model = new Model3DData(nextModelId++);
  82. rwLock.lockWrite();
  83. modelList->addModel(model, name);
  84. rwLock.unlockWrite();
  85. rwLock.unlockRead();
  86. return dynamic_cast<Model3DData*>(model->getThis());
  87. }
  88. // check if a model exists
  89. bool GraphicsApi::hasModel(const char* name)
  90. {
  91. rwLock.lockRead();
  92. bool res = modelList->hasModel(name);
  93. rwLock.unlockRead();
  94. return res;
  95. }