Removed initial startup dependency on the OpenGL DLLs so only the

glcanvasc.pyd depends on them, not wxNN_N.dll


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9588 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2001-03-26 21:31:04 +00:00
parent b075a3bbfd
commit 19cf4f8086
8 changed files with 930 additions and 14 deletions

View File

@@ -76,7 +76,6 @@ D. Change to the wx2\include\wx\msw directory and copy setup0.h to
wxUSE_NEW_GRID 1 wxUSE_NEW_GRID 1
wxUSE_GLOBAL_MEMORY_OPERATORS 0 wxUSE_GLOBAL_MEMORY_OPERATORS 0
wxUSE_LIBTIFF 1 wxUSE_LIBTIFF 1
wxUSE_GLCANVAS 1
wxDIALOG_UNIT_COMPATIBILITY 0 wxDIALOG_UNIT_COMPATIBILITY 0
I also turn off the following as they are not currently used in I also turn off the following as they are not currently used in
@@ -93,6 +92,12 @@ D. Change to the wx2\include\wx\msw directory and copy setup0.h to
wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW 0 wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW 0
** NEW **
Be sure that wxUSE_GLCANVAS is defined to be 0 as wxPython now
keeps its own copy of the glcanvas sources and expects that it is
not in the main library. This is reduce the number of dependant
DLLs on the core library and therefore help reduce startup time.
2. Build the wxWindows DLL 2. Build the wxWindows DLL

View File

@@ -2,6 +2,24 @@ CHANGES.txt for wxPython
---------------------------------------------------------------------- ----------------------------------------------------------------------
?????
-----
Removed initial startup dependency on the OpenGL DLLs so only the
glcanvasc.pyd depends on them.
Changed wxFont, wxPen, wxBrush to not implicitly use the
wxThe[Font|Pen|Brush]List behind the scenes, but to use normal ctor
and dtors.
Exposed the wxThe[Font|Pen|Brush]List to wxPython.
Also wxTheColourDatabase and added a library module (in the
wxPython.lib.colourdb module) to load LOTS more colour names into the
colour database.
2.2.6 2.2.6
----- -----
@@ -9,6 +27,7 @@ No changes happened in the Python wrappers for this release, only
changes and fixes in the wxWindows library. changes and fixes in the wxWindows library.
2.2.5 2.2.5
----- -----

View File

