@@ -290,7 +290,7 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
290290 const unsigned int depth_depth = depthstencil.depth ;
291291 const GLenum internal_format = fragcore::GLHelper::getGraphicFormat (depthstencil.graphicFormat );
292292
293- GLenum texture_type = GL_TEXTURE_2D ;
293+ GLenum texture_type = fragcore::GLHelper::getTextureTarget (depthstencil. target ) ;
294294 if (multisamples > 1 ) {
295295 texture_type = GL_TEXTURE_2D_MULTISAMPLE;
296296 }
@@ -300,8 +300,20 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
300300 if (multisamples > 0 ) {
301301 glTexImage2DMultisample (texture_type, multisamples, internal_format, depth_width, depth_height, GL_TRUE);
302302 } else {
303- glTexImage2D (texture_type, 0 , internal_format, depth_width, depth_height, 0 , GL_DEPTH_COMPONENT, GL_FLOAT,
304- nullptr );
303+ switch (texture_type) {
304+ case GL_TEXTURE_2D:
305+ glTexImage2D (texture_type, 0 , internal_format, depth_width, depth_height, 0 , GL_DEPTH_COMPONENT,
306+ GL_FLOAT, nullptr );
307+ break ;
308+ case GL_TEXTURE_CUBE_MAP:
309+ for (unsigned int i = 0 ; i < 6 ; i++) {
310+ glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0 , internal_format, depth_width, depth_height, 0 ,
311+ GL_DEPTH_COMPONENT, GL_FLOAT, nullptr );
312+ }
313+ break ;
314+ default :
315+ break ;
316+ }
305317 }
306318
307319 framebuffer->attachmentSize [framebuffer->depthIndex ] = {depth_width, depth_height, depth_depth};
@@ -328,9 +340,15 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
328340 }
329341
330342 glBindTexture (texture_type, 0 );
331-
332- glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texture_type,
333- framebuffer->attachments [framebuffer->depthIndex ], 0 );
343+ switch (texture_type) {
344+ case GL_TEXTURE_2D:
345+ glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texture_type,
346+ framebuffer->attachments [framebuffer->depthIndex ], 0 );
347+ break ;
348+ case GL_TEXTURE_CUBE_MAP:
349+ glFramebufferTexture (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, framebuffer->attachments [framebuffer->depthIndex ], 0 );
350+ break ;
351+ }
334352 }
335353
336354 /* Validate if created properly.*/
0 commit comments