PolyOpenGLGraphicsInterface.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. Copyright (C) 2015 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "polycode/core/PolyGlobals.h"
  21. #include "polycode/core/PolyRenderer.h"
  22. #include "polycode/core/PolyTexture.h"
  23. #ifdef _WINDOWS
  24. #include <windows.h>
  25. #endif
  26. #if defined(__APPLE__) && defined(__MACH__)
  27. #include <OpenGL/gl.h>
  28. #include <OpenGL/glext.h>
  29. #include <OpenGL/glu.h>
  30. #else
  31. #include <GL/gl.h>
  32. #include <GL/glu.h>
  33. #include <GL/glext.h>
  34. #if defined(_WINDOWS) && !defined(_MINGW)
  35. #include <GL/wglext.h>
  36. #endif
  37. #endif
  38. namespace Polycode {
  39. class _PolyExport OpenGLGraphicsInterface : public GraphicsInterface {
  40. public:
  41. OpenGLGraphicsInterface();
  42. ~OpenGLGraphicsInterface();
  43. // implementation
  44. void createTexture(Texture *texture);
  45. void setViewport(unsigned int x,unsigned int y,unsigned int width, unsigned height);
  46. void clearBuffers(const Color &clearColor, bool colorBuffer, bool depthBuffer, bool stencilBuffer);
  47. void setParamInShader(Shader *shader, ProgramParam *param, LocalShaderParam *localParam);
  48. void setAttributeInShader(Shader *shader, ProgramAttribute *attribute, AttributeBinding *attributeBinding);
  49. void disableAttribute(Shader *shader, const ProgramAttribute &attribute);
  50. void useShader(Shader *shader);
  51. void createProgram(ShaderProgram *program);
  52. void createShader(Shader *shader);
  53. void beginDrawCall();
  54. void endDrawCall();
  55. void setBlendingMode(unsigned int blendingMode);
  56. void bindFramebuffer(Texture *framebufferTexture);
  57. void createVertexBuffer(VertexDataArray *dataArray);
  58. void createIndexBuffer(IndexDataArray *dataArray);
  59. void drawIndices(int type, IndexDataArray *indexArray);
  60. void drawArrays(int type, unsigned int vertexCount);
  61. void enableDepthTest(bool val);
  62. void enableDepthWrite(bool val);
  63. void enableBackfaceCulling(bool val);
  64. void setLineSize(Number lineSize);
  65. protected:
  66. GLuint currentShaderID;
  67. int textureIndex;
  68. static GLenum getGLDrawMode(int polycodeMode);
  69. static int getPolycodeParamType(int glType);
  70. static int getAttributeSize(int glType);
  71. void setUniformMatrix(GLint paramLocation, const Polycode::Matrix4& matrix);
  72. };
  73. }