From e2b5268504ec16350534f327adc484a1ddcb2094 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 3 Feb 2010 14:07:19 +0000 Subject: [PATCH] New try for pixel-perfect rendering -- waiting for feedbacks git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1390 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Graphics/Renderer.hpp | 16 +++++++++++- src/SFML/Graphics/Renderer.cpp | 38 ---------------------------- src/SFML/Window/Win32/ContextWGL.cpp | 4 ++- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/include/SFML/Graphics/Renderer.hpp b/include/SFML/Graphics/Renderer.hpp index d57395f4..8b550f08 100644 --- a/include/SFML/Graphics/Renderer.hpp +++ b/include/SFML/Graphics/Renderer.hpp @@ -372,7 +372,6 @@ private : bool myShaderIsValid; ///< Is the cached shader valid? (if not, the cached value is ignored) bool myBlendModeIsValid; ///< Is the cached blend mode valid? (if not, the cached value is ignored) bool myViewportIsValid; ///< Is the cached viewport valid? (if not, the cached value is ignored) - Vector2f myViewportSize; ///< Half-size of the current viewport, stored for optimiation purpose }; } // namespace sf @@ -384,4 +383,19 @@ private : //////////////////////////////////////////////////////////// /// \class sf::Renderer /// +/// sf::Renderer is the abstraction layer between SFML code +/// and the low-level drawing API (OpenGL). It manages +/// render states efficiently, and provides a lightweight +/// abstraction for rendering geometry. +/// +/// The purpose of this class is to provide a single abstract +/// entry point for everything related to low-level rendering. +/// Hiding everything behind sf::Renderer makes optimizing +/// easy, as well as porting to other technologies in the future +/// (like OpenGL ES or OpenGL 3.x). +/// +/// This class is mainly meant for internal usage, you should +/// never care about it unless you write your own sf::Drawable +/// class that uses raw geometry in its Render function. +/// //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/Renderer.cpp b/src/SFML/Graphics/Renderer.cpp index b6ab3e79..29e7b7e1 100644 --- a/src/SFML/Graphics/Renderer.cpp +++ b/src/SFML/Graphics/Renderer.cpp @@ -31,34 +31,6 @@ #include -//////////////////////////////////////////////////////////// -// Private data -//////////////////////////////////////////////////////////// -namespace -{ - // Fast float to int conversion - inline sf::Int32 Round(double value) - { - // Use a union rather than reinterpret_cast, because it doesn't break strict-aliasing - // rules and results in a correct behaviour when compiling in optimized mode - union DoubleToInt - { - double d; - sf::Int32 i[2]; - }; - - DoubleToInt u; - u.d = value + 6755399441055744.0; - - #if defined(SFML_ENDIAN_LITTLE) - return u.i[0]; - #else - return u.i[1]; - #endif - } -} - - namespace sf { //////////////////////////////////////////////////////////// @@ -215,10 +187,6 @@ void Renderer::SetViewport(const IntRect& viewport) // Store it myViewport = viewport; myViewportIsValid = true; - - // Store the half-size of the viewport for later computations - myViewportSize.x = myViewport.GetSize().x / 2.f; - myViewportSize.y = myViewport.GetSize().y / 2.f; } } @@ -365,12 +333,6 @@ void Renderer::ProcessVertex(float x, float y, float u, float v, float r, float // Transform the vertex position by the current model-view-projection matrix Vector2f position = myTransform.Transform(Vector2f(x, y)); - // Round the vertex position so that it matches the - // viewport's pixels, and thus avoid rendering artifacts - // @todo remove and find a better solution :) - position.x = Round((position.x + 1.f) * myViewportSize.x) / myViewportSize.x - 1.f; - position.y = Round((position.y + 1.f) * myViewportSize.y) / myViewportSize.y - 1.f; - // Modulate the vertex color with the current global color r *= myStates->r; g *= myStates->g; diff --git a/src/SFML/Window/Win32/ContextWGL.cpp b/src/SFML/Window/Win32/ContextWGL.cpp index b180c3a3..0de0e4df 100644 --- a/src/SFML/Window/Win32/ContextWGL.cpp +++ b/src/SFML/Window/Win32/ContextWGL.cpp @@ -45,7 +45,9 @@ myDeviceContext(NULL), myContext (NULL), myOwnsWindow (true) { - // TODO : try to create a bitmap in memory instead of a dummy window + // Creating a dummy window is mandatory: we could create a memory DC but then + // its pixel format wouldn't match the regular contexts' format, and thus + // wglShareLists would always fail. Too bad... // Create a dummy window (disabled and hidden) myWindow = CreateWindowA("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, 1, 1, NULL, NULL, GetModuleHandle(NULL), NULL);