Canvas.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Copyright (c) 2006-2013 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 "graphics/DrawGable.h"
  23. #include "graphics/Volatile.h"
  24. #include "graphics/Image.h"
  25. #include "graphics/Color.h"
  26. #include "image/Image.h"
  27. #include "image/ImageData.h"
  28. #include "common/math.h"
  29. #include "common/Matrix.h"
  30. #include "OpenGL.h"
  31. namespace love
  32. {
  33. namespace graphics
  34. {
  35. namespace opengl
  36. {
  37. class Canvas : public DrawGable, public Volatile
  38. {
  39. public:
  40. enum TextureType
  41. {
  42. TYPE_NORMAL,
  43. TYPE_HDR,
  44. TYPE_MAX_ENUM
  45. };
  46. Canvas(int width, int height, TextureType texture_type = TYPE_NORMAL);
  47. virtual ~Canvas();
  48. /**
  49. * @param canvases A list of other canvases to temporarily attach to this one,
  50. * to allow drawing to multiple canvases at once.
  51. **/
  52. void startGrab(const std::vector<Canvas *> &canvases);
  53. void startGrab();
  54. void stopGrab();
  55. void clear(const Color &c);
  56. virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
  57. /**
  58. * @copydoc DrawGable::drawg()
  59. **/
  60. void drawg(love::graphics::Geometry *geom, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
  61. /**
  62. * Create and attach a stencil buffer to this Canvas' framebuffer, if necessary.
  63. **/
  64. bool checkCreateStencil();
  65. love::image::ImageData *getImageData(love::image::Image *image);
  66. void getPixel(unsigned char* pixel_rgba, int x, int y);
  67. const std::vector<Canvas *> &getAttachedCanvases() const;
  68. void setFilter(const Image::Filter &f);
  69. Image::Filter getFilter() const;
  70. void setWrap(const Image::Wrap &w);
  71. Image::Wrap getWrap() const;
  72. int getWidth();
  73. int getHeight();
  74. unsigned int getStatus() const
  75. {
  76. return status;
  77. }
  78. TextureType getTextureType() const
  79. {
  80. return texture_type;
  81. }
  82. bool loadVolatile();
  83. void unloadVolatile();
  84. static bool isSupported();
  85. static bool isHDRSupported();
  86. static bool isMultiCanvasSupported();
  87. static bool getConstant(const char *in, TextureType &out);
  88. static bool getConstant(TextureType in, const char *&out);
  89. static Canvas *current;
  90. static void bindDefaultCanvas();
  91. GLuint getTextureName() const
  92. {
  93. return img;
  94. }
  95. private:
  96. friend class Shader;
  97. GLsizei width;
  98. GLsizei height;
  99. GLuint fbo;
  100. GLuint depth_stencil;
  101. GLuint img;
  102. TextureType texture_type;
  103. vertex vertices[4];
  104. GLenum status;
  105. struct
  106. {
  107. Image::Filter filter;
  108. Image::Wrap wrap;
  109. } settings;
  110. std::vector<Canvas *> attachedCanvases;
  111. void setupGrab();
  112. void drawv(const Matrix &t, const vertex *v, GLsizei count = 4, GLenum mode = GL_QUADS, const uint16 *e = 0, GLsizei ecount = 0) const;
  113. static StringMap<TextureType, TYPE_MAX_ENUM>::Entry textureTypeEntries[];
  114. static StringMap<TextureType, TYPE_MAX_ENUM> textureTypes;
  115. };
  116. } // opengl
  117. } // graphics
  118. } // love
  119. #endif // LOVE_GRAPHICS_OPENGL_CANVAS_H