Canvas.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Copyright (c) 2006-2016 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_CANVAS_H
  21. #define LOVE_GRAPHICS_OPENGL_CANVAS_H
  22. #include "common/config.h"
  23. #include "graphics/Color.h"
  24. #include "image/Image.h"
  25. #include "image/ImageData.h"
  26. #include "common/Matrix.h"
  27. #include "common/StringMap.h"
  28. #include "common/int.h"
  29. #include "graphics/Texture.h"
  30. #include "graphics/Volatile.h"
  31. #include "OpenGL.h"
  32. namespace love
  33. {
  34. namespace graphics
  35. {
  36. namespace opengl
  37. {
  38. class Canvas : public Texture, public Volatile
  39. {
  40. public:
  41. Canvas(int width, int height, PixelFormat format = PIXELFORMAT_NORMAL, int msaa = 0);
  42. virtual ~Canvas();
  43. // Implements Volatile.
  44. bool loadVolatile() override;
  45. void unloadVolatile() override;
  46. // Implements Drawable.
  47. void draw(const Matrix4 &m) override;
  48. // Implements Texture.
  49. void drawq(Quad *quad, const Matrix4 &m) override;
  50. void setFilter(const Texture::Filter &f) override;
  51. bool setWrap(const Texture::Wrap &w) override;
  52. const void *getHandle() const override;
  53. inline GLenum getStatus() const
  54. {
  55. return status;
  56. }
  57. inline int getMSAA() const
  58. {
  59. return actual_samples;
  60. }
  61. inline int getRequestedMSAA() const
  62. {
  63. return requested_samples;
  64. }
  65. inline ptrdiff_t getMSAAHandle() const
  66. {
  67. return msaa_buffer;
  68. }
  69. inline GLuint getFBO() const
  70. {
  71. return fbo;
  72. }
  73. static PixelFormat getSizedFormat(PixelFormat format);
  74. static bool isSupported();
  75. static bool isMultiFormatMultiCanvasSupported();
  76. static bool isFormatSupported(PixelFormat format);
  77. static int canvasCount;
  78. private:
  79. void drawv(const Matrix4 &t, const Vertex *v);
  80. GLuint fbo;
  81. GLuint texture;
  82. GLuint msaa_buffer;
  83. PixelFormat requested_format;
  84. GLenum status;
  85. int requested_samples;
  86. int actual_samples;
  87. size_t texture_memory;
  88. static bool supportedFormats[PIXELFORMAT_MAX_ENUM];
  89. static bool checkedFormats[PIXELFORMAT_MAX_ENUM];
  90. }; // Canvas
  91. } // opengl
  92. } // graphics
  93. } // love
  94. #endif // LOVE_GRAPHICS_OPENGL_CANVAS_H