@@ -15,7 +15,7 @@
%{ %{
#include "export.h" #include "export.h"
#include <wx/glcanvas.h> #include "myglcanvas.h"
%} %}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -56,16 +56,16 @@ extern PyObject *SWIG_newvarlink(void);
#define SWIG_name "glcanvasc" #define SWIG_name "glcanvasc"
#include "export.h" #include "export.h"
#include <wx/glcanvas.h> #include "myglcanvas.h"
static PyObject* l_output_helper(PyObject* target, PyObject* o) { static PyObject* l_output_helper(PyObject* target, PyObject* o) {
PyObject* o2; PyObject* o2;
if (!target) { if (!target) {
target = o; target = o;
} else if (target == Py_None) { } else if (target == Py_None) {
Py_DECREF(Py_None); Py_DECREF(Py_None);
target = o; target = o;
} else { } else {
if (!PyList_Check(target)) { if (!PyList_Check(target)) {
o2 = target; o2 = target;
target = PyList_New(0); target = PyList_New(0);
@@ -82,23 +82,23 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) {
PyObject* o2; PyObject* o2;
PyObject* o3; PyObject* o3;
if (!target) { if (!target) {
target = o; target = o;
} else if (target == Py_None) { } else if (target == Py_None) {
Py_DECREF(Py_None); Py_DECREF(Py_None);
target = o; target = o;
} else { } else {
if (!PyTuple_Check(target)) { if (!PyTuple_Check(target)) {
o2 = target; o2 = target;
target = PyTuple_New(1); target = PyTuple_New(1);
PyTuple_SetItem(target, 0, o2); PyTuple_SetItem(target, 0, o2);
} }
o3 = PyTuple_New(1); o3 = PyTuple_New(1);
PyTuple_SetItem(o3, 0, o); PyTuple_SetItem(o3, 0, o);
o2 = target; o2 = target;
target = PySequence_Concat(o2, o3); target = PySequence_Concat(o2, o3);
Py_DECREF(o2); Py_DECREF(o2);
Py_DECREF(o3); Py_DECREF(o3);
} }
return target; return target;
@@ -595,6 +595,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
{ "_wxPyProcess","_class_wxPyProcess",0}, { "_wxPyProcess","_class_wxPyProcess",0},
{ "_wxPyTreeCtrl","_class_wxPyTreeCtrl",0}, { "_wxPyTreeCtrl","_class_wxPyTreeCtrl",0},
{ "_wxImageHandler","_class_wxImageHandler",0}, { "_wxImageHandler","_class_wxImageHandler",0},
{ "_wxMutexGuiLocker","_class_wxMutexGuiLocker",0},
{ "_wxLog","_class_wxLog",0}, { "_wxLog","_class_wxLog",0},
{ "_class_wxToolBarBase","_wxToolBarBase",0}, { "_class_wxToolBarBase","_wxToolBarBase",0},
{ "_wxMask","_class_wxMask",0}, { "_wxMask","_class_wxMask",0},
@@ -610,6 +611,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
{ "_wxDataObject","_class_wxDataObject",0}, { "_wxDataObject","_class_wxDataObject",0},
{ "_class_wxPyFontEnumerator","_wxPyFontEnumerator",0}, { "_class_wxPyFontEnumerator","_wxPyFontEnumerator",0},
{ "_wxStaticBox","_class_wxStaticBox",0}, { "_wxStaticBox","_class_wxStaticBox",0},
{ "_wxColourDatabase","_class_wxColourDatabase",0},
{ "_wxPyDataObjectSimple","_class_wxPyDataObjectSimple",0}, { "_wxPyDataObjectSimple","_class_wxPyDataObjectSimple",0},
{ "_wxPyDropSource","_class_wxPyDropSource",0}, { "_wxPyDropSource","_class_wxPyDropSource",0},
{ "_wxChoice","_class_wxChoice",0}, { "_wxChoice","_class_wxChoice",0},
@@ -726,6 +728,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
{ "_class_wxZipFSHandler","_wxZipFSHandler",0}, { "_class_wxZipFSHandler","_wxZipFSHandler",0},
{ "_char","_wxChar",0}, { "_char","_wxChar",0},
{ "_wxBitmap","_class_wxBitmap",0}, { "_wxBitmap","_class_wxBitmap",0},
{ "_wxPenList","_class_wxPenList",0},
{ "_wxTaskBarIcon","_class_wxTaskBarIcon",0}, { "_wxTaskBarIcon","_class_wxTaskBarIcon",0},
{ "_wxPrintDialog","_class_wxPrintDialog",0}, { "_wxPrintDialog","_class_wxPrintDialog",0},
{ "_wxWindowDC","_class_wxWindowDC",0}, { "_wxWindowDC","_class_wxWindowDC",0},
@@ -741,6 +744,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
{ "_wxMessageDialog","_class_wxMessageDialog",0}, { "_wxMessageDialog","_class_wxMessageDialog",0},
{ "_class_wxValidator","_wxValidator",0}, { "_class_wxValidator","_wxValidator",0},
{ "_class_wxPyEvent","_wxPyEvent",0}, { "_class_wxPyEvent","_wxPyEvent",0},
{ "_class_wxMutexGuiLocker","_wxMutexGuiLocker",0},
{ "_wxTextEntryDialog","_class_wxTextEntryDialog",0}, { "_wxTextEntryDialog","_class_wxTextEntryDialog",0},
{ "_wxConfig","_class_wxConfig",0}, { "_wxConfig","_class_wxConfig",0},
{ "_class_wxIconizeEvent","_wxIconizeEvent",0}, { "_class_wxIconizeEvent","_wxIconizeEvent",0},
@@ -753,6 +757,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
{ "_class_wxToolBar","_wxToolBar",0}, { "_class_wxToolBar","_wxToolBar",0},
{ "_wxDropTarget","_class_wxDropTarget",0}, { "_wxDropTarget","_class_wxDropTarget",0},
{ "_class_wxStaticLine","_wxStaticLine",0}, { "_class_wxStaticLine","_wxStaticLine",0},
{ "_class_wxColourDatabase","_wxColourDatabase",0},
{ "_wxScrollEvent","_class_wxScrollEvent",0}, { "_wxScrollEvent","_class_wxScrollEvent",0},
{ "_wxToolBarToolBase","_class_wxToolBarToolBase",0}, { "_wxToolBarToolBase","_class_wxToolBarToolBase",0},
{ "_wxCalculateLayoutEvent","_class_wxCalculateLayoutEvent",0}, { "_wxCalculateLayoutEvent","_class_wxCalculateLayoutEvent",0},
@@ -781,9 +786,11 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
{ "_wxScrollWinEvent","_class_wxScrollWinEvent",0}, { "_wxScrollWinEvent","_class_wxScrollWinEvent",0},
{ "_wxGenericDragImage","_class_wxGenericDragImage",0}, { "_wxGenericDragImage","_class_wxGenericDragImage",0},
{ "_class_wxProgressDialog","_wxProgressDialog",0}, { "_class_wxProgressDialog","_wxProgressDialog",0},
{ "_class_wxBrushList","_wxBrushList",0},
{ "_wxQueryNewPaletteEvent","_class_wxQueryNewPaletteEvent",0}, { "_wxQueryNewPaletteEvent","_class_wxQueryNewPaletteEvent",0},
{ "_wxPyInputStream","_class_wxPyInputStream",0}, { "_wxPyInputStream","_class_wxPyInputStream",0},
{ "_wxPyApp","_class_wxPyApp",0}, { "_wxPyApp","_class_wxPyApp",0},
{ "_class_wxPenList","_wxPenList",0},
{ "_class_wxWindowCreateEvent","_wxWindowCreateEvent",0}, { "_class_wxWindowCreateEvent","_wxWindowCreateEvent",0},
{ "_class_wxOutputStream","_wxOutputStream",0}, { "_class_wxOutputStream","_wxOutputStream",0},
{ "_wxLogTextCtrl","_class_wxLogTextCtrl",0}, { "_wxLogTextCtrl","_class_wxLogTextCtrl",0},
@@ -847,6 +854,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
{ "_class_wxCloseEvent","_wxCloseEvent",0}, { "_class_wxCloseEvent","_wxCloseEvent",0},
{ "_wxSashEvent","_class_wxSashEvent",0}, { "_wxSashEvent","_class_wxSashEvent",0},
{ "_wxBusyInfo","_class_wxBusyInfo",0}, { "_wxBusyInfo","_class_wxBusyInfo",0},
{ "_wxFontList","_class_wxFontList",0},
{ "_class_wxMenuEvent","_wxMenuEvent",0}, { "_class_wxMenuEvent","_wxMenuEvent",0},
{ "_wxPaletteChangedEvent","_class_wxPaletteChangedEvent",0}, { "_wxPaletteChangedEvent","_class_wxPaletteChangedEvent",0},
{ "_wxJoystick","_class_wxJoystick",0}, { "_wxJoystick","_class_wxJoystick",0},
@@ -1032,12 +1040,14 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = {
{ "_wxGauge","_class_wxGauge",0}, { "_wxGauge","_class_wxGauge",0},
{ "_class_wxCheckListBox","_wxCheckListBox",0}, { "_class_wxCheckListBox","_wxCheckListBox",0},
{ "_class_wxBusyInfo","_wxBusyInfo",0}, { "_class_wxBusyInfo","_wxBusyInfo",0},
{ "_class_wxFontList","_wxFontList",0},
{ "_class_wxJoystick","_wxJoystick",0}, { "_class_wxJoystick","_wxJoystick",0},
{ "_class_wxCommandEvent","_wxCommandEvent",0}, { "_class_wxCommandEvent","_wxCommandEvent",0},
{ "_class_wxClientDC","_wxClientDC",0}, { "_class_wxClientDC","_wxClientDC",0},
{ "_class_wxSizeEvent","_wxSizeEvent",0}, { "_class_wxSizeEvent","_wxSizeEvent",0},
{ "_class_wxListCtrl","_wxListCtrl",0}, { "_class_wxListCtrl","_wxListCtrl",0},
{ "_class_wxGLCanvas","_wxGLCanvas",0}, { "_class_wxGLCanvas","_wxGLCanvas",0},
{ "_wxBrushList","_class_wxBrushList",0},
{ "_wxCustomDataObject","_class_wxCustomDataObject",0}, { "_wxCustomDataObject","_class_wxCustomDataObject",0},
{ "_class_wxLogNull","_wxLogNull",0}, { "_class_wxLogNull","_wxLogNull",0},
{ "_class_wxSize","_wxSize",0}, { "_class_wxSize","_wxSize",0},

View File

@@ -0,0 +1,720 @@
/////////////////////////////////////////////////////////////////////////////
// Name: glcanvas.cpp
// Purpose: wxGLCanvas, for using OpenGL with wxWindows under MS Windows
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "glcanvas.h"
#endif
#include "wx/wxprec.h"
#if defined(__BORLANDC__)
#pragma hdrstop
#endif
#include <wx/setup.h>
#define wxUSE_GLCANVAS 1
#if wxUSE_GLCANVAS
#ifndef WX_PRECOMP
#include <wx/frame.h>
#endif
#include <wx/msw/private.h>
#include <wx/settings.h>
#include <wx/log.h>
#include "myglcanvas.h"
wxChar wxGLCanvasClassName[] = wxT("wxGLCanvasClass");
LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
/*
* GLContext implementation
*/
wxGLContext::wxGLContext(bool isRGB, wxGLCanvas *win, const wxPalette& palette)
{
m_window = win;
m_hDC = win->GetHDC();
m_glContext = wglCreateContext((HDC) m_hDC);
wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") );
wglMakeCurrent((HDC) m_hDC, m_glContext);
}
wxGLContext::wxGLContext(
bool isRGB, wxGLCanvas *win,
const wxPalette& palette,
const wxGLContext *other /* for sharing display lists */
)
{
m_window = win;
m_hDC = win->GetHDC();
m_glContext = wglCreateContext((HDC) m_hDC);
wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") );
if( other != 0 )
wglShareLists( other->m_glContext, m_glContext );
wglMakeCurrent((HDC) m_hDC, m_glContext);
}
wxGLContext::~wxGLContext()
{
if (m_glContext)
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_glContext);
}
}
void wxGLContext::SwapBuffers()
{
if (m_glContext)
{
wglMakeCurrent((HDC) m_hDC, m_glContext);
::SwapBuffers((HDC) m_hDC); //blits the backbuffer into DC
}
}
void wxGLContext::SetCurrent()
{
if (m_glContext)
{
wglMakeCurrent((HDC) m_hDC, m_glContext);
}
/*
setupPixelFormat(hDC);
setupPalette(hDC);
*/
}
void wxGLContext::SetColour(const char *colour)
{
float r = 0.0;
float g = 0.0;
float b = 0.0;
wxColour *col = wxTheColourDatabase->FindColour(colour);
if (col)
{
r = (float)(col->Red()/256.0);
g = (float)(col->Green()/256.0);
b = (float)(col->Blue()/256.0);
glColor3f( r, g, b);
}
}
/*
* wxGLCanvas implementation
*/
IMPLEMENT_CLASS(wxGLCanvas, wxScrolledWindow)
BEGIN_EVENT_TABLE(wxGLCanvas, wxScrolledWindow)
EVT_SIZE(wxGLCanvas::OnSize)
EVT_PALETTE_CHANGED(wxGLCanvas::OnPaletteChanged)
EVT_QUERY_NEW_PALETTE(wxGLCanvas::OnQueryNewPalette)
END_EVENT_TABLE()
wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name,
int *attribList, const wxPalette& palette) : wxScrolledWindow()
{
m_glContext = (wxGLContext*) NULL;
bool ret = Create(parent, id, pos, size, style, name);
if ( ret )
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
}
m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
SetupPixelFormat(attribList);
SetupPalette(palette);
m_glContext = new wxGLContext(TRUE, this, palette);
}
wxGLCanvas::wxGLCanvas( wxWindow *parent,
const wxGLContext *shared, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name,
int *attribList, const wxPalette& palette )
: wxScrolledWindow()
{
m_glContext = (wxGLContext*) NULL;
bool ret = Create(parent, id, pos, size, style, name);
if ( ret )
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
}
m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
SetupPixelFormat(attribList);
SetupPalette(palette);
m_glContext = new wxGLContext(TRUE, this, palette, shared );
}
// Not very useful for wxMSW, but this is to be wxGTK compliant
wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name,
int *attribList, const wxPalette& palette ):
wxScrolledWindow()
{
m_glContext = (wxGLContext*) NULL;
bool ret = Create(parent, id, pos, size, style, name);
if ( ret )
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
}
m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
SetupPixelFormat(attribList);
SetupPalette(palette);
wxGLContext *sharedContext=0;
if (shared) sharedContext=shared->GetContext();
m_glContext = new wxGLContext(TRUE, this, palette, sharedContext );
}
wxGLCanvas::~wxGLCanvas()
{
if (m_glContext)
delete m_glContext;
::ReleaseDC((HWND) GetHWND(), (HDC) m_hDC);
}
// Replaces wxWindow::Create functionality, since we need to use a different window class
bool wxGLCanvas::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
{
/*
Suggestion from Kelly Brock <kbrock@8cs.com> (not yet implemented):
OpenGL corruption fix is simple assuming it doesn't screw anything else
up. Add the following line to the top of the create function:
wxSize parentSize = GetClientSize();
All locations within the function that use 'size' are changed to
'parentSize'.
The above corrects the initial display corruption with the GeForce and
TNT2, not sure about other NVidia cards yet.
*/
static bool registeredGLCanvasClass = FALSE;
// We have to register a special window class because we need
// the CS_OWNDC style for GLCanvas.
/*
From Angel Popov <jumpo@bitex.com>
Here are two snips from a dicussion in the OpenGL Gamedev list that explains
how this problem can be fixed:
"There are 5 common DCs available in Win95. These are aquired when you call
GetDC or GetDCEx from a window that does _not_ have the OWNDC flag.
OWNDC flagged windows do not get their DC from the common DC pool, the issue
is they require 800 bytes each from the limited 64Kb local heap for GDI."
"The deal is, if you hold onto one of the 5 shared DC's too long (as GL apps
do), Win95 will actually "steal" it from you. MakeCurrent fails,
apparently, because Windows re-assigns the HDC to a different window. The
only way to prevent this, the only reliable means, is to set CS_OWNDC."
*/
if (!registeredGLCanvasClass)
{
WNDCLASS wndclass;
static const long styleNormal = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC;
// the fields which are common to all classes
wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof( DWORD ); // VZ: what is this DWORD used for?
wndclass.hInstance = wxhInstance;
wndclass.hIcon = (HICON) NULL;
wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW);
wndclass.lpszMenuName = NULL;
// Register the GLCanvas class name
wndclass.hbrBackground = (HBRUSH)NULL;
wndclass.lpszClassName = wxGLCanvasClassName;
wndclass.style = styleNormal;
if ( !RegisterClass(&wndclass) )
{
wxLogLastError(wxT("RegisterClass(wxGLCanvasClass)"));
return FALSE;
}
registeredGLCanvasClass = TRUE;
}
wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") );
if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
return FALSE;
parent->AddChild(this);
DWORD msflags = 0;
if ( style & wxBORDER )
msflags |= WS_BORDER;
if ( style & wxTHICK_FRAME )
msflags |= WS_THICKFRAME;
/*
A general rule with OpenGL and Win32 is that any window that will have a
HGLRC built for it must have two flags: WS_CLIPCHILDREN & WS_CLIPSIBLINGS.
You can find references about this within the knowledge base and most OpenGL
books that contain the wgl function descriptions.
*/
msflags |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
// if ( style & wxCLIP_CHILDREN )
// msflags |= WS_CLIPCHILDREN;
msflags |= WS_CLIPCHILDREN;
bool want3D;
WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
// Even with extended styles, need to combine with WS_BORDER
// for them to look right.
if ( want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER ) ||
(m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))
{
msflags |= WS_BORDER;
}
// calculate the value to return from WM_GETDLGCODE handler
if ( GetWindowStyleFlag() & wxWANTS_CHARS )
{
// want everything: i.e. all keys and WM_CHAR message
m_lDlgCode = DLGC_WANTARROWS | DLGC_WANTCHARS |
DLGC_WANTTAB | DLGC_WANTMESSAGE;
}
MSWCreate(m_windowId, parent, wxGLCanvasClassName, this, NULL,
pos.x, pos.y,
WidthDefault(size.x), HeightDefault(size.y),
msflags, NULL, exStyle);
return TRUE;
}
void wxGLCanvas::SetupPixelFormat(int *attribList) // (HDC hDC)
{
int pixelFormat;
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), /* size */
1, /* version */
PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, /* support double-buffering */
PFD_TYPE_RGBA, /* color type */
16, /* prefered color depth */
0, 0, 0, 0, 0, 0, /* color bits (ignored) */
0, /* no alpha buffer */
0, /* alpha bits (ignored) */
0, /* no accumulation buffer */
0, 0, 0, 0, /* accum bits (ignored) */
16, /* depth buffer */
0, /* no stencil buffer */
0, /* no auxiliary buffers */
PFD_MAIN_PLANE, /* main layer */
0, /* reserved */
0, 0, 0, /* no layer, visible, damage masks */
};
if (attribList) {
pfd.dwFlags &= ~PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_COLORINDEX;
pfd.cColorBits = 0;
int arg=0;
while( (attribList[arg]!=0) )
{
switch( attribList[arg++] )
{
case WX_GL_RGBA:
pfd.iPixelType = PFD_TYPE_RGBA;
break;
case WX_GL_BUFFER_SIZE:
pfd.cColorBits = attribList[arg++];
break;
case WX_GL_LEVEL:
// this member looks like it may be obsolete
if (attribList[arg] > 0) {
pfd.iLayerType = PFD_OVERLAY_PLANE;
} else if (attribList[arg] < 0) {
pfd.iLayerType = PFD_UNDERLAY_PLANE;
} else {
pfd.iLayerType = PFD_MAIN_PLANE;
}
arg++;
break;
case WX_GL_DOUBLEBUFFER:
pfd.dwFlags |= PFD_DOUBLEBUFFER;
break;
case WX_GL_STEREO:
pfd.dwFlags |= PFD_STEREO;
break;
case WX_GL_AUX_BUFFERS:
pfd.cAuxBuffers = attribList[arg++];
break;
case WX_GL_MIN_RED:
pfd.cColorBits += (pfd.cRedBits = attribList[arg++]);
break;
case WX_GL_MIN_GREEN:
pfd.cColorBits += (pfd.cGreenBits = attribList[arg++]);
break;
case WX_GL_MIN_BLUE:
pfd.cColorBits += (pfd.cBlueBits = attribList[arg++]);
break;
case WX_GL_MIN_ALPHA:
// doesn't count in cColorBits
pfd.cAlphaBits = attribList[arg++];
break;
case WX_GL_DEPTH_SIZE:
pfd.cDepthBits = attribList[arg++];
break;
case WX_GL_STENCIL_SIZE:
pfd.cStencilBits = attribList[arg++];
break;
case WX_GL_MIN_ACCUM_RED:
pfd.cAccumBits += (pfd.cAccumRedBits = attribList[arg++]);
break;
case WX_GL_MIN_ACCUM_GREEN:
pfd.cAccumBits += (pfd.cAccumGreenBits = attribList[arg++]);
break;
case WX_GL_MIN_ACCUM_BLUE:
pfd.cAccumBits += (pfd.cAccumBlueBits = attribList[arg++]);
break;
case WX_GL_MIN_ACCUM_ALPHA:
pfd.cAccumBits += (pfd.cAccumAlphaBits = attribList[arg++]);
break;
default:
break;
}
}
}
pixelFormat = ChoosePixelFormat((HDC) m_hDC, &pfd);
if (pixelFormat == 0) {
MessageBox(WindowFromDC((HDC) m_hDC), wxT("ChoosePixelFormat failed."), wxT("Error"),
MB_ICONERROR | MB_OK);
exit(1);
}
if (SetPixelFormat((HDC) m_hDC, pixelFormat, &pfd) != TRUE) {
MessageBox(WindowFromDC((HDC) m_hDC), wxT("SetPixelFormat failed."), wxT("Error"),
MB_ICONERROR | MB_OK);
exit(1);
}
}
void wxGLCanvas::SetupPalette(const wxPalette& palette)
{
int pixelFormat = GetPixelFormat((HDC) m_hDC);
PIXELFORMATDESCRIPTOR pfd;
DescribePixelFormat((HDC) m_hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
if (pfd.dwFlags & PFD_NEED_PALETTE)
{
}
else
{
return;
}
m_palette = palette;
if ( !m_palette.Ok() )
{
m_palette = CreateDefaultPalette();
}
if (m_palette.Ok())
{
SelectPalette((HDC) m_hDC, (HPALETTE) m_palette.GetHPALETTE(), FALSE);
RealizePalette((HDC) m_hDC);
}
}
wxPalette wxGLCanvas::CreateDefaultPalette()
{
PIXELFORMATDESCRIPTOR pfd;
int paletteSize;
int pixelFormat = GetPixelFormat((HDC) m_hDC);
DescribePixelFormat((HDC) m_hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
paletteSize = 1 << pfd.cColorBits;
LOGPALETTE* pPal =
(LOGPALETTE*) malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
pPal->palVersion = 0x300;
pPal->palNumEntries = paletteSize;
/* build a simple RGB color palette */
{
int redMask = (1 << pfd.cRedBits) - 1;
int greenMask = (1 << pfd.cGreenBits) - 1;
int blueMask = (1 << pfd.cBlueBits) - 1;
int i;
for (i=0; i<paletteSize; ++i) {
pPal->palPalEntry[i].peRed =
(((i >> pfd.cRedShift) & redMask) * 255) / redMask;
pPal->palPalEntry[i].peGreen =
(((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
pPal->palPalEntry[i].peBlue =
(((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
pPal->palPalEntry[i].peFlags = 0;
}
}
HPALETTE hPalette = CreatePalette(pPal);
free(pPal);
wxPalette palette;
palette.SetHPALETTE((WXHPALETTE) hPalette);
return palette;
}
void wxGLCanvas::SwapBuffers()
{
if (m_glContext)
m_glContext->SwapBuffers();
}
void wxGLCanvas::OnSize(wxSizeEvent& event)
{
int width, height;
GetClientSize(& width, & height);
if (m_glContext)
{
m_glContext->SetCurrent();
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
glMatrixMode(GL_MODELVIEW);
}
}
void wxGLCanvas::SetCurrent()
{
if (m_glContext)
{
m_glContext->SetCurrent();
}
}
void wxGLCanvas::SetColour(const char *colour)
{
if (m_glContext)
m_glContext->SetColour(colour);
}
// TODO: Have to have this called by parent frame (?)
// So we need wxFrame to call OnQueryNewPalette for all children...
void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent& event)
{
/* realize palette if this is the current window */
if ( GetPalette()->Ok() ) {
::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE());
::SelectPalette((HDC) GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
::RealizePalette((HDC) GetHDC());
Refresh();
event.SetPaletteRealized(TRUE);
}
else
event.SetPaletteRealized(FALSE);
}
// I think this doesn't have to be propagated to child windows.
void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event)
{
/* realize palette if this is *not* the current window */
if ( GetPalette() &&
GetPalette()->Ok() && (this != event.GetChangedWindow()) )
{
::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE());
::SelectPalette((HDC) GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
::RealizePalette((HDC) GetHDC());
Refresh();
}
}
/* Give extensions proper function names. */
/* EXT_vertex_array */
void glArrayElementEXT(GLint i)
{
}
void glColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer)
{
}
void glDrawArraysEXT(GLenum mode, GLint first, GLsizei count)
{
#ifdef GL_EXT_vertex_array
static PFNGLDRAWARRAYSEXTPROC proc = 0;
if ( !proc )
{
proc = (PFNGLDRAWARRAYSEXTPROC) wglGetProcAddress("glDrawArraysEXT");
}
if ( proc )
(* proc) (mode, first, count);
#endif
}
void glEdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *pointer)
{
}
void glGetPointervEXT(GLenum pname, GLvoid* *params)
{
}
void glIndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer)
{
}
void glNormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer)
{
#ifdef GL_EXT_vertex_array
static PFNGLNORMALPOINTEREXTPROC proc = 0;
if ( !proc )
{
proc = (PFNGLNORMALPOINTEREXTPROC) wglGetProcAddress("glNormalPointerEXT");
}
if ( proc )
(* proc) (type, stride, count, pointer);
#endif
}
void glTexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer)
{
}
void glVertexPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer)
{
#ifdef GL_EXT_vertex_array
static PFNGLVERTEXPOINTEREXTPROC proc = 0;
if ( !proc )
{
proc = (PFNGLVERTEXPOINTEREXTPROC) wglGetProcAddress("glVertexPointerEXT");
}
if ( proc )
(* proc) (size, type, stride, count, pointer);
#endif
}
/* EXT_color_subtable */
void glColorSubtableEXT(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *table)
{
}
/* EXT_color_table */
void glColorTableEXT(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table)
{
}
void glCopyColorTableEXT(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width)
{
}
void glGetColorTableEXT(GLenum target, GLenum format, GLenum type, GLvoid *table)
{
}
void glGetColorTableParamaterfvEXT(GLenum target, GLenum pname, GLfloat *params)
{
}
void glGetColorTavleParameterivEXT(GLenum target, GLenum pname, GLint *params)
{
}
/* SGI_compiled_vertex_array */
void glLockArraysSGI(GLint first, GLsizei count)
{
}
void glUnlockArraysSGI()
{
}
/* SGI_cull_vertex */
void glCullParameterdvSGI(GLenum pname, GLdouble* params)
{
}
void glCullParameterfvSGI(GLenum pname, GLfloat* params)
{
}
/* SGI_index_func */
void glIndexFuncSGI(GLenum func, GLclampf ref)
{
}
/* SGI_index_material */
void glIndexMaterialSGI(GLenum face, GLenum mode)
{
}
/* WIN_swap_hint */
void glAddSwapHintRectWin(GLint x, GLint y, GLsizei width, GLsizei height)
{
}
#endif
// wxUSE_GLCANVAS

