FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SFML/src/SFML/Graphics/RenderTextureImplFBO.cpp at master · githubhy/SFML · GitHub
githubhy
/
SFML
Public
forked from
SFML/SFML
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SFML
/
src
/
SFML
/
Graphics
/
RenderTextureImplFBO.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
650 lines (531 loc) · 23.6 KB
Breadcrumbs
SFML
/
src
/
SFML
/
Graphics
/
RenderTextureImplFBO.cpp
Copy path
File metadata and controls
650 lines (531 loc) · 23.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
//
//////////////////////////////////////////////////////////
//
//
SFML - Simple and Fast Multimedia Library
//
Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
//
//
This software is provided 'as-is', without any express or implied warranty.
//
In no event will the authors be held liable for any damages arising from the use of this software.
//
//
Permission is granted to anyone to use this software for any purpose,
//
including commercial applications, and to alter it and redistribute it freely,
//
subject to the following restrictions:
//
//
1. The origin of this software must not be misrepresented;
//
you must not claim that you wrote the original software.
//
If you use this software in a product, an acknowledgment
//
in the product documentation would be appreciated but is not required.
//
//
2. Altered source versions must be plainly marked as such,
//
and must not be misrepresented as being the original software.
//
//
3. This notice may not be removed or altered from any source distribution.
//
//
//////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////
//
Headers
//
//////////////////////////////////////////////////////////
#
include
<
SFML/Graphics/GLCheck.hpp
>
#
include
<
SFML/Graphics/GLExtensions.hpp
>
#
include
<
SFML/Graphics/RenderTextureImplFBO.hpp
>
#
include
<
SFML/Window/Context.hpp
>
#
include
<
SFML/Window/ContextSettings.hpp
>
#
include
<
SFML/System/Err.hpp
>
#
include
<
ostream
>
#
include
<
utility
>
namespace
sf
::priv
{
//
//////////////////////////////////////////////////////////
struct
RenderTextureImplFBO
::FrameBufferObject
{
FrameBufferObject
()
{
//
Create the framebuffer object
glCheck
(
GLEXT_glGenFramebuffers
(
1
, &object));
}
~FrameBufferObject
()
{
if
(object)
glCheck
(
GLEXT_glDeleteFramebuffers
(
1
, &object));
}
GLuint object{};
};
//
//////////////////////////////////////////////////////////
RenderTextureImplFBO::RenderTextureImplFBO
() =
default
;
//
//////////////////////////////////////////////////////////
RenderTextureImplFBO::~RenderTextureImplFBO
()
{
const
TransientContextLock contextLock;
//
Destroy the color buffer
if
(m_colorBuffer)
{
const
GLuint colorBuffer = m_colorBuffer;
glCheck
(
GLEXT_glDeleteRenderbuffers
(
1
, &colorBuffer));
}
//
Destroy the depth/stencil buffer
if
(m_depthStencilBuffer)
{
const
GLuint depthStencilBuffer = m_depthStencilBuffer;
glCheck
(
GLEXT_glDeleteRenderbuffers
(
1
, &depthStencilBuffer));
}
//
Unregister FBOs with the contexts if they haven't already been destroyed
for
(
auto
& entry : m_frameBuffers)
{
auto
frameBuffer = entry.
second
.
lock
();
if
(frameBuffer)
unregisterUnsharedGlObject
(
std::move
(frameBuffer));
}
for
(
auto
& entry : m_multisampleFrameBuffers)
{
auto
frameBuffer = entry.
second
.
lock
();
if
(frameBuffer)
unregisterUnsharedGlObject
(
std::move
(frameBuffer));
}
}
//
//////////////////////////////////////////////////////////
bool
RenderTextureImplFBO::isAvailable
()
{
const
TransientContextLock lock;
//
Make sure that extensions are initialized
priv::ensureExtensionsInit
();
return
GLEXT_framebuffer_object !=
0
;
}
//
//////////////////////////////////////////////////////////
unsigned
int
RenderTextureImplFBO::getMaximumAntialiasingLevel
()
{
#
ifdef
SFML_OPENGL_ES
return
0
;
#
else
const
TransientContextLock lock;
GLint samples =
0
;
glCheck
(
glGetIntegerv
(
GLEXT_GL_MAX_SAMPLES
, &samples));
return
static_cast
<
unsigned
int
>(samples);
#
endif
}
//
//////////////////////////////////////////////////////////
void
RenderTextureImplFBO::unbind
()
{
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
,
0
));
}
//
//////////////////////////////////////////////////////////
bool
RenderTextureImplFBO::create
(
const
Vector2u& size,
unsigned
int
textureId,
const
ContextSettings& settings)
{
//
Store the dimensions
m_size = size;
{
const
TransientContextLock lock;
//
Make sure that extensions are initialized
priv::ensureExtensionsInit
();
if
(settings.
antialiasingLevel
&& !(GLEXT_framebuffer_multisample && GLEXT_framebuffer_blit))
return
false
;
m_sRgb = settings.
sRgbCapable
&& GL_EXT_texture_sRGB;
#
ifndef
SFML_OPENGL_ES
//
Check if the requested anti-aliasing level is supported
if
(settings.
antialiasingLevel
)
{
GLint samples =
0
;
glCheck
(
glGetIntegerv
(
GLEXT_GL_MAX_SAMPLES
, &samples));
if
(settings.
antialiasingLevel
>
static_cast
<
unsigned
int
>(samples))
{
err
() <<
"
Impossible to create render texture (unsupported anti-aliasing level)
"
<<
"
Requested:
"
<< settings.
antialiasingLevel
<<
"
Maximum supported:
"
<< samples << std::endl;
return
false
;
}
}
#
endif
if
(!settings.
antialiasingLevel
)
{
//
Create the depth/stencil buffer if requested
if
(settings.
stencilBits
&& settings.
depthBits
)
{
if
(!GLEXT_packed_depth_stencil)
{
err
() <<
"
Impossible to create render texture (combined depth/stencil buffer not supported)
"
<< std::endl;
return
false
;
}
GLuint depthStencil =
0
;
glCheck
(
GLEXT_glGenRenderbuffers
(
1
, &depthStencil));
m_depthStencilBuffer = depthStencil;
if
(!m_depthStencilBuffer)
{
err
() <<
"
Impossible to create render texture (failed to create the attached depth/stencil buffer)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindRenderbuffer
(
GLEXT_GL_RENDERBUFFER
, m_depthStencilBuffer));
glCheck
(
GLEXT_glRenderbufferStorage
(
GLEXT_GL_RENDERBUFFER
,
GLEXT_GL_DEPTH24_STENCIL8
,
static_cast
<GLsizei>(size.
x
),
static_cast
<GLsizei>(size.
y
)));
m_depth =
true
;
m_stencil =
true
;
}
else
if
(settings.
depthBits
)
{
GLuint depthStencil =
0
;
glCheck
(
GLEXT_glGenRenderbuffers
(
1
, &depthStencil));
m_depthStencilBuffer = depthStencil;
if
(!m_depthStencilBuffer)
{
err
() <<
"
Impossible to create render texture (failed to create the attached depth buffer)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindRenderbuffer
(
GLEXT_GL_RENDERBUFFER
, m_depthStencilBuffer));
glCheck
(
GLEXT_glRenderbufferStorage
(
GLEXT_GL_RENDERBUFFER
,
GLEXT_GL_DEPTH_COMPONENT
,
static_cast
<GLsizei>(size.
x
),
static_cast
<GLsizei>(size.
y
)));
m_depth =
true
;
m_stencil =
false
;
}
else
if
(settings.
stencilBits
)
{
GLuint depthStencil =
0
;
glCheck
(
GLEXT_glGenRenderbuffers
(
1
, &depthStencil));
m_depthStencilBuffer = depthStencil;
if
(!m_depthStencilBuffer)
{
err
() <<
"
Impossible to create render texture (failed to create the attached stencil buffer)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindRenderbuffer
(
GLEXT_GL_RENDERBUFFER
, m_depthStencilBuffer));
glCheck
(
GLEXT_glRenderbufferStorage
(
GLEXT_GL_RENDERBUFFER
,
GLEXT_GL_STENCIL_INDEX8
,
static_cast
<GLsizei>(size.
x
),
static_cast
<GLsizei>(size.
y
)));
m_depth =
false
;
m_stencil =
true
;
}
}
else
{
#
ifndef
SFML_OPENGL_ES
//
Create the multisample color buffer
GLuint color =
0
;
glCheck
(
GLEXT_glGenRenderbuffers
(
1
, &color));
m_colorBuffer = color;
if
(!m_colorBuffer)
{
err
() <<
"
Impossible to create render texture (failed to create the attached multisample color buffer)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindRenderbuffer
(
GLEXT_GL_RENDERBUFFER
, m_colorBuffer));
glCheck
(
GLEXT_glRenderbufferStorageMultisample
(
GLEXT_GL_RENDERBUFFER
,
static_cast
<GLsizei>(settings.
antialiasingLevel
),
m_sRgb ?
GL_SRGB8_ALPHA8_EXT
:
GL_RGBA
,
static_cast
<GLsizei>(size.
x
),
static_cast
<GLsizei>(size.
y
)));
//
Create the multisample depth/stencil buffer if requested
if
(settings.
stencilBits
&& settings.
depthBits
)
{
GLuint depthStencil =
0
;
glCheck
(
GLEXT_glGenRenderbuffers
(
1
, &depthStencil));
m_depthStencilBuffer = depthStencil;
if
(!m_depthStencilBuffer)
{
err
() <<
"
Impossible to create render texture (failed to create the attached multisample
"
"
depth/stencil buffer)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindRenderbuffer
(
GLEXT_GL_RENDERBUFFER
, m_depthStencilBuffer));
glCheck
(
GLEXT_glRenderbufferStorageMultisample
(
GLEXT_GL_RENDERBUFFER
,
static_cast
<GLsizei>(settings.
antialiasingLevel
),
GLEXT_GL_DEPTH24_STENCIL8
,
static_cast
<GLsizei>(size.
x
),
static_cast
<GLsizei>(size.
y
)));
m_depth =
true
;
m_stencil =
true
;
}
else
if
(settings.
depthBits
)
{
GLuint depthStencil =
0
;
glCheck
(
GLEXT_glGenRenderbuffers
(
1
, &depthStencil));
m_depthStencilBuffer = depthStencil;
if
(!m_depthStencilBuffer)
{
err
() <<
"
Impossible to create render texture (failed to create the attached multisample depth
"
"
buffer)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindRenderbuffer
(
GLEXT_GL_RENDERBUFFER
, m_depthStencilBuffer));
glCheck
(
GLEXT_glRenderbufferStorageMultisample
(
GLEXT_GL_RENDERBUFFER
,
static_cast
<GLsizei>(settings.
antialiasingLevel
),
GLEXT_GL_DEPTH_COMPONENT
,
static_cast
<GLsizei>(size.
x
),
static_cast
<GLsizei>(size.
y
)));
m_depth =
true
;
m_stencil =
false
;
}
else
if
(settings.
stencilBits
)
{
GLuint depthStencil =
0
;
glCheck
(
GLEXT_glGenRenderbuffers
(
1
, &depthStencil));
m_depthStencilBuffer = depthStencil;
if
(!m_depthStencilBuffer)
{
err
() <<
"
Impossible to create render texture (failed to create the attached multisample
"
"
stencil buffer)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindRenderbuffer
(
GLEXT_GL_RENDERBUFFER
, m_depthStencilBuffer));
glCheck
(
GLEXT_glRenderbufferStorageMultisample
(
GLEXT_GL_RENDERBUFFER
,
static_cast
<GLsizei>(settings.
antialiasingLevel
),
GLEXT_GL_STENCIL_INDEX8
,
static_cast
<GLsizei>(size.
x
),
static_cast
<GLsizei>(size.
y
)));
m_depth =
false
;
m_stencil =
true
;
}
m_multisample =
true
;
#
else
m_multisample =
false
;
err
() <<
"
Impossible to create render texture (failed to create the multisample render buffers)
"
<< std::endl;
return
false
;
#
endif
//
SFML_OPENGL_ES
}
}
//
Save our texture ID in order to be able to attach it to an FBO at any time
m_textureId = textureId;
//
We can't create an FBO now if there is no active context
if
(!
Context::getActiveContextId
())
return
true
;
#
ifndef
SFML_OPENGL_ES
//
Save the current bindings so we can restore them after we are done
GLint readFramebuffer =
0
;
GLint drawFramebuffer =
0
;
glCheck
(
glGetIntegerv
(
GLEXT_GL_READ_FRAMEBUFFER_BINDING
, &readFramebuffer));
glCheck
(
glGetIntegerv
(
GLEXT_GL_DRAW_FRAMEBUFFER_BINDING
, &drawFramebuffer));
if
(
createFrameBuffer
())
{
//
Restore previously bound framebuffers
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_READ_FRAMEBUFFER
,
static_cast
<GLuint>(readFramebuffer)));
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_DRAW_FRAMEBUFFER
,
static_cast
<GLuint>(drawFramebuffer)));
return
true
;
}
#
else
//
Save the current binding so we can restore them after we are done
GLint frameBuffer =
0
;
glCheck
(
glGetIntegerv
(
GLEXT_GL_FRAMEBUFFER_BINDING
, &frameBuffer));
if
(
createFrameBuffer
())
{
//
Restore previously bound framebuffer
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
,
static_cast
<GLuint>(frameBuffer)));
return
true
;
}
#
endif
return
false
;
}
//
//////////////////////////////////////////////////////////
bool
RenderTextureImplFBO::createFrameBuffer
()
{
//
Create the framebuffer object
auto
frameBuffer = std::make_shared<FrameBufferObject>();
if
(!frameBuffer->
object
)
{
err
() <<
"
Impossible to create render texture (failed to create the frame buffer object)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
, frameBuffer->
object
));
//
Link the depth/stencil renderbuffer to the frame buffer
if
(!m_multisample && m_depthStencilBuffer)
{
if
(m_depth)
{
glCheck
(
GLEXT_glFramebufferRenderbuffer
(
GLEXT_GL_FRAMEBUFFER
,
GLEXT_GL_DEPTH_ATTACHMENT
,
GLEXT_GL_RENDERBUFFER
,
m_depthStencilBuffer));
}
if
(m_stencil)
{
glCheck
(
GLEXT_glFramebufferRenderbuffer
(
GLEXT_GL_FRAMEBUFFER
,
GLEXT_GL_STENCIL_ATTACHMENT
,
GLEXT_GL_RENDERBUFFER
,
m_depthStencilBuffer));
}
}
//
Link the texture to the frame buffer
glCheck
(
GLEXT_glFramebufferTexture2D
(
GLEXT_GL_FRAMEBUFFER
,
GLEXT_GL_COLOR_ATTACHMENT0
,
GL_TEXTURE_2D
, m_textureId,
0
));
//
A final check, just to be sure...
GLenum status =
0
;
glCheck
(status =
GLEXT_glCheckFramebufferStatus
(
GLEXT_GL_FRAMEBUFFER
));
if
(status !=
GLEXT_GL_FRAMEBUFFER_COMPLETE
)
{
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
,
0
));
err
() <<
"
Impossible to create render texture (failed to link the target texture to the frame buffer)
"
<< std::endl;
return
false
;
}
//
Insert the FBO into our map
m_frameBuffers.
emplace
(
Context::getActiveContextId
(), frameBuffer);
//
Register the object with the current context so it is automatically destroyed
registerUnsharedGlObject
(
std::move
(frameBuffer));
#
ifndef
SFML_OPENGL_ES
if
(m_multisample)
{
//
Create the multisample framebuffer object
auto
multisampleFrameBuffer = std::make_shared<FrameBufferObject>();
if
(!multisampleFrameBuffer->
object
)
{
err
() <<
"
Impossible to create render texture (failed to create the multisample frame buffer object)
"
<< std::endl;
return
false
;
}
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
, multisampleFrameBuffer->
object
));
//
Link the multisample color buffer to the frame buffer
glCheck
(
GLEXT_glBindRenderbuffer
(
GLEXT_GL_RENDERBUFFER
, m_colorBuffer));
glCheck
(
GLEXT_glFramebufferRenderbuffer
(
GLEXT_GL_FRAMEBUFFER
,
GLEXT_GL_COLOR_ATTACHMENT0
,
GLEXT_GL_RENDERBUFFER
, m_colorBuffer));
//
Link the depth/stencil renderbuffer to the frame buffer
if
(m_depthStencilBuffer)
{
if
(m_depth)
{
glCheck
(
GLEXT_glFramebufferRenderbuffer
(
GLEXT_GL_FRAMEBUFFER
,
GLEXT_GL_DEPTH_ATTACHMENT
,
GLEXT_GL_RENDERBUFFER
,
m_depthStencilBuffer));
}
if
(m_stencil)
{
glCheck
(
GLEXT_glFramebufferRenderbuffer
(
GLEXT_GL_FRAMEBUFFER
,
GLEXT_GL_STENCIL_ATTACHMENT
,
GLEXT_GL_RENDERBUFFER
,
m_depthStencilBuffer));
}
}
//
A final check, just to be sure...
glCheck
(status =
GLEXT_glCheckFramebufferStatus
(
GLEXT_GL_FRAMEBUFFER
));
if
(status !=
GLEXT_GL_FRAMEBUFFER_COMPLETE
)
{
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
,
0
));
err
() <<
"
Impossible to create render texture (failed to link the render buffers to the multisample frame
"
"
buffer)
"
<< std::endl;
return
false
;
}
//
Insert the FBO into our map
m_multisampleFrameBuffers.
emplace
(
Context::getActiveContextId
(), multisampleFrameBuffer);
//
Register the object with the current context so it is automatically destroyed
registerUnsharedGlObject
(
std::move
(multisampleFrameBuffer));
}
#
endif
return
true
;
}
//
//////////////////////////////////////////////////////////
bool
RenderTextureImplFBO::activate
(
bool
active)
{
//
Unbind the FBO if requested
if
(!active)
{
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
,
0
));
return
true
;
}
std::
uint64_t
contextId =
Context::getActiveContextId
();
//
In the odd case we have to activate and there is no active
//
context yet, we have to create one
if
(!contextId)
{
if
(!m_context)
m_context = std::make_unique<Context>();
if
(!m_context->
setActive
(
true
))
{
err
() <<
"
Failed to set context as active during render texture activation
"
<< std::endl;
return
false
;
}
contextId =
Context::getActiveContextId
();
if
(!contextId)
{
err
() <<
"
Impossible to activate render texture (failed to create backup context)
"
<< std::endl;
return
false
;
}
}
//
Lookup the FBO corresponding to the currently active context
//
If none is found, there is no FBO corresponding to the
//
currently active context so we will have to create a new FBO
if
(m_multisample)
{
const
auto
it = m_multisampleFrameBuffers.
find
(contextId);
if
(it != m_multisampleFrameBuffers.
end
())
{
const
auto
frameBuffer = it->
second
.
lock
();
if
(frameBuffer)
{
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
, frameBuffer->
object
));
return
true
;
}
}
}
else
{
const
auto
it = m_frameBuffers.
find
(contextId);
if
(it != m_frameBuffers.
end
())
{
const
auto
frameBuffer = it->
second
.
lock
();
if
(frameBuffer)
{
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_FRAMEBUFFER
, frameBuffer->
object
));
return
true
;
}
}
}
return
createFrameBuffer
();
}
//
//////////////////////////////////////////////////////////
bool
RenderTextureImplFBO::isSrgb
()
const
{
return
m_sRgb;
}
//
//////////////////////////////////////////////////////////
void
RenderTextureImplFBO::updateTexture
(
unsigned
int
)
{
//
If multisampling is enabled, we need to resolve by blitting
//
from our FBO with multisample renderbuffer attachments
//
to our FBO to which our target texture is attached
#
ifndef
SFML_OPENGL_ES
//
In case of multisampling, make sure both FBOs
//
are already available within the current context
if
(m_multisample && m_size.
x
&& m_size.
y
&&
activate
(
true
))
{
const
std::
uint64_t
contextId =
Context::getActiveContextId
();
const
auto
frameBufferIt = m_frameBuffers.
find
(contextId);
const
auto
multisampleIt = m_multisampleFrameBuffers.
find
(contextId);
if
((frameBufferIt != m_frameBuffers.
end
()) && (multisampleIt != m_multisampleFrameBuffers.
end
()))
{
const
auto
frameBuffer = frameBufferIt->
second
.
lock
();
const
auto
multiSampleFrameBuffer = multisampleIt->
second
.
lock
();
if
(frameBuffer && multiSampleFrameBuffer)
{
//
Scissor testing affects framebuffer blits as well
//
Since we don't want scissor testing to interfere with our copying, we temporarily disable it for the blit if it is enabled
GLboolean scissorEnabled =
GL_FALSE
;
glCheck
(
glGetBooleanv
(
GL_SCISSOR_TEST
, &scissorEnabled));
if
(scissorEnabled ==
GL_TRUE
)
glCheck
(
glDisable
(
GL_SCISSOR_TEST
));
//
Set up the blit target (draw framebuffer) and blit (from the read framebuffer, our multisample FBO)
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_DRAW_FRAMEBUFFER
, frameBuffer->
object
));
glCheck
(
GLEXT_glBlitFramebuffer
(
0
,
0
,
static_cast
<GLint>(m_size.
x
),
static_cast
<GLint>(m_size.
y
),
0
,
0
,
static_cast
<GLint>(m_size.
x
),
static_cast
<GLint>(m_size.
y
),
GL_COLOR_BUFFER_BIT
,
GL_NEAREST
));
glCheck
(
GLEXT_glBindFramebuffer
(
GLEXT_GL_DRAW_FRAMEBUFFER
, multiSampleFrameBuffer->
object
));
//
Re-enable scissor testing if it was previously enabled
if
(scissorEnabled ==
GL_TRUE
)
glCheck
(
glEnable
(
GL_SCISSOR_TEST
));
}
}
}
#
endif
//
SFML_OPENGL_ES
}
}
//
namespace sf::priv
Back
|
FazBrowse Home
|
New Git URL