[Libreoffice-commits] core.git: Branch 'feature/chart-opengl2' - 2 commits - chart2/source

YangZhang yangzhang at multicorewareinc.com
Mon Dec 30 23:26:30 PST 2013


 chart2/source/view/main/DummyXShape.cxx        |   12 +
 chart2/source/view/main/OpenGLRender.cxx       |  202 +++++++++++++++++++++++++
 chart2/source/view/main/OpenGLRender.hxx       |   13 +
 chart2/source/view/main/OpenglShapeFactory.cxx |    3 
 4 files changed, 229 insertions(+), 1 deletion(-)

New commits:
commit 140dc8560947e49ccc78d5ac3bf79d6232b779aa
Author: YangZhang <yangzhang at multicorewareinc.com>
Date:   Mon Dec 30 17:20:18 2013 +0800

    fix linux compilation
    
    Change-Id: I1631fe4abfd1a14d39410e6e75883949dfc15c18
    Signed-off-by: shaochunfang <shaochun at multicorewareinc.com>

diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 6e88010..d76b4fa 100755
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -996,6 +996,7 @@ void OpenGLRender::SetLine2DWidth(int width)
     m_fLineWidth = (m_fLineWidth < 0.001) ? 0.001 : m_fLineWidth;
 }
 
+#if defined( _WIN32 )
 static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     switch (message)
@@ -1106,7 +1107,7 @@ int OpenGLRender::InitMultisample(PIXELFORMATDESCRIPTOR pfd)
     DestroyWindow(hWnd);
     return  m_iArbMultisampleSupported;
 }
-
+#endif
 int OpenGLRender::GetMSAASupport()
 {
     return m_iArbMultisampleSupported;
@@ -1117,6 +1118,7 @@ int OpenGLRender::GetMSAAFormat()
     return m_iArbMultisampleFormat;
 }
 
+#if defined( _WIN32 )
 int OpenGLRender::InitTempWindow(HWND *hwnd, int width, int height, PIXELFORMATDESCRIPTOR inPfd)
 {
     PIXELFORMATDESCRIPTOR  pfd = inPfd;
@@ -1157,7 +1159,6 @@ int OpenGLRender::InitTempWindow(HWND *hwnd, int width, int height, PIXELFORMATD
     }
     return 0;
 }
-
 int OpenGLRender::WGLisExtensionSupported(const char *extension)
 {
     const size_t extlen = strlen(extension);
@@ -1194,7 +1195,7 @@ int OpenGLRender::WGLisExtensionSupported(const char *extension)
     }
     return 1;
 }
-
+#endif
 
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index 5643bc9..70b05e0 100755
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -124,7 +124,9 @@ public:
     void SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b);
     void SetLine2DWidth(int width);
     BitmapEx GetAsBitmap();
+#if defined( _WIN32 )
     int InitMultisample(PIXELFORMATDESCRIPTOR pfd);
+#endif
     int GetMSAASupport();
     int GetMSAAFormat();
 private:
@@ -134,7 +136,9 @@ private:
     int CreateFrameBufferObj();
     int RenderTexture(GLuint TexID);
     int RenderTexture2FBO(GLuint TexID);
+#if defined( _WIN32 )
     int InitTempWindow(HWND *hwnd, int width, int height, PIXELFORMATDESCRIPTOR inPfd);
+#endif
     int WGLisExtensionSupported(const char *extension);
 private:
     // Projection matrix : default 45 degree Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
commit a0fc1639bd544c48c121a4fff8e6109c8b164484
Author: Peilin <peilin at multicorewareinc.com>
Date:   Mon Dec 30 16:44:23 2013 +0800

    add anti-aliasing init

diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx
index 335e0e2..64dc65a 100644
--- a/chart2/source/view/main/DummyXShape.cxx
+++ b/chart2/source/view/main/DummyXShape.cxx
@@ -825,7 +825,17 @@ bool DummyChart::initOpengl()
         0, 0, 0                         // Layer Masks Ignored
     };
 
-    int WindowPix = ChoosePixelFormat(GLWin.hDC,&PixelFormatFront);
+    //  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);
diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx
index 1d3a9f4..6e88010 100755
--- a/chart2/source/view/main/OpenGLRender.cxx
+++ b/chart2/source/view/main/OpenGLRender.cxx
@@ -996,4 +996,205 @@ void OpenGLRender::SetLine2DWidth(int width)
     m_fLineWidth = (m_fLineWidth < 0.001) ? 0.001 : m_fLineWidth;
 }
 
