diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-06-08 21:12:58 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-06-09 02:15:17 +0300 |
commit | 4abb3c1bc45e31fd340d695c0f82e799370736a5 (patch) | |
tree | 32ecc89115b048700500dcbbe70f653237e2613c /source/blender/gpu | |
parent | c1009af596a17e6be37d5c64746ae3b2c6b6dc7d (diff) |
Draw Manager, GPUTexture: Add support for binding individual cubeface to framebuffer.
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 | 46 |
2 files changed, 48 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h index 92f5d8a3796..3ba3c6dbd15 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_cubeface_attach( + GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int face, int mip); void GPU_framebuffer_texture_detach(struct GPUTexture *tex); void GPU_framebuffer_bind(GPUFrameBuffer *fb); void GPU_framebuffer_slots_bind(GPUFrameBuffer *fb, int slot); diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c index dd23eaceaff..ae459eb7d2e 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.c +++ b/source/blender/gpu/intern/gpu_framebuffer.c @@ -163,6 +163,52 @@ 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) +{ + GLenum attachment; + GLenum facetarget; + + if (slot >= GPU_FB_MAX_SLOTS) { + fprintf(stderr, + "Attaching to index %d framebuffer slot unsupported. " + "Use at most %d\n", slot, GPU_FB_MAX_SLOTS); + return false; + } + + if ((G.debug & G_DEBUG)) { + if (GPU_texture_bound_number(tex) != -1) { + fprintf(stderr, + "Feedback loop warning!: " + "Attempting to attach texture to framebuffer while still bound to texture unit for drawing!\n"); + } + } + + BLI_assert(GPU_texture_target(tex) == GL_TEXTURE_CUBE_MAP); + + glBindFramebuffer(GL_FRAMEBUFFER, fb->object); + GG.currentfb = fb->object; + + if (GPU_texture_stencil(tex) && GPU_texture_depth(tex)) + attachment = GL_DEPTH_STENCIL_ATTACHMENT; + else if (GPU_texture_depth(tex)) + attachment = GL_DEPTH_ATTACHMENT; + 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 (GPU_texture_depth(tex)) + fb->depthtex = tex; + else + fb->colortex[slot] = tex; + + GPU_texture_framebuffer_set(tex, fb, slot); + + return true; +} + void GPU_framebuffer_texture_detach(GPUTexture *tex) { GLenum attachment; |