Canvas.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/DrawQable.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 DrawQable, public Volatile
  38. {
  39. public:
  40. enum TextureType {
  41. TYPE_NORMAL,
  42. TYPE_HDR,
  43. TYPE_MAX_ENUM
  44. };
  45. Canvas(int width, int height, TextureType texture_type = TYPE_NORMAL);
  46. virtual ~Canvas();
  47. void startGrab();
  48. void stopGrab();
  49. void clear(const Color &c);
  50. virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
  51. /**
  52. * @copydoc DrawQable::drawq()
  53. **/
  54. void drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
  55. love::image::ImageData *getImageData(love::image::Image *image);
  56. void getPixel(unsigned char* pixel_rgba, int x, int y);
  57. void setFilter(const Image::Filter &f);
  58. Image::Filter getFilter() const;
  59. void setWrap(const Image::Wrap &w);
  60. Image::Wrap getWrap() const;
  61. int getWidth();
  62. int getHeight();
  63. unsigned int getStatus() const
  64. {
  65. return status;
  66. }
  67. TextureType getTextureType() const
  68. {
  69. return texture_type;
  70. }
  71. bool loadVolatile();
  72. void unloadVolatile();
  73. static bool isSupported();
  74. static bool isHdrSupported();
  75. static bool getConstant(const char *in, TextureType &out);
  76. static bool getConstant(TextureType in, const char *&out);
  77. static Canvas *current;
  78. static void bindDefaultCanvas();
  79. private:
  80. friend class Shader;
  81. GLuint getTextureName() const
  82. {
  83. return img;
  84. }
  85. GLsizei width;
  86. GLsizei height;
  87. GLuint fbo;
  88. GLuint depth_stencil;
  89. GLuint img;
  90. TextureType texture_type;
  91. vertex vertices[4];
  92. GLenum status;
  93. struct
  94. {
  95. Image::Filter filter;
  96. Image::Wrap wrap;
  97. } settings;
  98. void drawv(const Matrix &t, const vertex *v) const;
  99. static StringMap<TextureType, TYPE_MAX_ENUM>::Entry textureTypeEntries[];
  100. static StringMap<TextureType, TYPE_MAX_ENUM> textureTypes;
  101. };
  102. } // opengl
  103. } // graphics
  104. } // love
  105. #endif // LOVE_GRAPHICS_OPENGL_CANVAS_H