+static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+    switch (message)
+    {
+    case WM_CREATE:
+        return 0;
+    case WM_CLOSE:
+        PostQuitMessage(0);
+        return 0;
+    case WM_DESTROY:
+        return 0;
+    case WM_KEYDOWN:
+        switch(wParam)
+        {
+        case VK_ESCAPE:
+            PostQuitMessage(0);
+            return 0;
+
+        case VK_SPACE:
+            break;
+        }
+    default:
+        return DefWindowProc(hwnd, message, wParam, lParam);
+    }
+}
+
+
+int OpenGLRender::InitMultisample(PIXELFORMATDESCRIPTOR pfd)
+{
+    HWND hWnd = NULL;
+    //create a temp windwo to check whether support multi-sample, if support, get the format
+    if (InitTempWindow(&hWnd, m_iWidth, m_iHeight, pfd) < 0)
+    {
+        printf("Can't create temp window to test\n");
+        return false;
+    }
+
+    // See If The String Exists In WGL!
+    if (!WGLisExtensionSupported("WGL_ARB_multisample"))
+    {
+        m_iArbMultisampleSupported = 0;
+        printf("Device doesn't support multi sample\n");
+        return false;
+    }
+    // Get Our Pixel Format
+    PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+    if (!wglChoosePixelFormatARB)
+    {
+        m_iArbMultisampleSupported = 0;
+        return false;
+    }
+    // Get Our Current Device Context
+    HDC hDC = GetDC(hWnd);
+
+    int pixelFormat;
+    int valid;
+    UINT    numFormats;
+    float   fAttributes[] = {0,0};
+    // These Attributes Are The Bits We Want To Test For In Our Sample
+    // Everything Is Pretty Standard, The Only One We Want To
+    // Really Focus On Is The SAMPLE BUFFERS ARB And WGL SAMPLES
+    // These Two Are Going To Do The Main Testing For Whether Or Not
+    // We Support Multisampling On This Hardware.
+    int iAttributes[] =
+    {
+        WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
+        WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
+        WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
+        WGL_COLOR_BITS_ARB,24,
+        WGL_ALPHA_BITS_ARB,8,
+        WGL_DEPTH_BITS_ARB,16,
+        WGL_STENCIL_BITS_ARB,0,
+        WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
+        WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
+        WGL_SAMPLES_ARB,8,
+        0,0
+    };
+    // First We Check To See If We Can Get A Pixel Format For 4 Samples
+    valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
+    // If We Returned True, And Our Format Count Is Greater Than 1
+    if (valid && numFormats >= 1)
+    {
+        m_iArbMultisampleSupported = 1;
+        m_iArbMultisampleFormat = pixelFormat;
+        wglMakeCurrent(NULL, NULL);
+        wglDeleteContext(glWin.hRC);
+        ReleaseDC(hWnd, glWin.hDC);
+        DestroyWindow(hWnd);
+        return m_iArbMultisampleSupported;
+    }
+    // Our Pixel Format With 4 Samples Failed, Test For 2 Samples
+    iAttributes[19] = 2;
+    valid = wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
+    if (valid && numFormats >= 1)
+    {
+        m_iArbMultisampleSupported = 1;
+        m_iArbMultisampleFormat = pixelFormat;
+        wglMakeCurrent(NULL, NULL);
+        wglDeleteContext(glWin.hRC);
+        ReleaseDC(hWnd, glWin.hDC);
+        DestroyWindow(hWnd);
+        return m_iArbMultisampleSupported;
+    }
+    // Return The Valid Format
+    wglMakeCurrent(NULL, NULL);
+    wglDeleteContext(glWin.hRC);
+    ReleaseDC(hWnd, glWin.hDC);
+    DestroyWindow(hWnd);
+    return  m_iArbMultisampleSupported;
+}
+
+int OpenGLRender::GetMSAASupport()
+{
+    return m_iArbMultisampleSupported;
+}
+
+int OpenGLRender::GetMSAAFormat()
+{
+    return m_iArbMultisampleFormat;
+}
+
+int OpenGLRender::InitTempWindow(HWND *hwnd, int width, int height, PIXELFORMATDESCRIPTOR inPfd)
+{
+    PIXELFORMATDESCRIPTOR  pfd = inPfd;
+    int  pfmt;
+    int ret;
+    WNDCLASS wc;
+    wc.style = 0;
+    wc.lpfnWndProc = WndProc;
+    wc.cbClsExtra = wc.cbWndExtra = 0;
+    wc.hInstance = NULL;
+    wc.hIcon = NULL;
+    wc.hCursor = NULL;
+    wc.hbrBackground = NULL;
+    wc.lpszMenuName = NULL;
+    wc.lpszClassName = (LPCSTR)"GLRenderer";
+    RegisterClass(&wc);
+    *hwnd = CreateWindow(wc.lpszClassName, NULL, WS_DISABLED, 0, 0, width, height, NULL, NULL, wc.hInstance, NULL);
+    glWin.hDC = GetDC(*hwnd);
+    pfmt = ChoosePixelFormat(glWin.hDC, &pfd);
+    if (!pfmt)
+    {
+        return -1;
+    }
+    ret = SetPixelFormat(glWin.hDC, pfmt, &pfd);
+    if(!ret)
+    {
+        return -1;
+    }
+    glWin.hRC = wglCreateContext(glWin.hDC);
+    if(!(glWin.hRC))
+    {
+        return -1;
+    }
+    ret = wglMakeCurrent(glWin.hDC, glWin.hRC);
+    if(!ret)
+    {
+        return -1;
+    }
+    return 0;
+}
+
+int OpenGLRender::WGLisExtensionSupported(const char *extension)
+{
+    const size_t extlen = strlen(extension);
+    const char *supported = NULL;
+
+    // Try To Use wglGetExtensionStringARB On Current DC, If Possible
+    PROC wglGetExtString = wglGetProcAddress("wglGetExtensionsStringARB");
+
+    if (wglGetExtString)
+        supported = ((char*(__stdcall*)(HDC))wglGetExtString)(wglGetCurrentDC());
+    // If That Failed, Try Standard Opengl Extensions String
+    if (supported == NULL)
+        supported = (char*)glGetString(GL_EXTENSIONS);
+    // If That Failed Too, Must Be No Extensions Supported
+    if (supported == NULL)
+        return 0;
+    // Begin Examination At Start Of String, Increment By 1 On False Match
+    for (const char* p = supported; ; p++)
+    {
+        // Advance p Up To The Next Possible Match
+        p = strstr(p, extension);
+
+        if (p == NULL)
+            return 0; // No Match
+
+        // Make Sure That Match Is At The Start Of The String Or That
+        // The Previous Char Is A Space, Or Else We Could Accidentally
+        // Match "wglFunkywglExtension" With "wglExtension"
+
+        // Also, Make Sure That The Following Character Is Space Or NULL
+        // Or Else "wglExtensionTwo" Might Match "wglExtension"
+        if ((p==supported || p[-1]==' ') && (p[extlen]=='\0' || p[extlen]==' '))
+            return 1; // Match
+    }
+    return 1;
+}
+
+
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx
index fa446d3..5643bc9 100755
--- a/chart2/source/view/main/OpenGLRender.hxx
+++ b/chart2/source/view/main/OpenGLRender.hxx
@@ -124,6 +124,9 @@ public:
     void SetLine2DColor(sal_uInt8 r, sal_uInt8 g, sal_uInt8 b);
     void SetLine2DWidth(int width);
     BitmapEx GetAsBitmap();
