summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorPeilin <peilin@multicorewareinc.com>2013-12-30 16:44:23 +0800
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-01-29 08:09:23 +0100
commit0f6fca34909535b48bad41e73e5d3d0e86c744b9 (patch)
tree5ad7d56044385573c5af2e1734c1f268f6e6eafd /chart2
parentfeade6799392fa390b79b9c4a3df51fb0054899c (diff)
add anti-aliasing init
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/view/main/DummyXShape.cxx12
-rwxr-xr-xchart2/source/view/main/OpenGLRender.cxx201
-rwxr-xr-xchart2/source/view/main/OpenGLRender.hxx9
-rw-r--r--chart2/source/view/main/OpenglShapeFactory.cxx3
4 files changed, 224 insertions, 1 deletions
diff --git a/chart2/source/view/main/DummyXShape.cxx b/chart2/source/view/main/DummyXShape.cxx
index 8890d55ac65b..7f8710fe043c 100644
--- a/chart2/source/view/main/DummyXShape.cxx
+++ b/chart2/source/view/main/DummyXShape.cxx
@@ -819,7 +819,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 1d3a9f415a66..6e8801035e2c 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 fa446d312e56..5643bc9eebb2 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 a1476cc05f7b..c5cc7e139da7 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;