// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "glcanvas.h"
-#endif
-
#include "wx/wxprec.h"
#if defined(__BORLANDC__)
-#pragma hdrstop
+ #pragma hdrstop
#endif
#if wxUSE_GLCANVAS
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/app.h"
+ #include "wx/module.h"
#endif
-#include "wx/module.h"
-
#include "wx/msw/private.h"
// DLL options compatibility check:
#include "wx/glcanvas.h"
+#if GL_EXT_vertex_array
+ #define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) name
+#else
+ #define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) WXUNUSED(name)
+#endif
+
/*
The following two compiler directives are specific to the Microsoft Visual
C++ family of compilers
* GLContext implementation
*/
-wxGLContext::wxGLContext(bool WXUNUSED(isRGB), wxGLCanvas *win, const wxPalette& WXUNUSED(palette))
-{
- m_window = win;
-
- m_hDC = win->GetHDC();
+IMPLEMENT_CLASS(wxGLContext, wxObject)
- 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 WXUNUSED(isRGB), wxGLCanvas *win,
- const wxPalette& WXUNUSED(palette),
- const wxGLContext *other /* for sharing display lists */
- )
+wxGLContext::wxGLContext(wxGLCanvas* win, const wxGLContext* other /* for sharing display lists */)
{
- m_window = win;
-
- m_hDC = win->GetHDC();
-
- m_glContext = wglCreateContext((HDC) m_hDC);
+ m_glContext = wglCreateContext((HDC) win->GetHDC());
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);
+ // If this context happens to be the current context, wglDeleteContext() makes it un-current first.
wglDeleteContext(m_glContext);
- }
}
-void wxGLContext::SwapBuffers()
+void wxGLContext::SetCurrent(const wxGLCanvas& win) const
{
- 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 wxChar *colour)
-{
- wxColour col = wxTheColourDatabase->Find(colour);
- if (col.Ok())
- {
- float r = (float)(col.Red()/256.0);
- float g = (float)(col.Green()/256.0);
- float b = (float)(col.Blue()/256.0);
- glColor3f( r, g, b);
- }
+ wglMakeCurrent((HDC) win.GetHDC(), m_glContext);
}
EVT_QUERY_NEW_PALETTE(wxGLCanvas::OnQueryNewPalette)
END_EVENT_TABLE()
+wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id, int *attribList,
+ const wxPoint& pos, const wxSize& size, long style,
+ const wxString& name, const wxPalette& palette) : wxWindow()
+{
+ m_glContext = NULL;
+
+ if (Create(parent, id, pos, size, style, name))
+ {
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
+ }
+
+ m_hDC = (WXHDC) ::GetDC((HWND) GetHWND());
+
+ SetupPixelFormat(attribList);
+ SetupPalette(palette);
+
+ // This ctor does *not* create an instance of wxGLContext,
+ // m_glContext intentionally remains NULL.
+}
+
wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style, const wxString& name,
int *attribList, const wxPalette& palette) : wxWindow()
SetupPixelFormat(attribList);
SetupPalette(palette);
- m_glContext = new wxGLContext(true, this, palette);
+ m_glContext = new wxGLContext(this);
}
wxGLCanvas::wxGLCanvas( wxWindow *parent,
SetupPixelFormat(attribList);
SetupPalette(palette);
- m_glContext = new wxGLContext(true, this, palette, shared );
+ m_glContext = new wxGLContext(this, shared);
}
// Not very useful for wxMSW, but this is to be wxGTK compliant
wxGLContext *sharedContext=0;
if (shared) sharedContext=shared->GetContext();
- m_glContext = new wxGLContext(true, this, palette, sharedContext );
+ m_glContext = new wxGLContext(this, sharedContext);
}
wxGLCanvas::~wxGLCanvas()
pfd.iPixelType = PFD_TYPE_RGBA;
break;
case WX_GL_BUFFER_SIZE:
- pfd.cColorBits = attribList[arg++];
+ pfd.cColorBits = (BYTE)attribList[arg++];
break;
case WX_GL_LEVEL:
// this member looks like it may be obsolete
pfd.dwFlags |= PFD_STEREO;
break;
case WX_GL_AUX_BUFFERS:
- pfd.cAuxBuffers = attribList[arg++];
+ pfd.cAuxBuffers = (BYTE)attribList[arg++];
break;
case WX_GL_MIN_RED:
- pfd.cColorBits += (pfd.cRedBits = attribList[arg++]);
+ pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cRedBits = (BYTE)attribList[arg++]));
break;
case WX_GL_MIN_GREEN:
- pfd.cColorBits += (pfd.cGreenBits = attribList[arg++]);
+ pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cGreenBits = (BYTE)attribList[arg++]));
break;
case WX_GL_MIN_BLUE:
- pfd.cColorBits += (pfd.cBlueBits = attribList[arg++]);
+ pfd.cColorBits = (BYTE)(pfd.cColorBits + (pfd.cBlueBits = (BYTE)attribList[arg++]));
break;
case WX_GL_MIN_ALPHA:
// doesn't count in cColorBits
- pfd.cAlphaBits = attribList[arg++];
+ pfd.cAlphaBits = (BYTE)attribList[arg++];
break;
case WX_GL_DEPTH_SIZE:
- pfd.cDepthBits = attribList[arg++];
+ pfd.cDepthBits = (BYTE)attribList[arg++];
break;
case WX_GL_STENCIL_SIZE:
- pfd.cStencilBits = attribList[arg++];
+ pfd.cStencilBits = (BYTE)attribList[arg++];
break;
case WX_GL_MIN_ACCUM_RED:
- pfd.cAccumBits += (pfd.cAccumRedBits = attribList[arg++]);
+ pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumRedBits = (BYTE)attribList[arg++]));
break;
case WX_GL_MIN_ACCUM_GREEN:
- pfd.cAccumBits += (pfd.cAccumGreenBits = attribList[arg++]);
+ pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumGreenBits = (BYTE)attribList[arg++]));
break;
case WX_GL_MIN_ACCUM_BLUE:
- pfd.cAccumBits += (pfd.cAccumBlueBits = attribList[arg++]);
+ pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumBlueBits = (BYTE)attribList[arg++]));
break;
case WX_GL_MIN_ACCUM_ALPHA:
- pfd.cAccumBits += (pfd.cAccumAlphaBits = attribList[arg++]);
+ pfd.cAccumBits = (BYTE)(pfd.cAccumBits + (pfd.cAccumAlphaBits = (BYTE)attribList[arg++]));
break;
default:
break;
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, /* support double-buffering */
PFD_TYPE_RGBA, /* color type */
- 16, /* prefered color depth */
+ 16, /* preferred color depth */
0, 0, 0, 0, 0, 0, /* color bits (ignored) */
0, /* no alpha buffer */
0, /* alpha bits (ignored) */
LOGPALETTE* pPal =
(LOGPALETTE*) malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
pPal->palVersion = 0x300;
- pPal->palNumEntries = paletteSize;
+ pPal->palNumEntries = (WORD)paletteSize;
/* build a simple RGB color palette */
{
for (i=0; i<paletteSize; ++i) {
pPal->palPalEntry[i].peRed =
- (((i >> pfd.cRedShift) & redMask) * 255) / redMask;
+ (BYTE)((((i >> pfd.cRedShift) & redMask) * 255) / redMask);
pPal->palPalEntry[i].peGreen =
- (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
+ (BYTE)((((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask);
pPal->palPalEntry[i].peBlue =
- (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
+ (BYTE)((((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask);
pPal->palPalEntry[i].peFlags = 0;
}
}
void wxGLCanvas::SwapBuffers()
{
- if (m_glContext)
- m_glContext->SwapBuffers();
+ ::SwapBuffers((HDC) m_hDC);
}
void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
{
}
+void wxGLCanvas::SetCurrent(const wxGLContext& RC) const
+{
+ // although on MSW it works even if the window is still hidden, it doesn't
+ // under wxGTK and documentation mentions that SetCurrent() can only be
+ // called for a shown window, so check it
+ wxASSERT_MSG( GetParent()->IsShown(), _T("can't make hidden GL canvas current") );
+
+ RC.SetCurrent(*this);
+}
+
void wxGLCanvas::SetCurrent()
{
+ // although on MSW it works even if the window is still hidden, it doesn't
+ // under wxGTK and documentation mentions that SetCurrent() can only be
+ // called for a shown window, so check it
+ wxASSERT_MSG( GetParent()->IsShown(),
+ _T("can't make hidden GL canvas current") );
+
if (m_glContext)
{
- m_glContext->SetCurrent();
+ m_glContext->SetCurrent(*this);
}
}
void wxGLCanvas::SetColour(const wxChar *colour)
{
- if (m_glContext)
- m_glContext->SetColour(colour);
+ wxColour col = wxTheColourDatabase->Find(colour);
+
+ if (col.Ok())
+ {
+ float r = (float)(col.Red()/256.0);
+ float g = (float)(col.Green()/256.0);
+ float b = (float)(col.Blue()/256.0);
+ glColor3f( r, g, b);
+ }
}
// TODO: Have to have this called by parent frame (?)
}
}
-/* Give extensions proper function names. */
-
-/* EXT_vertex_array */
-void glArrayElementEXT(GLint WXUNUSED(i))
-{
-}
-
-void glColorPointerEXT(GLint WXUNUSED(size), GLenum WXUNUSED(type), GLsizei WXUNUSED(stride), GLsizei WXUNUSED(count), const GLvoid *WXUNUSED(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 WXUNUSED(stride), GLsizei WXUNUSED(count), const GLboolean *WXUNUSED(pointer))
-{
-}
-
-void glGetPointervEXT(GLenum WXUNUSED(pname), GLvoid* *WXUNUSED(params))
-{
-}
-
-void glIndexPointerEXT(GLenum WXUNUSED(type), GLsizei WXUNUSED(stride), GLsizei WXUNUSED(count), const GLvoid *WXUNUSED(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 WXUNUSED(size), GLenum WXUNUSED(type), GLsizei WXUNUSED(stride), GLsizei WXUNUSED(count), const GLvoid *WXUNUSED(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 WXUNUSED(target), GLsizei WXUNUSED(start), GLsizei WXUNUSED(count), GLenum WXUNUSED(format), GLenum WXUNUSED(type), const GLvoid *WXUNUSED(table))
-{
-}
-
-/* EXT_color_table */
-void glColorTableEXT(GLenum WXUNUSED(target), GLenum WXUNUSED(internalformat), GLsizei WXUNUSED(width), GLenum WXUNUSED(format), GLenum WXUNUSED(type), const GLvoid *WXUNUSED(table))
-{
-}
-
-void glCopyColorTableEXT(GLenum WXUNUSED(target), GLenum WXUNUSED(internalformat), GLint WXUNUSED(x), GLint WXUNUSED(y), GLsizei WXUNUSED(width))
-{
-}
-
-void glGetColorTableEXT(GLenum WXUNUSED(target), GLenum WXUNUSED(format), GLenum WXUNUSED(type), GLvoid *WXUNUSED(table))
-{
-}
-
-void glGetColorTableParamaterfvEXT(GLenum WXUNUSED(target), GLenum WXUNUSED(pname), GLfloat *WXUNUSED(params))
-{
-}
-
-void glGetColorTavleParameterivEXT(GLenum WXUNUSED(target), GLenum WXUNUSED(pname), GLint *WXUNUSED(params))
-{
-}
-
-/* SGI_compiled_vertex_array */
-void glLockArraysSGI(GLint WXUNUSED(first), GLsizei WXUNUSED(count))
-{
-}
-
-void glUnlockArraysSGI()
-{
-}
-
-
-/* SGI_cull_vertex */
-void glCullParameterdvSGI(GLenum WXUNUSED(pname), GLdouble* WXUNUSED(params))
-{
-}
-
-void glCullParameterfvSGI(GLenum WXUNUSED(pname), GLfloat* WXUNUSED(params))
-{
-}
-
-/* SGI_index_func */
-void glIndexFuncSGI(GLenum WXUNUSED(func), GLclampf WXUNUSED(ref))
-{
-}
-
-/* SGI_index_material */
-void glIndexMaterialSGI(GLenum WXUNUSED(face), GLenum WXUNUSED(mode))
-{
-}
-
-/* WIN_swap_hint */
-void glAddSwapHintRectWin(GLint WXUNUSED(x), GLint WXUNUSED(y), GLsizei WXUNUSED(width), GLsizei WXUNUSED(height))
-{
-}
-
//---------------------------------------------------------------------------
// wxGLApp
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, /* support double-buffering */
PFD_TYPE_RGBA, /* color type */
- 16, /* prefered color depth */
+ 16, /* preferred color depth */
0, 0, 0, 0, 0, 0, /* color bits (ignored) */
0, /* no alpha buffer */
0, /* alpha bits (ignored) */