Commit: 4abb3c1bc45e31fd340d695c0f82e799370736a5
Author: Clément Foucault
Date:   Thu Jun 8 20:12:58 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB4abb3c1bc45e31fd340d695c0f82e799370736a5

Draw Manager, GPUTexture: Add support for binding individual cubeface to 
framebuffer.

===================================================================

M       source/blender/draw/intern/draw_manager.c
M       source/blender/gpu/GPU_framebuffer.h
M       source/blender/gpu/intern/gpu_framebuffer.c

===================================================================

diff --git a/source/blender/draw/intern/draw_manager.c 
b/source/blender/draw/intern/draw_manager.c
index 08ff7b52a38..e85de5da859 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2049,6 +2049,10 @@ void DRW_framebuffer_texture_attach(struct 
GPUFrameBuffer *fb, GPUTexture *tex,
        GPU_framebuffer_texture_attach(fb, tex, slot, 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 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;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to