+    int InitMultisample(PIXELFORMATDESCRIPTOR pfd);
+    int GetMSAASupport();
+    int GetMSAAFormat();
 private:
     GLint LoadShaders(const char *vertexShader,const char *fragmentShader);
     int CreateTextureObj(int width, int height);
@@ -131,6 +134,8 @@ private:
     int CreateFrameBufferObj();
     int RenderTexture(GLuint TexID);
     int RenderTexture2FBO(GLuint TexID);
+    int InitTempWindow(HWND *hwnd, int width, int height, PIXELFORMATDESCRIPTOR inPfd);
+    int WGLisExtensionSupported(const char *extension);
 private:
     // Projection matrix : default 45 degree Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
     glm::mat4 m_Projection;
@@ -210,6 +215,10 @@ private:
     list <Line2DPointList> m_Line2DShapePointList;
 
     com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxRenderTarget;
+	int m_iArbMultisampleSupported;
+	int m_iArbMultisampleFormat;
+	GLint m_iSampleBufs;
+	GLint m_iSamples;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/OpenglShapeFactory.cxx b/chart2/source/view/main/OpenglShapeFactory.cxx
index 27b1ca1..4189163 100644
--- a/chart2/source/view/main/OpenglShapeFactory.cxx
+++ b/chart2/source/view/main/OpenglShapeFactory.cxx
@@ -52,6 +52,9 @@
 #include <basegfx/matrix/b3dhommatrix.hxx>
 
 #include <algorithm>
+#include <iostream>
+using namespace std;
+
 
 using namespace ::com::sun::star;
 using ::com::sun::star::uno::Reference;


More information about the Libreoffice-commits mailing list