MCPcopy Create free account
hub / github.com/TankOs/SFGUI / Clear

Method Clear

src/SFGUI/Canvas.cpp:352–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350}
351
352void Canvas::Clear( const sf::Color& color, bool depth ) {
353 auto allocation = GetAllocation();
354
355 if( !m_render_texture ) {
356 // Make sure there is a non-internal/shared context active.
357 // After 8 hours of debugging, I found out that if you deactivate the
358 // currently active context and construct a sf::RenderTexture, it leads
359 // to the sf::RenderTexture's internal OpenGL texture being created
360 // in a "corrupted" context leading to OpenGL possibly generating the
361 // same texture IDs that it already previously generated and are still in
362 // use. Since 2 textures share the same ID, when you draw to the
363 // sf::RenderTexture it actually overwrites whatever was in the other
364 // normally created texture. This leads to very exotic looking sf::Sprites,
365 // not for the end-user. SFML context management strikes again.
366 sf::Context context;
367
368 m_render_texture = std::make_shared<sf::RenderTexture>();
369
370 if( !m_render_texture->resize( { static_cast<unsigned int>( std::floor( allocation.size.x + .5f ) ), static_cast<unsigned int>( std::floor( allocation.size.y + .5f ) ) }, sf::ContextSettings{ m_depth } ) ) {
371#if defined( SFGUI_DEBUG )
372 std::cerr << "SFGUI warning: Canvas failed to create internal SFML RenderTexture.\n";
373#endif
374 }
375 }
376 else if( m_resize ) {
377 if( !m_render_texture->resize( { static_cast<unsigned int>( std::floor( allocation.size.x + .5f ) ), static_cast<unsigned int>( std::floor( allocation.size.y + .5f ) ) }, sf::ContextSettings{ m_depth } ) ) {
378#if defined( SFGUI_DEBUG )
379 std::cerr << "SFGUI warning: Canvas failed to create internal SFML RenderTexture.\n";
380#endif
381 }
382 }
383
384 m_resize = false;
385
386 (void)m_render_texture->setActive( true );
387
388 WipeStateCache( *m_render_texture );
389
390 CheckGLError( glClearColor( color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f ) );
391 CheckGLError( glClear( GL_COLOR_BUFFER_BIT | ( depth ? GL_DEPTH_BUFFER_BIT : 0 ) ) );
392}
393
394void Canvas::Display() const {
395 if( !m_render_texture ) {

Callers 4

CreateTextMethod · 0.45
RunMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 1

WipeStateCacheFunction · 0.85

Tested by 1

RunMethod · 0.36