diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_texture_private.hh')
-rw-r--r-- | source/blender/gpu/intern/gpu_texture_private.hh | 83 |
1 files changed, 79 insertions, 4 deletions
diff --git a/source/blender/gpu/intern/gpu_texture_private.hh b/source/blender/gpu/intern/gpu_texture_private.hh index 6aa2a39046e..5eeb3d9e0f0 100644 --- a/source/blender/gpu/intern/gpu_texture_private.hh +++ b/source/blender/gpu/intern/gpu_texture_private.hh @@ -25,15 +25,88 @@ #include "BLI_assert.h" +#include "gpu_framebuffer_private.hh" + namespace blender { namespace gpu { +typedef enum eGPUTextureFlag { + GPU_TEXFORMAT_DEPTH = (1 << 0), + GPU_TEXFORMAT_STENCIL = (1 << 1), + GPU_TEXFORMAT_INTEGER = (1 << 2), + GPU_TEXFORMAT_FLOAT = (1 << 3), + + GPU_TEXTURE_1D = (1 << 10), + GPU_TEXTURE_2D = (1 << 11), + GPU_TEXTURE_3D = (1 << 12), + GPU_TEXTURE_CUBE = (1 << 13), + GPU_TEXTURE_ARRAY = (1 << 14), + GPU_TEXTURE_BUFFER = (1 << 15), + + GPU_TEXTURE_1D_ARRAY = (GPU_TEXTURE_1D | GPU_TEXTURE_ARRAY), + GPU_TEXTURE_2D_ARRAY = (GPU_TEXTURE_2D | GPU_TEXTURE_ARRAY), + GPU_TEXTURE_CUBE_ARRAY = (GPU_TEXTURE_CUBE | GPU_TEXTURE_ARRAY), + + GPU_TEXTURE_TARGET = (GPU_TEXTURE_1D | GPU_TEXTURE_2D | GPU_TEXTURE_3D | GPU_TEXTURE_CUBE | + GPU_TEXTURE_ARRAY), +} eGPUTextureFlag; + +ENUM_OPERATORS(eGPUTextureFlag) + +#ifdef DEBUG +# define DEBUG_NAME_LEN 64 +#else +# define DEBUG_NAME_LEN 8 +#endif + +/* Maximum number of FBOs a texture can be attached to. */ +#define GPU_TEX_MAX_FBO_ATTACHED 12 + class Texture { public: - /** TODO(fclem): make it a non-static function. */ - static GPUAttachmentType attachment_type(GPUTexture *tex, int slot) + /** Width & Height & Depth. */ + int w = 0, h = 0, d = 0; + /** Number of color/alpha channels. */ + int components = 0; + /** Internal data format and it's characteristics. */ + eGPUTextureFormat format; + eGPUTextureFlag flag; + /** Internal Sampler state. */ + eGPUSamplerState sampler_state; + /** Number of mipmaps this texture has. */ + int mipmaps = 0; + /** Reference counter. */ + int refcount = 0; + /** Width & Height (of source data), optional. */ + int src_w = 0, src_h = 0; + /** Framebuffer references to update on deletion. */ + GPUAttachmentType fb_attachment[GPU_TEX_MAX_FBO_ATTACHED]; + FrameBuffer *fb[GPU_TEX_MAX_FBO_ATTACHED]; + + protected: + /** For debugging */ + char name_[DEBUG_NAME_LEN]; + + public: + Texture(const char *name); + virtual ~Texture(); + + virtual void bind(int slot) = 0; + virtual void update(void *data) = 0; + virtual void update_sub(void *data, int offset[3], int size[3]) = 0; + virtual void generate_mipmap(void) = 0; + virtual void copy_to(Texture *tex) = 0; + + virtual void swizzle_set(char swizzle_mask[4]) = 0; + + /* TODO(fclem) Legacy. Should be removed at some point. */ + virtual uint gl_bindcode_get(void) = 0; + + void attach_to(FrameBuffer *fb); + + GPUAttachmentType attachment_type(int slot) const { - switch (GPU_texture_format(tex)) { + switch (format) { case GPU_DEPTH_COMPONENT32F: case GPU_DEPTH_COMPONENT24: case GPU_DEPTH_COMPONENT16: @@ -44,10 +117,12 @@ class Texture { BLI_assert(slot == 0); return GPU_FB_DEPTH_STENCIL_ATTACHMENT; default: - return static_cast<GPUAttachmentType>(GPU_FB_COLOR_ATTACHMENT0 + slot); + return GPU_FB_COLOR_ATTACHMENT0 + slot; } } }; +#undef DEBUG_NAME_LEN + } // namespace gpu } // namespace blender |