From 8ebc0f2b24934875ea96f1940bb0d91044ce811c Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Wed, 31 Oct 2012 01:38:59 +0100 Subject: [PATCH] Add VGInitOperation for initializing OpenVG --- simgear/canvas/CMakeLists.txt | 1 + simgear/canvas/ShivaVG/src/shContext.c | 4 +- simgear/canvas/VGInitOperation.hxx | 59 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 simgear/canvas/VGInitOperation.hxx diff --git a/simgear/canvas/CMakeLists.txt b/simgear/canvas/CMakeLists.txt index dac03aba..0a10e585 100644 --- a/simgear/canvas/CMakeLists.txt +++ b/simgear/canvas/CMakeLists.txt @@ -2,6 +2,7 @@ include (SimGearComponent) set(HEADERS ODGauge.hxx + VGInitOperation.hxx ) set(SOURCES diff --git a/simgear/canvas/ShivaVG/src/shContext.c b/simgear/canvas/ShivaVG/src/shContext.c index a78bfcc5..6f2fe597 100644 --- a/simgear/canvas/ShivaVG/src/shContext.c +++ b/simgear/canvas/ShivaVG/src/shContext.c @@ -47,6 +47,8 @@ VG_API_CALL VGboolean vgCreateContextSH(VGint width, VGint height) g_context->surfaceHeight = height; /* setup GL projection */ + /* We handle viewport and projection ourselves... + glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); @@ -54,7 +56,7 @@ VG_API_CALL VGboolean vgCreateContextSH(VGint width, VGint height) gluOrtho2D(0,width,0,height); glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + glLoadIdentity();*/ return VG_TRUE; } diff --git a/simgear/canvas/VGInitOperation.hxx b/simgear/canvas/VGInitOperation.hxx new file mode 100644 index 00000000..9fb650cb --- /dev/null +++ b/simgear/canvas/VGInitOperation.hxx @@ -0,0 +1,59 @@ +// osg::Operation to initialize the OpenVG context used for path rendering +// +// Copyright (C) 2012 Thomas Geymayer +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#ifndef CANVAS_VG_INITOPERATION_HXX_ +#define CANVAS_VG_INITOPERATION_HXX_ + +#include +#include + +namespace simgear +{ +namespace canvas +{ + + /** + * Deferred graphics operation to setup OpenVG which needs a valid OpenGL + * context. Pass to osg::GraphicsContext::add and ensure it's executed before + * doing any path rendering + */ + class VGInitOperation: + public osg::GraphicsOperation + { + public: + + VGInitOperation(): + GraphicsOperation("canvas::VGInit", false) + {} + + virtual void operator()(osg::GraphicsContext* context) + { + GLint vp[4]; + glGetIntegerv(GL_VIEWPORT, vp); + + // ATTENTION: If using another OpenVG implementation ensure it doesn't + // change any OpenGL state! + vgCreateContextSH(vp[2], vp[3]); + } + + }; + +} // namespace canvas +} // namespace simgear + +#endif /* CANVAS_VG_INITOPERATION_HXX_ */ -- 2.39.5