X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3103e8a97e834e9793f0eb149aa82a99fd64ef9a..184fc6c87d232c6bcd0e7eb9b319183a9609ea69:/src/msw/glcanvas.cpp diff --git a/src/msw/glcanvas.cpp b/src/msw/glcanvas.cpp index 21e44ab4b5..64f90c4ef2 100644 --- a/src/msw/glcanvas.cpp +++ b/src/msw/glcanvas.cpp @@ -9,14 +9,10 @@ // 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 @@ -27,10 +23,9 @@ #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: @@ -188,78 +183,26 @@ void wxGLModule::UnregisterClasses() * 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); } @@ -275,6 +218,26 @@ BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow) 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() @@ -293,7 +256,7 @@ wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id, SetupPixelFormat(attribList); SetupPalette(palette); - m_glContext = new wxGLContext(true, this, palette); + m_glContext = new wxGLContext(this); } wxGLCanvas::wxGLCanvas( wxWindow *parent, @@ -316,7 +279,7 @@ 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 @@ -342,7 +305,7 @@ wxGLCanvas::wxGLCanvas( wxWindow *parent, const wxGLCanvas *shared, wxWindowID i wxGLContext *sharedContext=0; if (shared) sharedContext=shared->GetContext(); - m_glContext = new wxGLContext(true, this, palette, sharedContext ); + m_glContext = new wxGLContext(this, sharedContext); } wxGLCanvas::~wxGLCanvas() @@ -576,26 +539,48 @@ wxPalette wxGLCanvas::CreateDefaultPalette() 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 (?) @@ -628,146 +613,6 @@ void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event) } } -/* 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