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

Function WipeStateCache

src/SFGUI/Canvas.cpp:179–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177}
178
179void WipeStateCache( sf::RenderTarget& target ) {
180 // Make SFML disable it's **************** vertex cache without us
181 // having to call ResetGLStates() and disturbing OpenGL needlessly.
182 // This would be sooo much easier if we could somehow set
183 // myCache.UseVertexCache = false;
184 // in window by ourself every frame.
185 // SFML doesn't like to play nice with other VBO / Vertex Array
186 // users, that's for sure... It assumes that the array pointers
187 // don't get changed between calls to Draw() unless ResetGLStates()
188 // is explicitly called in between. Why do we need to call OpenGL
189 // 10+ times just to reset something this simple? No logic.
190
191 //static sf::VertexArray resetter_array( sf::TrianglesStrip, 5 );
192 //window.Draw( resetter_array );
193
194 // Or... even more evil... use memset to blank the StatesCache of
195 // the RenderWindow with zeros. Thankfully, because we are using
196 // the data structures directly from the SFML headers, if Laurent
197 // decides to change their size one day we won't even notice.
198 struct StatesCache {
199 bool glStatesSet;
200 bool ViewChanged;
201 sf::BlendMode LastBlendMode;
202 std::uint64_t LastTextureId;
203 bool UseVertexCache;
204 sf::Vertex VertexCache[4];
205 };
206
207 // All your cache are belong to us.
208 memset( reinterpret_cast<char*>( &target ) + sizeof( sf::RenderTarget ) - sizeof( StatesCache ) + 1, 0, sizeof( StatesCache ) - 1 );
209
210 // This is to make it forget it's cached viewport.
211 // Seriously... caching the viewport? Come on...
212 memset( reinterpret_cast<char*>( &target ) + sizeof( sf::RenderTarget ) - sizeof( StatesCache ) + 1, 1, 1 );
213
214 // Since we wiped SFML's cache of its bound texture, we
215 // should make sure that it stays coherent with reality :).
216 sf::Texture::bind( 0 );
217}
218
219}
220

Callers 3

ClearMethod · 0.85
DisplayMethod · 0.85
DisplayMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected