From 65ea276fa4b0a94bb1166f3418d1432014653cba Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Thu, 15 May 2008 20:54:47 -0800 Subject: [PATCH] I turned on hardware acceleration for my graphics card, and everything broke; apparently that driver didn't like me continually destroying and recreating the HPGL context, and it also didn't like me drawing zero-area polygons for my edges (which seemed like a good idea, because it let me use glPolygonOffset instead of doing that by hand). So it now all seems to work again, and faster. [git-p4: depot-paths = "//depot/solvespace/": change = 1723] --- entity.cpp | 15 ++++++--------- graphicswin.cpp | 2 +- win32/w32main.cpp | 38 ++++++++++++++------------------------ 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/entity.cpp b/entity.cpp index 9536d14..9e802f0 100644 --- a/entity.cpp +++ b/entity.cpp @@ -508,16 +508,13 @@ Quaternion Entity::PointGetQuaternion(void) { void Entity::LineDrawOrGetDistance(Vector a, Vector b) { if(dogd.drawing) { - glPolygonOffset(-5, -5); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - // Have to draw this as a polygon in order to make the offset work. - glBegin(GL_TRIANGLES); - glxVertex3v(a); - glxVertex3v(b); - glxVertex3v(b); + // glPolygonOffset works only on polys, not lines, so do it myself + Vector adj = SS.GW.projRight.Cross(SS.GW.projUp); + adj = adj.ScaledBy(5/SS.GW.scale); + glBegin(GL_LINES); + glxVertex3v(a.Plus(adj)); + glxVertex3v(b.Plus(adj)); glEnd(); - glPolygonOffset(0, 0); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } else { Point2d ap = SS.GW.ProjectPoint(a); Point2d bp = SS.GW.ProjectPoint(b); diff --git a/graphicswin.cpp b/graphicswin.cpp index 31029e4..631dd30 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -1065,7 +1065,7 @@ void GraphicsWindow::Paint(int w, int h) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glScaled(scale*2.0/w, scale*2.0/h, scale*1.0/50000); + glScaled(scale*2.0/w, scale*2.0/h, scale*1.0/10000); double tx = projRight.Dot(offset); double ty = projUp.Dot(offset); diff --git a/win32/w32main.cpp b/win32/w32main.cpp index 45ee175..3cda5e0 100644 --- a/win32/w32main.cpp +++ b/win32/w32main.cpp @@ -24,6 +24,7 @@ int TextWndScrollPos; // The scrollbar position, in half-row units int TextWndHalfRows; // The height of our window, in half-row units HWND GraphicsWnd; +HGLRC GraphicsHpgl; HWND GraphicsEditControl; HMENU SubMenus[100]; struct { @@ -393,8 +394,10 @@ void ShowTextWindow(BOOL visible) ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE); } -static HGLRC CreateGlContext(HDC hdc) -{ +static void CreateGlContext(void) +{ + HDC hdc = GetDC(GraphicsWnd); + PIXELFORMATDESCRIPTOR pfd; int pixelFormat; @@ -405,7 +408,7 @@ static HGLRC CreateGlContext(HDC hdc) PFD_DOUBLEBUFFER; pfd.dwLayerMask = PFD_MAIN_PLANE; pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 8; + pfd.cColorBits = 16; pfd.cDepthBits = 16; pfd.cAccumBits = 0; pfd.cStencilBits = 0; @@ -415,37 +418,25 @@ static HGLRC CreateGlContext(HDC hdc) if(!SetPixelFormat(hdc, pixelFormat, &pfd)) oops(); - HGLRC hgrc = wglCreateContext(hdc); - wglMakeCurrent(hdc, hgrc); - - return hgrc; + GraphicsHpgl = wglCreateContext(hdc); + wglMakeCurrent(hdc, GraphicsHpgl); } void InvalidateGraphics(void) { InvalidateRect(GraphicsWnd, NULL, FALSE); } -static void PaintGraphicsWithHdc(HDC hdc) +void PaintGraphics(void) { - HGLRC hgrc = CreateGlContext(hdc); - RECT r; GetClientRect(GraphicsWnd, &r); int w = r.right - r.left; int h = r.bottom - r.top; SS.GW.Paint(w, h); - - SwapBuffers(hdc); - - wglMakeCurrent(NULL, NULL); - wglDeleteContext(hgrc); -} -void PaintGraphics(void) -{ - HDC hdc = GetDC(GraphicsWnd); - PaintGraphicsWithHdc(hdc); + SwapBuffers(GetDC(GraphicsWnd)); } + SDWORD GetMilliseconds(void) { return (SDWORD)GetTickCount(); @@ -494,12 +485,9 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, break; case WM_PAINT: { - InvalidateRect(GraphicsWnd, NULL, FALSE); + PaintGraphics(); PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); - - PaintGraphicsWithHdc(hdc); - EndPaint(hwnd, &ps); break; } @@ -711,6 +699,8 @@ static void CreateMainWindows(void) 600, 300, 200, 200, NULL, top, Instance, NULL); if(!GraphicsWnd) oops(); + CreateGlContext(); + GraphicsEditControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS, 50, 50, 100, 21, GraphicsWnd, NULL, Instance, NULL);