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/gpu | |
parent | 7b14065729af4266bffbf70ef0de3bd646ec555c (diff) |
GPUFramebuffer: Add support to attach individual texture layer.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_framebuffer.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer.c | 25 |
2 files changed, 21 insertions, 6 deletions
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; |