BsGLPixelBuffer.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. #include "BsPixelBuffer.h"
  4. namespace BansheeEngine
  5. {
  6. class GLTextureBuffer;
  7. class BS_RSGL_EXPORT GLPixelBuffer: public PixelBuffer
  8. {
  9. public:
  10. // Upload a box of pixels to this buffer on the card
  11. virtual void upload(const PixelData &data, const PixelVolume &dest);
  12. // Download a box of pixels from the card
  13. virtual void download(const PixelData &data);
  14. virtual void blitFromTexture(GLTextureBuffer *src);
  15. virtual void blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox);
  16. protected:
  17. /// Lock a box
  18. PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options);
  19. /// Unlock a box
  20. void unlockImpl(void);
  21. // Internal buffer; either on-card or in system memory, freed/allocated on demand
  22. // depending on buffer usage
  23. PixelData mBuffer;
  24. GLenum mGLInternalFormat; // GL internal format
  25. GpuLockOptions mCurrentLockOptions;
  26. // Buffer allocation/freeage
  27. void allocateBuffer();
  28. void freeBuffer();
  29. public:
  30. /// Should be called by HardwareBufferManager
  31. GLPixelBuffer(UINT32 mWidth, UINT32 mHeight, UINT32 mDepth,
  32. PixelFormat mFormat,
  33. GpuBufferUsage usage);
  34. ~GLPixelBuffer();
  35. /** Bind surface to frame buffer. Needs FBO extension.
  36. */
  37. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  38. GLenum getGLFormat() { return mGLInternalFormat; }
  39. };
  40. /** Texture surface.
  41. */
  42. class BS_RSGL_EXPORT GLTextureBuffer: public GLPixelBuffer
  43. {
  44. public:
  45. /** Texture constructor */
  46. GLTextureBuffer(const String &baseName, GLenum target, GLuint id, GLint face,
  47. GLint level, GpuBufferUsage usage, bool softwareMipmap, bool writeGamma, UINT32 multisampleCount);
  48. ~GLTextureBuffer();
  49. /// @copydoc HardwarePixelBuffer::bindToFramebuffer
  50. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  51. /// Upload a box of pixels to this buffer on the card
  52. virtual void upload(const PixelData &data, const PixelVolume &dest);
  53. // Download a box of pixels from the card
  54. virtual void download(const PixelData &data);
  55. /// Copy from framebuffer
  56. void copyFromFramebuffer(UINT32 zoffset);
  57. void blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox);
  58. protected:
  59. // In case this is a texture level
  60. GLenum mTarget;
  61. GLenum mFaceTarget; // same as mTarget in case of GL_TEXTURE_xD, but cubemap face for cubemaps
  62. GLuint mTextureID;
  63. GLint mFace;
  64. GLint mLevel;
  65. bool mSoftwareMipmap; // Use GLU for mip mapping
  66. };
  67. /** Renderbuffer surface. Needs FBO extension.
  68. */
  69. class BS_RSGL_EXPORT GLRenderBuffer: public GLPixelBuffer
  70. {
  71. public:
  72. GLRenderBuffer(GLenum format, UINT32 width, UINT32 height, GLsizei numSamples);
  73. ~GLRenderBuffer();
  74. /// @copydoc GLHardwarePixelBuffer::bindToFramebuffer
  75. virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
  76. protected:
  77. // In case this is a render buffer
  78. GLuint mRenderbufferID;
  79. };
  80. };