X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/53fcd32e576b8662c0d044d2e0e65eb15df88022..3f4a2351e4c677c88c18ea812b609477adee7380:/src/msw/glcanvas.cpp diff --git a/src/msw/glcanvas.cpp b/src/msw/glcanvas.cpp index 65a39574a5..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: @@ -39,6 +34,12 @@ WX_CHECK_BUILD_OPTIONS("wxGL") #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 @@ -182,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); } @@ -269,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() @@ -287,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, @@ -310,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 @@ -336,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() @@ -401,7 +370,7 @@ static void AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, int *attribList) 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 @@ -421,38 +390,38 @@ static void AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, int *attribList) 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; @@ -470,7 +439,7 @@ void wxGLCanvas::SetupPixelFormat(int *attribList) // (HDC hDC) 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) */ @@ -539,7 +508,7 @@ wxPalette wxGLCanvas::CreateDefaultPalette() 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 */ { @@ -550,11 +519,11 @@ wxPalette wxGLCanvas::CreateDefaultPalette() for (i=0; ipalPalEntry[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; } } @@ -570,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 (?) @@ -622,137 +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 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 @@ -770,7 +630,7 @@ bool wxGLApp::InitGLVisual(int *attribList) 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) */