44#include " RenderDesc.h"
55#include " SampleHelper.h"
66#include < ProceduralGeometry.h>
7- #include < internal_object_type.h>
87
98using namespace glsample ;
109using namespace fragcore ;
@@ -149,6 +148,9 @@ void CommonUtil::loadCube(MeshObject &cubeMesh, const float scale, const int seg
149148
150149 glBindVertexArray (0 );
151150
151+ glBindBuffer (GL_ARRAY_BUFFER, 0 );
152+ glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0 );
153+
152154 cubeMesh.nrIndicesElements = indices.size ();
153155 cubeMesh.indices_offset = 0 ;
154156 cubeMesh.vertex_offset = 0 ;
@@ -244,8 +246,9 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
244246 const unsigned int height = target_desc.height ;
245247 const unsigned int depth = target_desc.depth ;
246248 const unsigned int multisamples = target_desc.nrSamples ;
247- const unsigned int maxLODLevels = target_desc.numlevel ;
248249 const bool useMultiSampling = multisamples > 1 ;
250+ const unsigned int maxLODLevels = target_desc.numlevel ;
251+ const bool fixedSampling = target_desc.fixedSamples ;
249252
250253 const GLenum internal_format = fragcore::GLHelper::getGraphicFormat (target_desc.graphicFormat );
251254
@@ -267,7 +270,11 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
267270 texture_attachment_name.data ());
268271
269272 if (useMultiSampling) {
270- glTexImage2DMultisample (texture_type, multisamples, internal_format, width, height, GL_TRUE);
273+ if (depth > 1 ) {
274+ } else {
275+ glTexImage2DMultisample (texture_type, multisamples, internal_format, width, height, GL_TRUE);
276+ }
277+
271278 } else {
272279 if (depth > 1 ) {
273280 glTexImage3D (texture_type, 0 , internal_format, width, height, depth, 0 , GL_RGBA, GL_UNSIGNED_BYTE,
@@ -291,12 +298,12 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
291298 FVALIDATE_GL_CALL (glTexParameteri (texture_type, GL_TEXTURE_MAX_LOD, 0 ));
292299 FVALIDATE_GL_CALL (glTexParameterf (texture_type, GL_TEXTURE_LOD_BIAS, 0 .0f ));
293300 FVALIDATE_GL_CALL (glTexParameteri (texture_type, GL_TEXTURE_BASE_LEVEL, 0 ));
294-
295301 FVALIDATE_GL_CALL (glTexParameteri (texture_type, GL_TEXTURE_MAX_LEVEL, maxLODLevels));
296- }
297302
298- if (maxLODLevels > 0 ) {
299- glGenerateMipmap (texture_type);
303+ /* */
304+ if (maxLODLevels > 1 ) {
305+ glGenerateMipmap (texture_type);
306+ }
300307 }
301308
302309 glBindTexture (texture_type, 0 );
@@ -322,17 +329,27 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
322329 const unsigned int depth_width = depthstencil->width ;
323330 const unsigned int depth_height = depthstencil->height ;
324331 const unsigned int depth_depth = depthstencil->depth ;
332+ const bool useMultiSampling = multisamples > 1 ;
333+ const bool fixedSampling = depthstencil->fixedSamples ;
325334 const GLenum internal_format = fragcore::GLHelper::getGraphicFormat (depthstencil->graphicFormat );
326335
336+ /* */
327337 GLenum texture_type = fragcore::GLHelper::getTextureTarget (depthstencil->target );
328338 if (multisamples > 1 ) {
329339 texture_type = GL_TEXTURE_2D_MULTISAMPLE;
330340 }
331341
332342 /* */
333343 glBindTexture (texture_type, framebuffer->attachments [framebuffer->depthIndex ]);
334- if (multisamples > 0 ) {
335- glTexImage2DMultisample (texture_type, multisamples, internal_format, depth_width, depth_height, GL_TRUE);
344+ if (useMultiSampling) {
345+ switch (texture_type) {
346+ case GL_TEXTURE_2D_MULTISAMPLE:
347+ glTexImage2DMultisample (texture_type, multisamples, internal_format, depth_width, depth_height,
348+ fixedSampling);
349+ default :
350+ break ;
351+ }
352+
336353 } else {
337354 switch (texture_type) {
338355 case GL_TEXTURE_2D:
@@ -353,7 +370,7 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
353370 framebuffer->attachmentSize [framebuffer->depthIndex ] = {depth_width, depth_height, depth_depth};
354371
355372 /* */
356- if (multisamples <= 1 ) {
373+ if (!useMultiSampling ) {
357374
358375 const float borderColor[] = {1 .0f , 1 .0f , 1 .0f , 1 .0f };
359376 glTexParameterfv (texture_type, GL_TEXTURE_BORDER_COLOR, borderColor);
@@ -376,13 +393,16 @@ void CommonUtil::updateFrameBuffer(FrameBuffer *framebuffer, const std::initiali
376393 glBindTexture (texture_type, 0 );
377394 switch (texture_type) {
378395 case GL_TEXTURE_2D:
396+ case GL_TEXTURE_2D_MULTISAMPLE:
379397 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, texture_type,
380398 framebuffer->attachments [framebuffer->depthIndex ], 0 );
381399 break ;
382400 case GL_TEXTURE_CUBE_MAP:
383401 glFramebufferTexture (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, framebuffer->attachments [framebuffer->depthIndex ],
384402 0 );
385403 break ;
404+ default :
405+ throw RuntimeException (" Failed to bind texture attachment for framebuffer, {}" , -1 );
386406 }
387407 }
388408
0 commit comments