View File

@@ -0,0 +1,140 @@
/////////////////////////////////////////////////////////////////////////////
// Name: glcanvas.h
// Purpose: wxGLCanvas, for using OpenGL with wxWindows under Windows
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma interface "glcanvas.h"
#endif
#ifndef _WX_GLCANVAS_H_
#define _WX_GLCANVAS_H_
#include <wx/setup.h>
#define wxUSE_GLCANVAS 1
#if wxUSE_GLCANVAS
#include <wx/palette.h>
#include <wx/scrolwin.h>
#include <windows.h>
#include "gl/gl.h"
//---------------------------------------------------------------------------
// Constants for attriblist
//---------------------------------------------------------------------------
// The generic GL implementation doesn't support most of these options,
// such as stereo, auxiliary buffers, alpha channel, and accum buffer.
// Other implementations may actually support them.
enum
{
WX_GL_RGBA=1, /* use true color palette */
WX_GL_BUFFER_SIZE, /* bits for buffer if not WX_GL_RGBA */
WX_GL_LEVEL, /* 0 for main buffer, >0 for overlay, <0 for underlay */
WX_GL_DOUBLEBUFFER, /* use doublebuffer */
WX_GL_STEREO, /* use stereoscopic display */
WX_GL_AUX_BUFFERS, /* number of auxiliary buffers */
WX_GL_MIN_RED, /* use red buffer with most bits (> MIN_RED bits) */
WX_GL_MIN_GREEN, /* use green buffer with most bits (> MIN_GREEN bits) */
WX_GL_MIN_BLUE, /* use blue buffer with most bits (> MIN_BLUE bits) */
WX_GL_MIN_ALPHA, /* use blue buffer with most bits (> MIN_ALPHA bits) */
WX_GL_DEPTH_SIZE, /* bits for Z-buffer (0,16,32) */
WX_GL_STENCIL_SIZE, /* bits for stencil buffer */
WX_GL_MIN_ACCUM_RED, /* use red accum buffer with most bits (> MIN_ACCUM_RED bits) */
WX_GL_MIN_ACCUM_GREEN, /* use green buffer with most bits (> MIN_ACCUM_GREEN bits) */
WX_GL_MIN_ACCUM_BLUE, /* use blue buffer with most bits (> MIN_ACCUM_BLUE bits) */
WX_GL_MIN_ACCUM_ALPHA /* use blue buffer with most bits (> MIN_ACCUM_ALPHA bits) */
};
class wxGLCanvas; /* forward reference */
class wxGLContext: public wxObject
{
public:
wxGLContext(bool isRGB, wxGLCanvas *win, const wxPalette& palette = wxNullPalette);
wxGLContext(
bool isRGB, wxGLCanvas *win,
const wxPalette& WXUNUSED(palette),
const wxGLContext *other /* for sharing display lists */
);
~wxGLContext();
void SetCurrent();
void SetColour(const char *colour);
void SwapBuffers();
inline wxWindow* GetWindow() const { return m_window; }
inline WXHDC GetHDC() const { return m_hDC; }
inline HGLRC GetGLRC() const { return m_glContext; }
public:
HGLRC m_glContext;
WXHDC m_hDC;
wxWindow* m_window;
};
class wxGLCanvas: public wxScrolledWindow
{
DECLARE_CLASS(wxGLCanvas)
public:
wxGLCanvas(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = "GLCanvas", int *attribList = 0, const wxPalette& palette = wxNullPalette);
wxGLCanvas( wxWindow *parent, const wxGLContext *shared = (wxGLContext *)NULL,
wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "GLCanvas",
int *attribList = (int*) NULL, const wxPalette& palette = wxNullPalette );
wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared = (wxGLCanvas *)NULL, wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = "GLCanvas", int *attribList = 0, const wxPalette& palette = wxNullPalette );
~wxGLCanvas();
// Replaces wxWindow::Create functionality, since we need to use a different window class
bool Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name);
void SetCurrent();
void SetColour(const char *colour);
void SwapBuffers();
void OnSize(wxSizeEvent& event);
void OnQueryNewPalette(wxQueryNewPaletteEvent& event);
void OnPaletteChanged(wxPaletteChangedEvent& event);
inline wxGLContext* GetContext() const { return m_glContext; }
inline WXHDC GetHDC() const { return m_hDC; }
void SetupPixelFormat(int *attribList = (int*) NULL);
void SetupPalette(const wxPalette& palette);
wxPalette CreateDefaultPalette();
inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; }
protected:
wxGLContext* m_glContext; // this is typedef-ed ptr, in fact
wxPalette m_palette;
WXHDC m_hDC;
DECLARE_EVENT_TABLE()
};
#endif
// wxUSE_GLCANVAS
#endif
// _WX_GLCANVAS_H_

