Graphics.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * Copyright (c) 2006-2017 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #ifndef LOVE_GRAPHICS_OPENGL_GRAPHICS_H
  21. #define LOVE_GRAPHICS_OPENGL_GRAPHICS_H
  22. // STD
  23. #include <stack>
  24. #include <vector>
  25. #include <unordered_map>
  26. // OpenGL
  27. #include "OpenGL.h"
  28. // LOVE
  29. #include "graphics/Graphics.h"
  30. #include "graphics/Color.h"
  31. #include "image/Image.h"
  32. #include "image/ImageData.h"
  33. #include "Image.h"
  34. #include "SpriteBatch.h"
  35. #include "ParticleSystem.h"
  36. #include "Canvas.h"
  37. #include "Shader.h"
  38. #include "Mesh.h"
  39. namespace love
  40. {
  41. namespace graphics
  42. {
  43. namespace opengl
  44. {
  45. class Graphics final : public love::graphics::Graphics
  46. {
  47. public:
  48. Graphics();
  49. virtual ~Graphics();
  50. // Implements Module.
  51. const char *getName() const override;
  52. love::graphics::Image *newImage(const Image::Slices &data, const Image::Settings &settings) override;
  53. love::graphics::Image *newImage(TextureType textype, PixelFormat format, int width, int height, int slices, const Image::Settings &settings) override;
  54. love::graphics::SpriteBatch *newSpriteBatch(Texture *texture, int size, vertex::Usage usage) override;
  55. love::graphics::ParticleSystem *newParticleSystem(Texture *texture, int size) override;
  56. love::graphics::Canvas *newCanvas(const Canvas::Settings &settings) override;
  57. love::graphics::Shader *newShader(const Shader::ShaderSource &source) override;
  58. love::graphics::Buffer *newBuffer(size_t size, const void *data, BufferType type, vertex::Usage usage, uint32 mapflags) override;
  59. love::graphics::Mesh *newMesh(const std::vector<Vertex> &vertices, Mesh::DrawMode drawmode, vertex::Usage usage) override;
  60. love::graphics::Mesh *newMesh(int vertexcount, Mesh::DrawMode drawmode, vertex::Usage usage) override;
  61. love::graphics::Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, int vertexcount, Mesh::DrawMode drawmode, vertex::Usage usage) override;
  62. love::graphics::Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, const void *data, size_t datasize, Mesh::DrawMode drawmode, vertex::Usage usage) override;
  63. love::graphics::Text *newText(love::graphics::Font *font, const std::vector<Font::ColoredString> &text = {}) override;
  64. void setViewportSize(int width, int height, int pixelwidth, int pixelheight) override;
  65. bool setMode(int width, int height, int pixelwidth, int pixelheight, bool windowhasstencil) override;
  66. void unSetMode() override;
  67. void setActive(bool active) override;
  68. void flushStreamDraws() override;
  69. void clear(OptionalColorf color, OptionalInt stencil, OptionalDouble depth) override;
  70. void clear(const std::vector<OptionalColorf> &colors, OptionalInt stencil, OptionalDouble depth) override;
  71. void discard(const std::vector<bool> &colorbuffers, bool depthstencil) override;
  72. void present(void *screenshotCallbackData) override;
  73. void setColor(Colorf c) override;
  74. void setCanvas(const RenderTargets &rts) override;
  75. void setCanvas() override;
  76. void setScissor(const Rect &rect) override;
  77. void setScissor() override;
  78. void drawToStencilBuffer(StencilAction action, int value) override;
  79. void stopDrawToStencilBuffer() override;
  80. void setStencilTest(CompareMode compare, int value) override;
  81. void setStencilTest() override;
  82. void setColorMask(ColorMask mask) override;
  83. void setBlendMode(BlendMode mode, BlendAlpha alphamode) override;
  84. void setPointSize(float size) override;
  85. void setWireframe(bool enable) override;
  86. bool isSupported(Feature feature) const override;
  87. bool isTextureTypeSupported(TextureType textype) const override;
  88. double getSystemLimit(SystemLimit limittype) const override;
  89. bool isCanvasFormatSupported(PixelFormat format) const override;
  90. bool isCanvasFormatSupported(PixelFormat format, bool readable) const override;
  91. bool isImageFormatSupported(PixelFormat format) const override;
  92. Renderer getRenderer() const override;
  93. RendererInfo getRendererInfo() const override;
  94. Shader::Language getShaderLanguageTarget() const override;
  95. private:
  96. love::graphics::StreamBuffer *newStreamBuffer(BufferType type, size_t size) override;
  97. void getAPIStats(int &drawcalls, int &shaderswitches) const override;
  98. void endPass();
  99. void bindCachedFBO(const RenderTargets &targets);
  100. void discard(OpenGL::FramebufferTarget target, const std::vector<bool> &colorbuffers, bool depthstencil);
  101. void setDebug(bool enable);
  102. std::unordered_map<uint32, GLuint> framebufferObjects;
  103. QuadIndices *quadIndices;
  104. bool windowHasStencil;
  105. GLuint mainVAO;
  106. }; // Graphics
  107. } // opengl
  108. } // graphics
  109. } // love
  110. #endif // LOVE_GRAPHICS_OPENGL_GRAPHICS_H