From 00a2da7d185bf2dff01f039d5df4b6bf5b75cc37 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 28 Aug 2013 17:06:07 +0200 Subject: [PATCH] Fixed cursor drawing for OpenGL. --- common/gal/cairo/cairo_gal.cpp | 2 +- common/gal/opengl/opengl_gal.cpp | 65 ++++++++++++++++++-------------- include/gal/cairo/cairo_gal.h | 2 +- include/gal/opengl/opengl_gal.h | 7 ++++ 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 058c34b338..4ed047b24c 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -792,7 +792,7 @@ void CAIRO_GAL::ClearTarget( RenderTarget aTarget ) void CAIRO_GAL::DrawCursor( const VECTOR2D& aCursorPosition ) { // Now we should only store the position of the mouse cursor - // The real drawing routines are in EndDrawing() + // The real drawing routines are in blitCursor() cursorPosition = VECTOR2D( aCursorPosition.x - cursorSize / 2, aCursorPosition.y - cursorSize / 2 ); } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index efe801d137..5b584ff10e 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -214,9 +214,11 @@ void OPENGL_GAL::EndDrawing() overlayManager.EndDrawing(); // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers - glFlush(); compositor.DrawBuffer( mainBuffer ); compositor.DrawBuffer( overlayBuffer ); + blitCursor(); + + glFlush(); SwapBuffers(); delete clientDC; @@ -737,33 +739,10 @@ void OPENGL_GAL::ClearTarget( RenderTarget aTarget ) void OPENGL_GAL::DrawCursor( const VECTOR2D& aCursorPosition ) { - if( !isCursorEnabled ) - return; - - compositor.SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING ); - - // Invert y axis - VECTOR2D cursorPosition = VECTOR2D( aCursorPosition.x, screenSize.y - aCursorPosition.y ); - - VECTOR2D cursorBegin = ToWorld( cursorPosition - - VECTOR2D( cursorSize / 2, cursorSize / 2 ) ); - VECTOR2D cursorEnd = ToWorld( cursorPosition + - VECTOR2D( cursorSize / 2, cursorSize / 2 ) ); - VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2.0; - - glLineWidth( 1.0 ); - glColor4d( cursorColor.r, cursorColor.g, cursorColor.b, cursorColor.a ); - - glBegin( GL_LINES ); - glVertex3f( cursorCenter.x, cursorBegin.y, GetMinDepth() ); - glVertex3f( cursorCenter.x, cursorEnd.y, GetMinDepth() ); - - glVertex3f( cursorBegin.x, cursorCenter.y, GetMinDepth() ); - glVertex3f( cursorEnd.x, cursorCenter.y, GetMinDepth() ); - glEnd(); - - // Restore the default color, so textures will be drawn properly - glColor4d( 1.0, 1.0, 1.0, 1.0 ); + // Now we should only store the position of the mouse cursor + // The real drawing routines are in blitCursor() + cursorPosition = VECTOR2D( aCursorPosition.x, + screenSize.y - aCursorPosition.y ); // invert Y axis } @@ -969,6 +948,36 @@ void OPENGL_GAL::initCursor( int aCursorSize ) } +void OPENGL_GAL::blitCursor() +{ + if( !isCursorEnabled ) + return; + + compositor.SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING ); + + VECTOR2D cursorBegin = ToWorld( cursorPosition - + VECTOR2D( cursorSize / 2, cursorSize / 2 ) ); + VECTOR2D cursorEnd = ToWorld( cursorPosition + + VECTOR2D( cursorSize / 2, cursorSize / 2 ) ); + VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2.0; + + glDisable( GL_TEXTURE_2D ); + glLineWidth( 1.0 ); + glColor4d( cursorColor.r, cursorColor.g, cursorColor.b, cursorColor.a ); + + glBegin( GL_LINES ); + glVertex2d( cursorCenter.x, cursorBegin.y ); + glVertex2d( cursorCenter.x, cursorEnd.y ); + + glVertex2d( cursorBegin.x, cursorCenter.y ); + glVertex2d( cursorEnd.x, cursorCenter.y ); + glEnd(); + + // Restore the default color, so textures will be drawn properly + glColor4d( 1.0, 1.0, 1.0, 1.0 ); +} + + unsigned int OPENGL_GAL::getNewGroupNumber() { wxASSERT_MSG( groups.size() < std::numeric_limits::max(), diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index be1e2fc7b4..77ba5c0a1e 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -357,7 +357,7 @@ private: virtual void initCursor( int aCursorSize ); /** - * @brief Blits cursor into current screen. + * @brief Blits cursor into the current screen. */ virtual void blitCursor( wxBufferedDC& clientDC ); diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 170b6c7a50..f8c0addee9 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -297,6 +297,8 @@ private: bool isShaderInitialized; ///< Was the shader initialized? bool isGrouping; ///< Was a group started? + VECTOR2D cursorPosition; ///< Current cursor position + // Polygon tesselation /// The tessellator GLUtesselator* tesselator; @@ -363,6 +365,11 @@ private: /// @copydoc GAL::initCursor() virtual void initCursor( int aCursorSize ); + /** + * @brief Blits cursor into the current screen. + */ + void blitCursor(); + /** * @brief Returns a valid key that can be used as a new group number. *