dynamically switch between OpenGL 2 and OpenGL 3 (test gwen)

This commit is contained in:
Erwin Coumans
2014-06-30 14:42:11 -07:00
parent 473c2d43bf
commit 8e2a4f8171
2 changed files with 54 additions and 65 deletions

View File

@@ -305,54 +305,29 @@ extern int avoidUpdate;
int main()
{
//#define TEST_OPENGL2_GWEN
#ifdef TEST_OPENGL2_GWEN
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
window->setKeyboardCallback(keyCallback);
b3gWindowConstructionInfo wci;
wci.m_openglVersion = 2;
wci.m_width = sWidth;
wci.m_height = sHeight;
// wci.m_resizeCallback = MyResizeCallback;
window->createWindow(wci);
window->setResizeCallback(MyResizeCallback);
window->setWindowTitle("render test");
// Gwen::Renderer::OpenGL_DebugFont* pRenderer = new Gwen::Renderer::OpenGL_DebugFont();
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
int majorGlVersion, minorGlVersion;
skin.SetRender( gwenRenderer );
pCanvas = new Gwen::Controls::Canvas( &skin );
pCanvas->SetSize( sWidth, sHeight);
pCanvas->SetDrawBackground( true );
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
glClearColor(1,0,0,1);
/* while( !window->requestedExit() )
if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2)
{
window->startRendering();
// Main OpenGL Render Loop
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
window->endRendering();
printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n");
exit(0);
}
*/
//exit(0);
#else
if (majorGlVersion>=3)
{
float retinaScale = 1.f;
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
window->setKeyboardCallback(keyCallback);
b3gWindowConstructionInfo wci;
wci.m_width = sWidth;
wci.m_height = sHeight;
// wci.m_resizeCallback = MyResizeCallback;
window->createWindow(wci);
window->setResizeCallback(MyResizeCallback);
window->setWindowTitle("render test");
#ifndef __APPLE__
glewInit();
#endif
@@ -365,7 +340,24 @@ glClearColor(1,0,0,1);
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
#endif
} else
{
//OpenGL 2.x
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
skin.SetRender( gwenRenderer );
pCanvas = new Gwen::Controls::Canvas( &skin );
pCanvas->SetSize( sWidth, sHeight);
pCanvas->SetDrawBackground( true );
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
glClearColor(1,0,0,1);
}
//
@@ -418,8 +410,10 @@ glClearColor(1,0,0,1);
// MSG msg;
while( !window->requestedExit() )
{
if (majorGlVersion<3)
{
saveOpenGLState(sWidth,sHeight);
}
// Skip out if the window is closed
//if ( !IsWindowVisible( g_pHWND ) )
@@ -508,8 +502,12 @@ glClearColor(1,0,0,1);
// SwapBuffers( GetDC( g_pHWND ) );
}
window->endRendering();
if (majorGlVersion<3)
{
restoreOpenGLState();
}
}
window->closeWindow();
delete window;

View File

@@ -339,8 +339,10 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
// https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//apple_ref/doc/uid/TP40012302-CH10-SW1
//support HighResolutionOSX for Retina Macbook
if (ci.m_openglVersion>=3)
{
[m_internalData->m_myview setWantsBestResolutionOpenGLSurface:YES];
}
NSSize sz;
sz.width = 1;
sz.height = 1;
@@ -354,16 +356,9 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
[m_internalData->m_window setContentView: m_internalData->m_myview];
GLuint n = 1;
GLuint vbo[3]={-1,-1,-1};
glGenBuffers(n, vbo);
checkError("glGenBuffers");
[m_internalData->m_window setDelegate:(id) m_internalData->m_myview];
glGenBuffers(n, vbo);
checkError("glGenBuffers");
[m_internalData->m_window makeKeyAndOrderFront: nil];
@@ -371,12 +366,8 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
m_internalData->m_width = m_internalData->m_myview.GetWindowWidth;
m_internalData->m_height = m_internalData->m_myview.GetWindowHeight;
glGenBuffers(n, vbo);
checkError("glGenBuffers");
[NSApp activateIgnoringOtherApps:YES];
glGenBuffers(n, vbo);
checkError("glGenBuffers");
//[m_internalData->m_window setLevel:NSMainMenuWindowLevel];