5252
5353namespace
5454{
55- // Mutex to protect ID generation and our context-RenderTarget-map
56- sf::Mutex mutex;
57-
58- // Unique identifier, used for identifying RenderTargets when
59- // tracking the currently active RenderTarget within a given context
60- sf::Uint64 getUniqueId ()
55+ // A nested named namespace is used here to allow unity builds of SFML.
56+ namespace RenderTargetImpl
6157 {
62- sf::Lock lock (mutex);
63-
64- static sf::Uint64 id = 1 ; // start at 1, zero is "no RenderTarget"
65-
66- return id++;
67- }
58+ // Mutex to protect ID generation and our context-RenderTarget-map
59+ sf::Mutex mutex;
6860
69- // Map to help us detect whether a different RenderTarget
70- // has been activated within a single context
71- typedef std::map<sf::Uint64, sf::Uint64> ContextRenderTargetMap;
72- ContextRenderTargetMap contextRenderTargetMap;
61+ // Unique identifier, used for identifying RenderTargets when
62+ // tracking the currently active RenderTarget within a given context
63+ sf::Uint64 getUniqueId ()
64+ {
65+ sf::Lock lock (mutex);
7366
74- // Check if a RenderTarget with the given ID is active in the current context
75- bool isActive (sf::Uint64 id)
76- {
77- ContextRenderTargetMap::iterator iter = contextRenderTargetMap.find (sf::Context::getActiveContextId ());
67+ static sf::Uint64 id = 1 ; // start at 1, zero is "no RenderTarget"
7868
79- if ((iter == contextRenderTargetMap. end ()) || (iter-> second != id))
80- return false ;
69+ return id++;
70+ }
8171
82- return true ;
83- }
72+ // Map to help us detect whether a different RenderTarget
73+ // has been activated within a single context
74+ typedef std::map<sf::Uint64, sf::Uint64> ContextRenderTargetMap;
75+ ContextRenderTargetMap contextRenderTargetMap;
8476
85- // Convert an sf::BlendMode::Factor constant to the corresponding OpenGL constant.
86- sf::Uint32 factorToGlConstant (sf::BlendMode::Factor blendFactor)
87- {
88- switch (blendFactor)
77+ // Check if a RenderTarget with the given ID is active in the current context
78+ bool isActive (sf::Uint64 id)
8979 {
90- case sf::BlendMode::Zero: return GL_ZERO;
91- case sf::BlendMode::One: return GL_ONE;
92- case sf::BlendMode::SrcColor: return GL_SRC_COLOR;
93- case sf::BlendMode::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR;
94- case sf::BlendMode::DstColor: return GL_DST_COLOR;
95- case sf::BlendMode::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR;
96- case sf::BlendMode::SrcAlpha: return GL_SRC_ALPHA;
97- case sf::BlendMode::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA;
98- case sf::BlendMode::DstAlpha: return GL_DST_ALPHA;
99- case sf::BlendMode::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA;
100- }
80+ ContextRenderTargetMap::iterator iter = contextRenderTargetMap.find (sf::Context::getActiveContextId ());
10181
102- sf::err () << " Invalid value for sf::BlendMode::Factor! Fallback to sf::BlendMode::Zero." << std::endl;
103- assert (false );
104- return GL_ZERO;
105- }
82+ if ((iter == contextRenderTargetMap.end ()) || (iter->second != id))
83+ return false ;
10684
85+ return true ;
86+ }
10787
108- // Convert an sf::BlendMode::BlendEquation constant to the corresponding OpenGL constant.
109- sf::Uint32 equationToGlConstant (sf::BlendMode::Equation blendEquation)
110- {
111- switch (blendEquation)
88+ // Convert an sf::BlendMode::Factor constant to the corresponding OpenGL constant.
89+ sf::Uint32 factorToGlConstant (sf::BlendMode::Factor blendFactor)
11290 {
113- case sf::BlendMode::Add:
114- return GLEXT_GL_FUNC_ADD;
115- case sf::BlendMode::Subtract:
116- if (GLEXT_blend_subtract)
117- return GLEXT_GL_FUNC_SUBTRACT;
118- break ;
119- case sf::BlendMode::ReverseSubtract:
120- if (GLEXT_blend_subtract)
121- return GLEXT_GL_FUNC_REVERSE_SUBTRACT;
122- break ;
123- case sf::BlendMode::Min:
124- if (GLEXT_blend_minmax)
125- return GLEXT_GL_MIN;
126- break ;
127- case sf::BlendMode::Max:
128- if (GLEXT_blend_minmax)
129- return GLEXT_GL_MAX;
130- break ;
91+ switch (blendFactor)
92+ {
93+ case sf::BlendMode::Zero: return GL_ZERO;
94+ case sf::BlendMode::One: return GL_ONE;
95+ case sf::BlendMode::SrcColor: return GL_SRC_COLOR;
96+ case sf::BlendMode::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR;
97+ case sf::BlendMode::DstColor: return GL_DST_COLOR;
98+ case sf::BlendMode::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR;
99+ case sf::BlendMode::SrcAlpha: return GL_SRC_ALPHA;
100+ case sf::BlendMode::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA;
101+ case sf::BlendMode::DstAlpha: return GL_DST_ALPHA;
102+ case sf::BlendMode::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA;
103+ }
104+
105+ sf::err () << " Invalid value for sf::BlendMode::Factor! Fallback to sf::BlendMode::Zero." << std::endl;
106+ assert (false );
107+ return GL_ZERO;
131108 }
132109
133- static bool warned = false ;
134- if (!warned)
110+
111+ // Convert an sf::BlendMode::BlendEquation constant to the corresponding OpenGL constant.
112+ sf::Uint32 equationToGlConstant (sf::BlendMode::Equation blendEquation)
135113 {
136- sf::err () << " OpenGL extension EXT_blend_minmax or EXT_blend_subtract unavailable" << std::endl;
137- sf::err () << " Some blending equations will fallback to sf::BlendMode::Add" << std::endl;
138- sf::err () << " Ensure that hardware acceleration is enabled if available" << std::endl;
114+ switch (blendEquation)
115+ {
116+ case sf::BlendMode::Add:
117+ return GLEXT_GL_FUNC_ADD;
118+ case sf::BlendMode::Subtract:
119+ if (GLEXT_blend_subtract)
120+ return GLEXT_GL_FUNC_SUBTRACT;
121+ break ;
122+ case sf::BlendMode::ReverseSubtract:
123+ if (GLEXT_blend_subtract)
124+ return GLEXT_GL_FUNC_REVERSE_SUBTRACT;
125+ break ;
126+ case sf::BlendMode::Min:
127+ if (GLEXT_blend_minmax)
128+ return GLEXT_GL_MIN;
129+ break ;
130+ case sf::BlendMode::Max:
131+ if (GLEXT_blend_minmax)
132+ return GLEXT_GL_MAX;
133+ break ;
134+ }
139135
140- warned = true ;
141- }
136+ static bool warned = false ;
137+ if (!warned)
138+ {
139+ sf::err () << " OpenGL extension EXT_blend_minmax or EXT_blend_subtract unavailable" << std::endl;
140+ sf::err () << " Some blending equations will fallback to sf::BlendMode::Add" << std::endl;
141+ sf::err () << " Ensure that hardware acceleration is enabled if available" << std::endl;
142142
143- return GLEXT_GL_FUNC_ADD;
143+ warned = true ;
144+ }
145+
146+ return GLEXT_GL_FUNC_ADD;
147+ }
144148 }
145149}
146150
@@ -167,7 +171,7 @@ RenderTarget::~RenderTarget()
167171// //////////////////////////////////////////////////////////
168172void RenderTarget::clear (const Color& color)
169173{
170- if (isActive (m_id) || setActive (true ))
174+ if (RenderTargetImpl:: isActive (m_id) || setActive (true ))
171175 {
172176 // Unbind texture to fix RenderTexture preventing clear
173177 applyTexture (NULL );
@@ -282,7 +286,7 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount,
282286 }
283287 #endif
284288
285- if (isActive (m_id) || setActive (true ))
289+ if (RenderTargetImpl:: isActive (m_id) || setActive (true ))
286290 {
287291 // Check if the vertex count is low enough so that we can pre-transform them
288292 bool useVertexCache = (vertexCount <= StatesCache::VertexCacheSize);
@@ -382,7 +386,7 @@ void RenderTarget::draw(const VertexBuffer& vertexBuffer, std::size_t firstVerte
382386 }
383387 #endif
384388
385- if (isActive (m_id) || setActive (true ))
389+ if (RenderTargetImpl:: isActive (m_id) || setActive (true ))
386390 {
387391 setupDraw (false , states);
388392
@@ -424,11 +428,12 @@ bool RenderTarget::setActive(bool active)
424428{
425429 // Mark this RenderTarget as active or no longer active in the tracking map
426430 {
427- sf::Lock lock (mutex);
431+ sf::Lock lock (RenderTargetImpl:: mutex);
428432
429433 Uint64 contextId = Context::getActiveContextId ();
430434
431- ContextRenderTargetMap::iterator iter = contextRenderTargetMap.find (contextId);
435+ using RenderTargetImpl::contextRenderTargetMap;
436+ RenderTargetImpl::ContextRenderTargetMap::iterator iter = contextRenderTargetMap.find (contextId);
432437
433438 if (active)
434439 {
@@ -462,7 +467,7 @@ bool RenderTarget::setActive(bool active)
462467// //////////////////////////////////////////////////////////
463468void RenderTarget::pushGLStates ()
464469{
465- if (isActive (m_id) || setActive (true ))
470+ if (RenderTargetImpl:: isActive (m_id) || setActive (true ))
466471 {
467472 #ifdef SFML_DEBUG
468473 // make sure that the user didn't leave an unchecked OpenGL error
@@ -494,7 +499,7 @@ void RenderTarget::pushGLStates()
494499// //////////////////////////////////////////////////////////
495500void RenderTarget::popGLStates ()
496501{
497- if (isActive (m_id) || setActive (true ))
502+ if (RenderTargetImpl:: isActive (m_id) || setActive (true ))
498503 {
499504 glCheck (glMatrixMode (GL_PROJECTION));
500505 glCheck (glPopMatrix ());
@@ -523,7 +528,7 @@ void RenderTarget::resetGLStates()
523528 setActive (false );
524529 #endif
525530
526- if (isActive (m_id) || setActive (true ))
531+ if (RenderTargetImpl:: isActive (m_id) || setActive (true ))
527532 {
528533 // Make sure that extensions are initialized
529534 priv::ensureExtensionsInit ();
@@ -582,7 +587,7 @@ void RenderTarget::initialize()
582587
583588 // Generate a unique ID for this RenderTarget to track
584589 // whether it is active within a specific context
585- m_id = getUniqueId ();
590+ m_id = RenderTargetImpl:: getUniqueId ();
586591}
587592
588593
@@ -608,6 +613,9 @@ void RenderTarget::applyCurrentView()
608613// //////////////////////////////////////////////////////////
609614void RenderTarget::applyBlendMode (const BlendMode& mode)
610615{
616+ using RenderTargetImpl::factorToGlConstant;
617+ using RenderTargetImpl::equationToGlConstant;
618+
611619 // Apply the blend mode, falling back to the non-separate versions if necessary
612620 if (GLEXT_blend_func_separate)
613621 {
0 commit comments