View File

@@ -0,0 +1,17 @@
//----------------------------------------------------------------------
//
// For MSW I keep my own copy of the glcanvas code. This lets me build
// the main wxWindows library without OpenGL support and the DLL
// depenencies that go along with it. The DLL dependencies will then
// be localized to this extension module, will not need to be loaded
// when the core is started up, and won't make the core unrunnable on
// systems that don't have OpenGL.
//
//----------------------------------------------------------------------
#if defined(__WXMSW__)
#include "msw/myglcanvas.h"
#else
#include <wx/glcanvas.h>
#endif

View File

@@ -327,6 +327,7 @@ if BUILD_GLCANVAS or GL_ONLY:
print 'Preparing GLCANVAS...' print 'Preparing GLCANVAS...'
location = 'contrib/glcanvas' location = 'contrib/glcanvas'
swig_files = ['glcanvas.i'] swig_files = ['glcanvas.i']
other_sources = []
swig_sources = run_swig(swig_files, location, GENDIR, PKGDIR, swig_sources = run_swig(swig_files, location, GENDIR, PKGDIR,
USE_SWIG, swig_force, swig_args) USE_SWIG, swig_force, swig_args)
@@ -337,9 +338,13 @@ if BUILD_GLCANVAS or GL_ONLY:
gl_libs = ['wx_gtkd_gl', 'GL', 'GLU'] gl_libs = ['wx_gtkd_gl', 'GL', 'GLU']
else: else:
gl_libs = ['wx_gtk_gl', 'GL', 'GLU'] gl_libs = ['wx_gtk_gl', 'GL', 'GLU']
else:
other_sources = [location + '/msw/myglcanvas.cpp']
gl_libs = ['opengl32', 'glu32']
ext = Extension('glcanvasc', ext = Extension('glcanvasc',
swig_sources, swig_sources + other_sources,
include_dirs = includes, include_dirs = includes,
define_macros = defines, define_macros = defines,