// 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:
* 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_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) */
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 WXUNUSED_WITHOUT_GL_EXT_vertex_array(mode),
- GLint WXUNUSED_WITHOUT_GL_EXT_vertex_array(first),
- GLsizei WXUNUSED_WITHOUT_GL_EXT_vertex_array(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 WXUNUSED_WITHOUT_GL_EXT_vertex_array(type),
- GLsizei WXUNUSED_WITHOUT_GL_EXT_vertex_array(stride),
- GLsizei WXUNUSED_WITHOUT_GL_EXT_vertex_array(count),
- const GLvoid *WXUNUSED_WITHOUT_GL_EXT_vertex_array(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 WXUNUSED_WITHOUT_GL_EXT_vertex_array(size),
- GLenum WXUNUSED_WITHOUT_GL_EXT_vertex_array(type),
- GLsizei WXUNUSED_WITHOUT_GL_EXT_vertex_array(stride),
- GLsizei WXUNUSED_WITHOUT_GL_EXT_vertex_array(count),
- const GLvoid *WXUNUSED_WITHOUT_GL_EXT_vertex_array(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) */