GLRenderDevice.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #pragma once
  2. #include "Common.h"
  3. #include "util/Dictionary.h"
  4. #ifdef BF_PLATFORM_OPENGL_ES2
  5. #include <SDL2/SDL_opengles2.h>
  6. #else
  7. #include <SDL2/SDL_opengl.h>
  8. #endif
  9. #include "gfx/Shader.h"
  10. #include "gfx/Texture.h"
  11. #include "gfx/RenderDevice.h"
  12. #include "gfx/DrawLayer.h"
  13. struct SDL_Window;
  14. NS_BF_BEGIN;
  15. class BFApp;
  16. class GLRenderDevice;
  17. class GLTexture : public Texture
  18. {
  19. public:
  20. GLRenderDevice* mRenderDevice;
  21. GLuint mGLTexture;
  22. GLuint mGLTexture2;
  23. ImageData* mImageData;
  24. //IGL10RenderTargetView* mGLRenderTargetView;
  25. public:
  26. GLTexture();
  27. ~GLTexture();
  28. virtual void PhysSetAsTarget();
  29. virtual void Blt(ImageData* imageData, int x, int y) override;
  30. };
  31. class GLShaderParam : public ShaderParam
  32. {
  33. public:
  34. GLint mGLVariable;
  35. public:
  36. GLShaderParam();
  37. ~GLShaderParam();
  38. virtual void SetTexture(Texture* texture);
  39. virtual void SetFloat4(float x, float y, float z, float w) override;
  40. };
  41. typedef Dictionary<String, GLShaderParam*> GLShaderParamMap;
  42. class GLShader : public Shader
  43. {
  44. public:
  45. //IGL10Effect* mGLEffect;
  46. GLuint mGLVertexShader;
  47. GLuint mGLFragmentShader;
  48. GLuint mGLProgram;
  49. GLint mAttribPosition;
  50. GLint mAttribTexCoord0;
  51. GLint mAttribColor;
  52. GLint mAttribTex0;
  53. GLint mAttribTex1;
  54. GLShaderParamMap mParamsMap;
  55. public:
  56. GLShader();
  57. ~GLShader();
  58. virtual ShaderParam* GetShaderParam(const StringImpl& name) override;
  59. };
  60. class GLSetTextureCmd : public RenderCmd
  61. {
  62. public:
  63. int mTextureIdx;
  64. Texture* mTexture;
  65. public:
  66. virtual void Render(RenderDevice* renderDevice, RenderWindow* renderWindow) override;
  67. };
  68. class GLDrawBatch : public DrawBatch
  69. {
  70. public:
  71. //IGL10Buffer* mGLBuffer;
  72. public:
  73. GLDrawBatch();
  74. ~GLDrawBatch();
  75. //virtual void Lock();
  76. virtual void Render(RenderDevice* renderDevice, RenderWindow* renderWindow) override;
  77. };
  78. class GLDrawLayer : public DrawLayer
  79. {
  80. public:
  81. virtual DrawBatch* CreateDrawBatch();
  82. virtual RenderCmd* CreateSetTextureCmd(int textureIdx, Texture* texture) override;
  83. virtual void SetShaderConstantData(int usageIdx, int slotIdx, void* constData, int size) override;
  84. public:
  85. GLDrawLayer();
  86. ~GLDrawLayer();
  87. };
  88. class GLRenderWindow : public RenderWindow
  89. {
  90. public:
  91. SDL_Window* mSDLWindow;
  92. GLRenderDevice* mRenderDevice;
  93. bool mResizePending;
  94. int mPendingWidth;
  95. int mPendingHeight;
  96. public:
  97. virtual void PhysSetAsTarget();
  98. public:
  99. GLRenderWindow(GLRenderDevice* renderDevice, SDL_Window* sdlWindow);
  100. ~GLRenderWindow();
  101. void SetAsTarget() override;
  102. void Resized() override;
  103. virtual void Present() override;
  104. void CopyBitsTo(uint32* dest, int width, int height);
  105. };
  106. class GLRenderDevice : public RenderDevice
  107. {
  108. public:
  109. GLuint mGLVAO;
  110. GLuint mGLVertexBuffer;
  111. GLuint mGLIndexBuffer;
  112. GLuint mBlankTexture;
  113. GLShader* mCurShader;
  114. bool mHasVSync;
  115. GLDrawBatch* mFreeBatchHead;
  116. public:
  117. //virtual void PhysSetAdditive(bool additive);
  118. //virtual void PhysSetShader(Shader* shaderPass);
  119. virtual void PhysSetRenderWindow(RenderWindow* renderWindow);
  120. virtual void PhysSetRenderState(RenderState* renderState) override;
  121. virtual void PhysSetRenderTarget(Texture* renderTarget) override;
  122. public:
  123. GLRenderDevice();
  124. virtual ~GLRenderDevice();
  125. bool Init(BFApp* app) override;
  126. void FrameStart() override;
  127. void FrameEnd() override;
  128. Texture* LoadTexture(ImageData* imageData, int flags) override;
  129. Shader* LoadShader(const StringImpl& fileName, VertexDefinition* vertexDefinition) override;
  130. Texture* CreateRenderTarget(int width, int height, bool destAlpha) override;
  131. virtual Texture* CreateDynTexture(int width, int height) override { return NULL; }
  132. virtual void SetRenderState(RenderState* renderState) override;
  133. /*void SetShader(Shader* shader) override;
  134. virtual void SetClip(float x, float y, float width, float height) override;
  135. virtual void DisableClip() override;*/
  136. };
  137. NS_BF_END;