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
parent
e8fbf81de5
commit
65ea276fa4
15
entity.cpp
15
entity.cpp
|
@ -508,16 +508,13 @@ Quaternion Entity::PointGetQuaternion(void) {
|
||||||
|
|
||||||
void Entity::LineDrawOrGetDistance(Vector a, Vector b) {
|
void Entity::LineDrawOrGetDistance(Vector a, Vector b) {
|
||||||
if(dogd.drawing) {
|
if(dogd.drawing) {
|
||||||
glPolygonOffset(-5, -5);
|
// glPolygonOffset works only on polys, not lines, so do it myself
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
Vector adj = SS.GW.projRight.Cross(SS.GW.projUp);
|
||||||
// Have to draw this as a polygon in order to make the offset work.
|
adj = adj.ScaledBy(5/SS.GW.scale);
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_LINES);
|
||||||
glxVertex3v(a);
|
glxVertex3v(a.Plus(adj));
|
||||||
glxVertex3v(b);
|
glxVertex3v(b.Plus(adj));
|
||||||
glxVertex3v(b);
|
|
||||||
glEnd();
|
glEnd();
|
||||||
glPolygonOffset(0, 0);
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
||||||
} else {
|
} else {
|
||||||
Point2d ap = SS.GW.ProjectPoint(a);
|
Point2d ap = SS.GW.ProjectPoint(a);
|
||||||
Point2d bp = SS.GW.ProjectPoint(b);
|
Point2d bp = SS.GW.ProjectPoint(b);
|
||||||
|
|
|
@ -1065,7 +1065,7 @@ void GraphicsWindow::Paint(int w, int h) {
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
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 tx = projRight.Dot(offset);
|
||||||
double ty = projUp.Dot(offset);
|
double ty = projUp.Dot(offset);
|
||||||
|
|
|
@ -24,6 +24,7 @@ int TextWndScrollPos; // The scrollbar position, in half-row units
|
||||||
int TextWndHalfRows; // The height of our window, in half-row units
|
int TextWndHalfRows; // The height of our window, in half-row units
|
||||||
|
|
||||||
HWND GraphicsWnd;
|
HWND GraphicsWnd;
|
||||||
|
HGLRC GraphicsHpgl;
|
||||||
HWND GraphicsEditControl;
|
HWND GraphicsEditControl;
|
||||||
HMENU SubMenus[100];
|
HMENU SubMenus[100];
|
||||||
struct {
|
struct {
|
||||||
|
@ -393,8 +394,10 @@ void ShowTextWindow(BOOL visible)
|
||||||
ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE);
|
ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HGLRC CreateGlContext(HDC hdc)
|
static void CreateGlContext(void)
|
||||||
{
|
{
|
||||||
|
HDC hdc = GetDC(GraphicsWnd);
|
||||||
|
|
||||||
PIXELFORMATDESCRIPTOR pfd;
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
int pixelFormat;
|
int pixelFormat;
|
||||||
|
|
||||||
|
@ -405,7 +408,7 @@ static HGLRC CreateGlContext(HDC hdc)
|
||||||
PFD_DOUBLEBUFFER;
|
PFD_DOUBLEBUFFER;
|
||||||
pfd.dwLayerMask = PFD_MAIN_PLANE;
|
pfd.dwLayerMask = PFD_MAIN_PLANE;
|
||||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||||
pfd.cColorBits = 8;
|
pfd.cColorBits = 16;
|
||||||
pfd.cDepthBits = 16;
|
pfd.cDepthBits = 16;
|
||||||
pfd.cAccumBits = 0;
|
pfd.cAccumBits = 0;
|
||||||
pfd.cStencilBits = 0;
|
pfd.cStencilBits = 0;
|
||||||
|
@ -415,37 +418,25 @@ static HGLRC CreateGlContext(HDC hdc)
|
||||||
|
|
||||||
if(!SetPixelFormat(hdc, pixelFormat, &pfd)) oops();
|
if(!SetPixelFormat(hdc, pixelFormat, &pfd)) oops();
|
||||||
|
|
||||||
HGLRC hgrc = wglCreateContext(hdc);
|
GraphicsHpgl = wglCreateContext(hdc);
|
||||||
wglMakeCurrent(hdc, hgrc);
|
wglMakeCurrent(hdc, GraphicsHpgl);
|
||||||
|
|
||||||
return hgrc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InvalidateGraphics(void)
|
void InvalidateGraphics(void)
|
||||||
{
|
{
|
||||||
InvalidateRect(GraphicsWnd, NULL, FALSE);
|
InvalidateRect(GraphicsWnd, NULL, FALSE);
|
||||||
}
|
}
|
||||||
static void PaintGraphicsWithHdc(HDC hdc)
|
void PaintGraphics(void)
|
||||||
{
|
{
|
||||||
HGLRC hgrc = CreateGlContext(hdc);
|
|
||||||
|
|
||||||
RECT r;
|
RECT r;
|
||||||
GetClientRect(GraphicsWnd, &r);
|
GetClientRect(GraphicsWnd, &r);
|
||||||
int w = r.right - r.left;
|
int w = r.right - r.left;
|
||||||
int h = r.bottom - r.top;
|
int h = r.bottom - r.top;
|
||||||
|
|
||||||
SS.GW.Paint(w, h);
|
SS.GW.Paint(w, h);
|
||||||
|
SwapBuffers(GetDC(GraphicsWnd));
|
||||||
SwapBuffers(hdc);
|
|
||||||
|
|
||||||
wglMakeCurrent(NULL, NULL);
|
|
||||||
wglDeleteContext(hgrc);
|
|
||||||
}
|
|
||||||
void PaintGraphics(void)
|
|
||||||
{
|
|
||||||
HDC hdc = GetDC(GraphicsWnd);
|
|
||||||
PaintGraphicsWithHdc(hdc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDWORD GetMilliseconds(void)
|
SDWORD GetMilliseconds(void)
|
||||||
{
|
{
|
||||||
return (SDWORD)GetTickCount();
|
return (SDWORD)GetTickCount();
|
||||||
|
@ -494,12 +485,9 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_PAINT: {
|
case WM_PAINT: {
|
||||||
InvalidateRect(GraphicsWnd, NULL, FALSE);
|
PaintGraphics();
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
HDC hdc = BeginPaint(hwnd, &ps);
|
HDC hdc = BeginPaint(hwnd, &ps);
|
||||||
|
|
||||||
PaintGraphicsWithHdc(hdc);
|
|
||||||
|
|
||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -711,6 +699,8 @@ static void CreateMainWindows(void)
|
||||||
600, 300, 200, 200, NULL, top, Instance, NULL);
|
600, 300, 200, 200, NULL, top, Instance, NULL);
|
||||||
if(!GraphicsWnd) oops();
|
if(!GraphicsWnd) oops();
|
||||||
|
|
||||||
|
CreateGlContext();
|
||||||
|
|
||||||
GraphicsEditControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "",
|
GraphicsEditControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "",
|
||||||
WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
|
WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
|
||||||
50, 50, 100, 21, GraphicsWnd, NULL, Instance, NULL);
|
50, 50, 100, 21, GraphicsWnd, NULL, Instance, NULL);
|
||||||
|
|
Loading…
Reference in New Issue