@@ -51,10 +51,42 @@ RenderSceneBuffersGLES3::~RenderSceneBuffersGLES3() {
51
51
free_render_buffer_data ();
52
52
}
53
53
54
+ void RenderSceneBuffersGLES3::_rt_attach_textures (GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count) {
55
+ if (p_view_count > 1 ) {
56
+ if (p_samples > 1 ) {
57
+ #if defined(ANDROID_ENABLED) || defined(WEB_ENABLED)
58
+ glFramebufferTextureMultisampleMultiviewOVR (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, p_color, 0 , p_samples, 0 , p_view_count);
59
+ glFramebufferTextureMultisampleMultiviewOVR (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, p_depth, 0 , p_samples, 0 , p_view_count);
60
+ #else
61
+ ERR_PRINT_ONCE (" Multiview MSAA isn't supported on this platform." );
62
+ #endif
63
+ } else {
64
+ #ifndef IOS_ENABLED
65
+ glFramebufferTextureMultiviewOVR (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, p_color, 0 , 0 , p_view_count);
66
+ glFramebufferTextureMultiviewOVR (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, p_depth, 0 , 0 , p_view_count);
67
+ #else
68
+ ERR_PRINT_ONCE (" Multiview isn't supported on this platform." );
69
+ #endif
70
+ }
71
+ } else {
72
+ if (p_samples > 1 ) {
73
+ #ifdef ANDROID_ENABLED
74
+ glFramebufferTexture2DMultisampleEXT (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, p_color, 0 , p_samples);
75
+ glFramebufferTexture2DMultisampleEXT (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, p_depth, 0 , p_samples);
76
+ #else
77
+ ERR_PRINT_ONCE (" MSAA via EXT_multisampled_render_to_texture isn't supported on this platform." );
78
+ #endif
79
+ } else {
80
+ glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, p_color, 0 );
81
+ glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, p_depth, 0 );
82
+ }
83
+ }
84
+ }
85
+
54
86
GLuint RenderSceneBuffersGLES3::_rt_get_cached_fbo (GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count) {
55
87
FBDEF new_fbo;
56
88
57
- #ifdef ANDROID_ENABLED
89
+ #if defined( ANDROID_ENABLED) || defined(WEB_ENABLED)
58
90
// There shouldn't be more then 3 entries in this...
59
91
for (const FBDEF &cached_fbo : msaa3d.cached_fbos ) {
60
92
if (cached_fbo.color == p_color && cached_fbo.depth == p_depth) {
@@ -68,13 +100,7 @@ GLuint RenderSceneBuffersGLES3::_rt_get_cached_fbo(GLuint p_color, GLuint p_dept
68
100
glGenFramebuffers (1 , &new_fbo.fbo );
69
101
glBindFramebuffer (GL_FRAMEBUFFER, new_fbo.fbo );
70
102
71
- if (p_view_count > 1 ) {
72
- glFramebufferTextureMultisampleMultiviewOVR (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, p_color, 0 , p_samples, 0 , p_view_count);
73
- glFramebufferTextureMultisampleMultiviewOVR (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, p_depth, 0 , p_samples, 0 , p_view_count);
74
- } else {
75
- glFramebufferTexture2DMultisampleEXT (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, p_color, 0 , p_samples);
76
- glFramebufferTexture2DMultisampleEXT (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, p_depth, 0 , p_samples);
77
- }
103
+ _rt_attach_textures (p_color, p_depth, p_samples, p_view_count);
78
104
79
105
GLenum status = glCheckFramebufferStatus (GL_FRAMEBUFFER);
80
106
if (status != GL_FRAMEBUFFER_COMPLETE) {
@@ -317,8 +343,6 @@ void RenderSceneBuffersGLES3::configure(const RenderSceneBuffersConfiguration *p
317
343
// hence we'll use our FBO cache here.
318
344
msaa3d.needs_resolve = false ;
319
345
msaa3d.check_fbo_cache = true ;
320
- #endif
321
- #ifdef ANDROID_ENABLED
322
346
} else if (use_internal_buffer) {
323
347
// We can combine MSAA and scaling/effects.
324
348
msaa3d.needs_resolve = false ;
@@ -329,13 +353,7 @@ void RenderSceneBuffersGLES3::configure(const RenderSceneBuffersConfiguration *p
329
353
glGenFramebuffers (1 , &msaa3d.fbo );
330
354
glBindFramebuffer (GL_FRAMEBUFFER, msaa3d.fbo );
331
355
332
- if (use_multiview) {
333
- glFramebufferTextureMultisampleMultiviewOVR (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, internal3d.color , 0 , msaa3d.samples , 0 , view_count);
334
- glFramebufferTextureMultisampleMultiviewOVR (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, internal3d.depth , 0 , msaa3d.samples , 0 , view_count);
335
- } else {
336
- glFramebufferTexture2DMultisampleEXT (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, internal3d.color , 0 , msaa3d.samples );
337
- glFramebufferTexture2DMultisampleEXT (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, internal3d.depth , 0 , msaa3d.samples );
338
- }
356
+ _rt_attach_textures (internal3d.color , internal3d.depth , msaa3d.samples , view_count);
339
357
340
358
GLenum status = glCheckFramebufferStatus (GL_FRAMEBUFFER);
341
359
if (status != GL_FRAMEBUFFER_COMPLETE) {
@@ -515,24 +533,34 @@ void RenderSceneBuffersGLES3::free_render_buffer_data() {
515
533
}
516
534
517
535
GLuint RenderSceneBuffersGLES3::get_render_fbo () {
518
- if (msaa3d. check_fbo_cache ) {
519
- GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton () ;
536
+ GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton ();
537
+ GLuint rt_fbo = 0 ;
520
538
539
+ if (msaa3d.check_fbo_cache ) {
521
540
GLuint color = texture_storage->render_target_get_color (render_target);
522
541
GLuint depth = texture_storage->render_target_get_depth (render_target);
523
542
524
- return _rt_get_cached_fbo (color, depth, msaa3d.samples , view_count);
543
+ rt_fbo = _rt_get_cached_fbo (color, depth, msaa3d.samples , view_count);
525
544
} else if (msaa3d.fbo != 0 ) {
526
545
// We have an MSAA fbo, render to our MSAA buffer
527
546
return msaa3d.fbo ;
528
547
} else if (internal3d.fbo != 0 ) {
529
548
// We have an internal buffer, render to our internal buffer!
530
549
return internal3d.fbo ;
531
550
} else {
532
- GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton ();
551
+ rt_fbo = texture_storage->render_target_get_fbo (render_target);
552
+ }
533
553
534
- return texture_storage->render_target_get_fbo (render_target);
554
+ if (texture_storage->render_target_is_reattach_textures (render_target)) {
555
+ GLuint color = texture_storage->render_target_get_color (render_target);
556
+ GLuint depth = texture_storage->render_target_get_depth (render_target);
557
+
558
+ glBindFramebuffer (GL_FRAMEBUFFER, rt_fbo);
559
+ _rt_attach_textures (color, depth, msaa3d.samples , view_count);
560
+ glBindFramebuffer (GL_FRAMEBUFFER, texture_storage->system_fbo );
535
561
}
562
+
563
+ return rt_fbo;
536
564
}
537
565
538
566
#endif // GLES3_ENABLED
0 commit comments