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]
solver
Jonathan Westhues 2008-05-15 20:54:47 -08:00
parent e8fbf81de5
commit 65ea276fa4
3 changed files with 21 additions and 34 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);