summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-03-14 18:51:06 +0100
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-03-14 19:59:22 +0100
commita5d178b424d55f61bb3502bb9cbc7ea96aee2cd7 (patch)
treeaafe2e279b5d467c4c514af40c32b0122e253f95 /chart2
parent04b70c682e2cdc52b144961a83d05fd203de6884 (diff)
Introduce OpenGLContext in vclopengl
Move DummyChart::initOpengl() and DummyChart::initWindow into this class. Change-Id: If3c1bb52cb2819019f0dda626612a164709b17ac
Diffstat (limited to 'chart2')
-rw-r--r--chart2/Library_chartopengl.mk20
-rw-r--r--chart2/source/view/inc/DummyXShape.hxx37
-rw-r--r--chart2/source/view/main/DummyXShape.cxx407
3 files changed, 6 insertions, 458 deletions
diff --git a/chart2/Library_chartopengl.mk b/chart2/Library_chartopengl.mk
index db3dc299b1c2..15260d48306e 100644
--- a/chart2/Library_chartopengl.mk
+++ b/chart2/Library_chartopengl.mk
@@ -18,7 +18,6 @@ $(eval $(call gb_Library_set_include,chartopengl,\
))
$(eval $(call gb_Library_use_externals,chartopengl,\
- boost_headers \
mdds_headers \
glm_headers \
mesa_headers \
@@ -56,23 +55,4 @@ $(eval $(call gb_Library_add_exception_objects,chartopengl,\
chart2/source/view/main/DummyXShape \
))
-ifeq ($(strip $(OS)),WNT)
-$(eval $(call gb_Library_use_system_win32_libs,chartopengl,\
- opengl32 \
- gdi32 \
- glu32 \
-))
-else ifeq ($(OS),MACOSX)
-$(eval $(call gb_Library_use_system_darwin_frameworks,chartopengl,\
- OpenGL \
-))
-else ifeq ($(OS),LINUX)
-$(eval $(call gb_Library_add_libs,chartopengl,\
- -ldl \
- -lGL \
- -lGLU \
- -lX11 \
-))
-endif
-
# vim: set noet sw=4 ts=4:
diff --git a/chart2/source/view/inc/DummyXShape.hxx b/chart2/source/view/inc/DummyXShape.hxx
index 553b4e1c20fa..2862b238b400 100644
--- a/chart2/source/view/inc/DummyXShape.hxx
+++ b/chart2/source/view/inc/DummyXShape.hxx
@@ -13,6 +13,7 @@
#include <cppuhelper/implbase6.hxx>
#include <vcl/OpenGLRender.hxx>
+#include <vcl/OpenGLContext.hxx>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/drawing/XShapes.hpp>
@@ -59,34 +60,8 @@
#include <vector>
#include <map>
-#include <boost/scoped_ptr.hpp>
#include <boost/unordered_map.hpp>
-#if defined( MACOSX )
-#include <OpenGL/gl.h>
-#include <OpenGL/glu.h>
-#else
-#include <GL/gl.h>
-#include <GL/glu.h>
-#endif
-
-#include <vcl/window.hxx>
-#include <vcl/syschild.hxx>
-#include <vcl/sysdata.hxx>
-
-#if defined( _WIN32 )
- #include <GL/glu.h>
- #include <GL/glext.h>
- #include <GL/wglext.h>
-#elif defined( MACOSX )
-#elif defined( UNX )
- #include <GL/glu.h>
- #include <GL/glext.h>
-#endif
-
-class SystemWindow;
-class SystemChildWindow;
-
using namespace com::sun::star;
@@ -431,15 +406,9 @@ public:
private:
- GLWindow GLWin; /// Holds the information of our new child window
-
- void createGLContext();
-
- bool initWindow();
- bool initOpengl();
- boost::scoped_ptr<Window> mpWindow;
- boost::scoped_ptr<SystemChildWindow> pWindow;
TextCache maTextCache;
+ OpenGLContext m_aGLContext;
+
public:
OpenGLRender m_GLRender;
};
diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx
index 35716c3b7eb5..0416ea9c54d4 100644
--- a/chart2/source/view/main/DummyXShape.cxx
+++ b/chart2/source/view/main/DummyXShape.cxx
@@ -1145,412 +1145,12 @@ void DummyXShapes::render()
}
}
-#if defined( WNT )
-
-bool DummyChart::initWindow()
-{
- const SystemEnvData* sysData(mpWindow->GetSystemData());
- GLWin.hWnd = sysData->hWnd;
- SystemWindowData winData;
- winData.nSize = sizeof(winData);
- pWindow.reset(new SystemChildWindow(mpWindow.get(), 0, &winData, sal_False));
-
-
- if( pWindow )
- {
- pWindow->SetMouseTransparent( sal_True );
- pWindow->SetParentClipMode( PARENTCLIPMODE_NOCLIP );
- pWindow->EnableEraseBackground( sal_False );
- pWindow->SetControlForeground();
- pWindow->SetControlBackground();
- pWindow->EnablePaint(sal_False);
- GLWin.hWnd = sysData->hWnd;
- }
-
- return true;
-}
-
-#elif defined( MACOSX )
-
-bool DummyChart::initWindow()
-{
- return false;
-}
-
-#elif defined( UNX )
-
-namespace {
-
-// we need them before glew can initialize them
-// glew needs an OpenGL context so we need to get the address manually
-void initOpenGLFunctionPointers()
-{
- glXChooseFBConfig = (GLXFBConfig*(*)(Display *dpy, int screen, const int *attrib_list, int *nelements))glXGetProcAddressARB((GLubyte*)"glXChooseFBConfig");
- glXGetVisualFromFBConfig = (XVisualInfo*(*)(Display *dpy, GLXFBConfig config))glXGetProcAddressARB((GLubyte*)"glXGetVisualFromFBConfig"); // try to find a visual for the current set of attributes
- glXGetFBConfigAttrib = (int(*)(Display *dpy, GLXFBConfig config, int attribute, int* value))glXGetProcAddressARB((GLubyte*)"glXGetFBConfigAttrib");
-
-}
-
-}
-
-bool DummyChart::initWindow()
-{
- const SystemEnvData* sysData(mpWindow->GetSystemData());
-
- GLWin.dpy = reinterpret_cast<Display*>(sysData->pDisplay);
-
- if( !glXQueryExtension( GLWin.dpy, NULL, NULL ) )
- return false;
-
- GLWin.win = sysData->aWindow;
-
- OSL_TRACE("parent window: %d", GLWin.win);
-
- XWindowAttributes xattr;
- XGetWindowAttributes( GLWin.dpy, GLWin.win, &xattr );
-
- GLWin.screen = XScreenNumberOfScreen( xattr.screen );
-
- static int visual_attribs[] =
- {
- GLX_RED_SIZE, 8,
- GLX_GREEN_SIZE, 8,
- GLX_BLUE_SIZE, 8,
- GLX_ALPHA_SIZE, 8,
- GLX_DEPTH_SIZE, 24,
- GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
- None
- };
-
- const SystemEnvData* pChildSysData = NULL;
- pWindow.reset();
-
- initOpenGLFunctionPointers();
-
- int fbCount = 0;
- GLXFBConfig* pFBC = glXChooseFBConfig( GLWin.dpy,
- GLWin.screen,
- visual_attribs, &fbCount );
-
- if(!pFBC)
- {
- SAL_WARN("chart2.opengl", "no suitable fb format found");
- return false;
- }
-
- int best_fbc = -1, best_num_samp = -1;
- for(int i = 0; i < fbCount; ++i)
- {
- XVisualInfo* pVi = glXGetVisualFromFBConfig( GLWin.dpy, pFBC[i] );
- if(pVi)
- {
- // pick the one with the most samples per pixel
- int nSampleBuf = 0;
- int nSamples = 0;
- glXGetFBConfigAttrib( GLWin.dpy, pFBC[i], GLX_SAMPLE_BUFFERS, &nSampleBuf );
- glXGetFBConfigAttrib( GLWin.dpy, pFBC[i], GLX_SAMPLES , &nSamples );
-
- if ( best_fbc < 0 || (nSampleBuf && ( nSamples > best_num_samp )) )
- {
- best_fbc = i;
- best_num_samp = nSamples;
- }
- }
- XFree( pVi );
- }
-
- XVisualInfo* vi = glXGetVisualFromFBConfig( GLWin.dpy, pFBC[best_fbc] );
- if( vi )
- {
- SystemWindowData winData;
- winData.nSize = sizeof(winData);
- OSL_TRACE("using VisualID %08X", vi->visualid);
- winData.pVisual = (void*)(vi->visual);
- pWindow.reset(new SystemChildWindow(mpWindow.get(), 0, &winData, false));
- pChildSysData = pWindow->GetSystemData();
- }
-
- if (!pWindow || !pChildSysData)
- return false;
-
- pWindow->SetMouseTransparent( true );
- pWindow->SetParentClipMode( PARENTCLIPMODE_NOCLIP );
- pWindow->EnableEraseBackground( false );
- pWindow->SetControlForeground();
- pWindow->SetControlBackground();
-
- GLWin.dpy = reinterpret_cast<Display*>(pChildSysData->pDisplay);
- GLWin.win = pChildSysData->aWindow;
- GLWin.vi = vi;
- GLWin.GLXExtensions = glXQueryExtensionsString( GLWin.dpy, GLWin.screen );
- OSL_TRACE("available GLX extensions: %s", GLWin.GLXExtensions);
-
- return true;
-}
-
-namespace {
-
-static bool errorTriggered;
-int oglErrorHandler( Display* /*dpy*/, XErrorEvent* /*evnt*/ )
-{
- errorTriggered = true;
-
- return 0;
-}
-
-}
-
-#endif
-
-#ifdef DBG_UTIL
-
-namespace {
-
-const char* getSeverityString(GLenum severity)
-{
- switch(severity)
- {
- case GL_DEBUG_SEVERITY_LOW:
- return "low";
- case GL_DEBUG_SEVERITY_MEDIUM:
- return "medium";
- case GL_DEBUG_SEVERITY_HIGH:
- return "high";
- default:
- ;
- }
-
- return "unknown";
-}
-
-const char* getSourceString(GLenum source)
-{
- switch(source)
- {
- case GL_DEBUG_SOURCE_API:
- return "API";
- case GL_DEBUG_SOURCE_SHADER_COMPILER:
- return "shader compiler";
- case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
- return "window system";
- case GL_DEBUG_SOURCE_THIRD_PARTY:
- return "third party";
- case GL_DEBUG_SOURCE_APPLICATION:
- return "Libreoffice";
- case GL_DEBUG_SOURCE_OTHER:
- return "unknown";
- default:
- ;
- }
-
- return "unknown";
-}
-
-const char* getTypeString(GLenum type)
-{
- switch(type)
- {
- case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
- return "deprecated behavior";
- case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
- return "undefined behavior";
- case GL_DEBUG_TYPE_PERFORMANCE:
- return "performance";
- case GL_DEBUG_TYPE_PORTABILITY:
- return "portability";
- case GL_DEBUG_TYPE_MARKER:
- return "marker";
- case GL_DEBUG_TYPE_PUSH_GROUP:
- return "push group";
- case GL_DEBUG_TYPE_POP_GROUP:
- return "pop group";
- case GL_DEBUG_TYPE_OTHER:
- return "other";
- default:
- ;
- }
-
- return "unkown";
-}
-
-extern "C" void
-#if defined _WIN32
-APIENTRY
-#endif
-debug_callback(GLenum source, GLenum type, GLuint id,
- GLenum severity, GLsizei , const GLchar* message, GLvoid* )
-{
- SAL_WARN("chart2.opengl", "OpenGL debug message: source: " << getSourceString(source) << ", type: "
- << getTypeString(type) << ", id: " << id << ", severity: " << getSeverityString(severity) << " with message: " << message);
-}
-
-}
-
-#endif
-
-bool DummyChart::initOpengl()
-{
- SAL_INFO("chart2.opengl", "DummyChart::initOpengl----start");
- initWindow();
- mpWindow->setPosSizePixel(0,0,0,0);
- GLWin.Width = 0;
- GLWin.Height = 0;
-
-#if defined( WNT )
- GLWin.hDC = GetDC(GLWin.hWnd);
-#elif defined( MACOSX )
-
-#elif defined( UNX )
- GLWin.ctx = glXCreateContext(GLWin.dpy,
- GLWin.vi,
- 0,
- GL_TRUE);
- if( GLWin.ctx == NULL )
- {
- OSL_TRACE("unable to create GLX context");
- return false;
- }
-#endif
-
-#if defined( WNT )
- PIXELFORMATDESCRIPTOR PixelFormatFront = // PixelFormat Tells Windows How We Want Things To Be
- {
- sizeof(PIXELFORMATDESCRIPTOR),
- 1, // Version Number
- PFD_DRAW_TO_WINDOW |
- PFD_SUPPORT_OPENGL |
- PFD_DOUBLEBUFFER,
- PFD_TYPE_RGBA, // Request An RGBA Format
- (BYTE)32, // Select Our Color Depth
- 0, 0, 0, 0, 0, 0, // Color Bits Ignored
- 0, // No Alpha Buffer
- 0, // Shift Bit Ignored
- 0, // No Accumulation Buffer
- 0, 0, 0, 0, // Accumulation Bits Ignored
- 64, // 32 bit Z-BUFFER
- 0, // 0 bit stencil buffer
- 0, // No Auxiliary Buffer
- 0, // now ignored
- 0, // Reserved
- 0, 0, 0 // Layer Masks Ignored
- };
-
- // we must check whether can set the MSAA
- int WindowPix;
- m_GLRender.InitMultisample(PixelFormatFront);
- if (m_GLRender.GetMSAASupport())
- {
- WindowPix = m_GLRender.GetMSAAFormat();
- }
- else
- {
- WindowPix = ChoosePixelFormat(GLWin.hDC,&PixelFormatFront);
- }
- SetPixelFormat(GLWin.hDC,WindowPix,&PixelFormatFront);
- GLWin.hRC = wglCreateContext(GLWin.hDC);
- wglMakeCurrent(GLWin.hDC,GLWin.hRC);
-
-#elif defined( MACOSX )
-
-#elif defined( UNX )
- if( !glXMakeCurrent( GLWin.dpy, GLWin.win, GLWin.ctx ) )
- {
- OSL_TRACE("unable to select current GLX context");
- return false;
- }
-
- int glxMinor, glxMajor;
- double nGLXVersion = 0;
- if( glXQueryVersion( GLWin.dpy, &glxMajor, &glxMinor ) )
- nGLXVersion = glxMajor + 0.1*glxMinor;
- OSL_TRACE("available GLX version: %f", nGLXVersion);
-
- GLWin.GLExtensions = glGetString( GL_EXTENSIONS );
- OSL_TRACE("available GL extensions: %s", GLWin.GLExtensions);
-
- if( GLWin.HasGLXExtension("GLX_SGI_swap_control" ) )
- {
- // enable vsync
- typedef GLint (*glXSwapIntervalProc)(GLint);
- glXSwapIntervalProc glXSwapInterval = (glXSwapIntervalProc) glXGetProcAddress( (const GLubyte*) "glXSwapIntervalSGI" );
- if( glXSwapInterval ) {
- int (*oldHandler)(Display* /*dpy*/, XErrorEvent* /*evnt*/);
-
- // replace error handler temporarily
- oldHandler = XSetErrorHandler( oglErrorHandler );
-
- errorTriggered = false;
-
- glXSwapInterval( 1 );
-
- // sync so that we possibly get an XError
- glXWaitGL();
- XSync(GLWin.dpy, false);
-
- if( errorTriggered )
- OSL_TRACE("error when trying to set swap interval, NVIDIA or Mesa bug?");
- else
- OSL_TRACE("set swap interval to 1 (enable vsync)");
-
- // restore the error handler
- XSetErrorHandler( oldHandler );
- }
- }
-
-#endif
-
- m_GLRender.InitOpenGL(GLWin);
-
-#ifdef DBG_UTIL
- // only enable debug output in dbgutil build
- if( GLEW_ARB_debug_output )
- {
- glEnable(GL_DEBUG_OUTPUT);
- glDebugMessageCallback(&debug_callback, NULL);
- }
-
-#endif
-
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- // Enable depth test
- glEnable(GL_DEPTH_TEST);
- // Accept fragment if it closer to the camera than the former one
- glDepthFunc(GL_LESS);
-
-#if defined( WNT )
- SwapBuffers(GLWin.hDC);
- glFlush();
-#elif defined( MACOSX )
-
-#elif defined( UNX )
- glXSwapBuffers(GLWin.dpy, GLWin.win);
-#endif
- glEnable(GL_LIGHTING);
- GLfloat light_direction[] = { 0.0 , 0.0 , 1.0 };
- GLfloat materialDiffuse[] = { 1.0 , 1.0 , 1.0 , 1.0};
- glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_direction);
- glMaterialfv(GL_FRONT,GL_DIFFUSE,materialDiffuse);
- glEnable(GL_LIGHT0);
- glEnable(GL_NORMALIZE);
- SAL_INFO("chart2.opengl", "DummyChart::initOpengl----end");
- return true;
-}
-
-
DummyChart::DummyChart(uno::Reference< drawing::XShape > xTarget):
- mpWindow(new Window(0, WB_NOBORDER|WB_NODIALOGCONTROL)),
m_GLRender(xTarget)
{
SAL_INFO("chart2.opengl", "DummyXShape::DummyChart()-----test: ");
setName("com.sun.star.chart2.shapes");
- createGLContext();
-}
-
-void DummyChart::createGLContext()
-{
- initOpengl();
+ m_aGLContext.init(m_GLRender);
}
void SAL_CALL DummyChart::setPosition( const awt::Point& aPosition )
@@ -1569,8 +1169,7 @@ void SAL_CALL DummyChart::setSize( const awt::Size& aSize )
SAL_INFO("chart2.opengl", "DummyChart::setSize()---aSize.Width = " << aSize.Width << ", aSize.Height = " << aSize.Height);
int width = aSize.Width / OPENGL_SCALE_VALUE;
int height = aSize.Height / OPENGL_SCALE_VALUE;
- mpWindow->SetSizePixel(Size(width, height));
- pWindow->SetSizePixel(Size(width, height));
+ m_aGLContext.setWinSize(Size(width, height));
DummyXShape::setSize(awt::Size(0,0));
m_GLRender.SetSize(width, height);
SAL_INFO("chart2.opengl", "DummyChart::GLRender.Width = " << width << ", GLRender.Height = " << height);
@@ -1586,7 +1185,7 @@ void DummyChart::render()
DummyXShapes::render();
#endif
m_GLRender.renderToBitmap();
-}
+ }
void DummyChart::clear()
{