diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-06-16 14:25:22 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-06-19 11:47:56 +0300 |
commit | 8a10fa1c530a0981301d0459a7a697c27a685c48 (patch) | |
tree | 42a055422373a5325c73d990ceb2129419a06b1d /source/blender | |
parent | 7b14065729af4266bffbf70ef0de3bd646ec555c (diff) |
GPUFramebuffer: Add support to attach individual texture layer.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 6 | ||||
-rw-r--r-- | source/blender/gpu/GPU_framebuffer.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer.c | 25 |
4 files changed, 28 insertions, 6 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 25e6bec93b6..3c368944320 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -198,6 +198,7 @@ void DRW_framebuffer_bind(struct GPUFrameBuffer *fb); void DRW_framebuffer_clear(bool color, bool depth, bool stencil, float clear_col[4], float clear_depth); void DRW_framebuffer_read_data(int x, int y, int w, int h, int channels, int slot, float *data); void DRW_framebuffer_texture_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int mip); +void DRW_framebuffer_texture_layer_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int layer, int mip); void DRW_framebuffer_cubeface_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int face, int mip); void DRW_framebuffer_texture_detach(struct GPUTexture *tex); void DRW_framebuffer_blit(struct GPUFrameBuffer *fb_read, struct GPUFrameBuffer *fb_write, bool depth); diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 62a95bcc22b..9483a55ec40 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2089,10 +2089,16 @@ void DRW_framebuffer_texture_attach(struct GPUFrameBuffer *fb, GPUTexture *tex, GPU_framebuffer_texture_attach(fb, tex, slot, mip); } +void DRW_framebuffer_texture_layer_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int layer, int mip) +{ + GPU_framebuffer_texture_layer_attach(fb, tex, slot, layer, mip); +} + void DRW_framebuffer_cubeface_attach(struct GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip) { GPU_framebuffer_texture_cubeface_attach(fb, tex, slot, face, mip); } + void DRW_framebuffer_texture_detach(GPUTexture *tex) { GPU_framebuffer_texture_detach(tex); diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h index 3ba3c6dbd15..6778930f61c 100644 --- a/source/blender/gpu/GPU_framebuffer.h +++ b/source/blender/gpu/GPU_framebuffer.h @@ -51,6 +51,8 @@ void GPU_texture_bind_as_framebuffer(struct GPUTexture *tex); GPUFrameBuffer *GPU_framebuffer_create(void); bool GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int mip); +bool GPU_framebuffer_texture_layer_attach( + GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int layer, int mip); bool GPU_framebuffer_texture_cubeface_attach( GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int face, int mip); void GPU_framebuffer_texture_detach(struct GPUTexture *tex); diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c index ae459eb7d2e..96c740410c5 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.c +++ b/source/blender/gpu/intern/gpu_framebuffer.c @@ -163,7 +163,7 @@ bool GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slo return true; } -bool GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip) +static bool gpu_framebuffer_texture_layer_attach_ex(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip, bool cubemap) { GLenum attachment; GLenum facetarget; @@ -183,8 +183,6 @@ bool GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *fb, GPUTexture *tex } } - BLI_assert(GPU_texture_target(tex) == GL_TEXTURE_CUBE_MAP); - glBindFramebuffer(GL_FRAMEBUFFER, fb->object); GG.currentfb = fb->object; @@ -195,9 +193,13 @@ bool GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *fb, GPUTexture *tex else attachment = GL_COLOR_ATTACHMENT0 + slot; - facetarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face; - - glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, facetarget, GPU_texture_opengl_bindcode(tex), mip); + if (cubemap) { + facetarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; + glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, facetarget, GPU_texture_opengl_bindcode(tex), mip); + } + else { + glFramebufferTextureLayer(GL_FRAMEBUFFER, attachment, GPU_texture_opengl_bindcode(tex), mip, layer); + } if (GPU_texture_depth(tex)) fb->depthtex = tex; @@ -209,6 +211,17 @@ bool GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *fb, GPUTexture *tex return true; } +bool GPU_framebuffer_texture_layer_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip) +{ + return gpu_framebuffer_texture_layer_attach_ex(fb, tex, slot, layer, mip, false); +} + +bool GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip) +{ + BLI_assert(GPU_texture_target(tex) == GL_TEXTURE_CUBE_MAP); + return gpu_framebuffer_texture_layer_attach_ex(fb, tex, slot, face, mip, true); +} + void GPU_framebuffer_texture_detach(GPUTexture *tex) { GLenum attachment; |