Image.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * Copyright (c) 2006-2012 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_IMAGE_H
  21. #define LOVE_GRAPHICS_OPENGL_IMAGE_H
  22. // LOVE
  23. #include "common/Matrix.h"
  24. #include "common/math.h"
  25. #include "common/config.h"
  26. #include "image/ImageData.h"
  27. #include "graphics/Image.h"
  28. // OpenGL
  29. #include "OpenGL.h"
  30. namespace love
  31. {
  32. namespace graphics
  33. {
  34. namespace opengl
  35. {
  36. /**
  37. * A drawable image based on OpenGL-textures. This class takes ImageData
  38. * objects and create textures on the GPU for fast drawing.
  39. *
  40. * @author Anders Ruud
  41. **/
  42. class Image : public love::graphics::Image
  43. {
  44. public:
  45. /**
  46. * Creates a new Image. Not that anything is ready to use
  47. * before load is called.
  48. *
  49. * @param file The file from which to load the image.
  50. **/
  51. Image(love::image::ImageData *data);
  52. /**
  53. * Destructor. Deletes the hardware texture and other resources.
  54. **/
  55. virtual ~Image();
  56. float getWidth() const;
  57. float getHeight() const;
  58. const vertex *getVertices() const;
  59. love::image::ImageData *getData() const;
  60. /**
  61. * Generate vertices according to a subimage.
  62. *
  63. * Note: out-of-range values will be clamped.
  64. * Note: the vertex colors will not be changed.
  65. *
  66. * @param x The top-left corner of the subimage along the x-axis.
  67. * @param y The top-left corner of the subimage along the y-axis.
  68. * @param w The width of the subimage.
  69. * @param h The height of the subimage.
  70. * @param vertices A vertex array of size four.
  71. **/
  72. void getRectangleVertices(int x, int y, int w, int h, vertex *vertices) const;
  73. /**
  74. * @copydoc Drawable::draw()
  75. **/
  76. void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
  77. /**
  78. * @copydoc DrawQable::drawq()
  79. **/
  80. 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;
  81. /**
  82. * Sets the filter mode.
  83. * @param f The filter mode.
  84. **/
  85. void setFilter(const Image::Filter &f);
  86. const Image::Filter &getFilter() const;
  87. void setWrap(const Image::Wrap &w);
  88. const Image::Wrap &getWrap() const;
  89. void setMipmapSharpness(float sharpness);
  90. float getMipmapSharpness() const;
  91. void bind() const;
  92. bool load();
  93. void unload();
  94. // Implements Volatile.
  95. bool loadVolatile();
  96. void unloadVolatile();
  97. static bool hasNpot();
  98. static bool hasMipmapSupport();
  99. static bool hasMipmapSharpnessSupport();
  100. private:
  101. void drawv(const Matrix &t, const vertex *v) const;
  102. friend class Shader;
  103. GLuint getTextureName() const
  104. {
  105. return texture;
  106. }
  107. // The ImageData from which the texture is created.
  108. love::image::ImageData *data;
  109. // Width and height of the hardware texture.
  110. float width, height;
  111. // OpenGL texture identifier.
  112. GLuint texture;
  113. // The source vertices of the image.
  114. vertex vertices[4];
  115. // Mipmap texture LOD bias value
  116. float mipmapsharpness;
  117. // Implementation-dependent maximum/minimum mipmap sharpness values
  118. float maxmipmapsharpness;
  119. // The image's filter mode
  120. Image::Filter filter;
  121. // The image's wrap mode
  122. Image::Wrap wrap;
  123. bool loadVolatilePOT();
  124. bool loadVolatileNPOT();
  125. void checkMipmapsCreated() const;
  126. }; // Image
  127. } // opengl
  128. } // graphics
  129. } // love
  130. #endif // LOVE_GRAPHICS_OPENGL_IMAGE_H