more X11/Linux debug-graphics fixes

This commit is contained in:
Erwin Coumans (Google)
2014-06-30 16:03:36 -07:00
parent 8e2a4f8171
commit b7402df015
4 changed files with 78 additions and 58 deletions

View File

@@ -68,8 +68,8 @@ void MyMouseButtonCallback(int button, int state, float x, float y)
} }
} }
int sWidth = 1050; int sWidth = 800;//1050;
int sHeight = 768; int sHeight = 600;//768;
GLPrimitiveRenderer* primRenderer=0; GLPrimitiveRenderer* primRenderer=0;
//GwenOpenGL3CoreRenderer* gwenRenderer=0; //GwenOpenGL3CoreRenderer* gwenRenderer=0;
Gwen::Renderer::Base* gwenRenderer =0; Gwen::Renderer::Base* gwenRenderer =0;
@@ -107,7 +107,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
stash = sth_create(512,512,renderCallbacks);//256,256);//,1024);//512,512); stash = sth_create(512,512,renderCallbacks);//256,256);//,1024);//512,512);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
if (!stash) if (!stash)
{ {
fprintf(stderr, "Could not create stash.\n"); fprintf(stderr, "Could not create stash.\n");
@@ -121,7 +121,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
float sx,sy,dx,dy,lh; float sx,sy,dx,dy,lh;
GLuint texture; GLuint texture;
const char* fontPaths[]={ const char* fontPaths[]={
"./", "./",
@@ -131,16 +131,16 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
}; };
int numPaths=sizeof(fontPaths)/sizeof(char*); int numPaths=sizeof(fontPaths)/sizeof(char*);
// Load the first truetype font from memory (just because we can). // Load the first truetype font from memory (just because we can).
FILE* fp = 0; FILE* fp = 0;
const char* fontPath ="./"; const char* fontPath ="./";
char fullFontFileName[1024]; char fullFontFileName[1024];
for (int i=0;i<numPaths;i++) for (int i=0;i<numPaths;i++)
{ {
fontPath = fontPaths[i]; fontPath = fontPaths[i];
//sprintf(fullFontFileName,"%s%s",fontPath,"OpenSans.ttf");//"DroidSerif-Regular.ttf"); //sprintf(fullFontFileName,"%s%s",fontPath,"OpenSans.ttf");//"DroidSerif-Regular.ttf");
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Regular.ttf");//OpenSans.ttf");//"DroidSerif-Regular.ttf"); sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Regular.ttf");//OpenSans.ttf");//"DroidSerif-Regular.ttf");
@@ -151,7 +151,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
assert(fp); assert(fp);
if (fp) if (fp)
{ {
@@ -195,7 +195,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
} }
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSansJapanese.ttf"); sprintf(fullFontFileName,"%s%s",fontPath,"DroidSansJapanese.ttf");
if (!(droidJapanese = sth_add_font(stash,fullFontFileName))) if (!(droidJapanese = sth_add_font(stash,fullFontFileName)))
{ {
@@ -222,7 +222,7 @@ void keyCallback(int key, int value)
{ {
printf("key = %d, value = %d\n", key,value); printf("key = %d, value = %d\n", key,value);
//pCanvas->InputKey(key,value==1); //pCanvas->InputKey(key,value==1);
int gwenKey = -1; int gwenKey = -1;
@@ -278,8 +278,8 @@ void keyCallback(int key, int value)
gwenKey = Gwen::Key::Control; gwenKey = Gwen::Key::Control;
break; break;
} }
default: default:
{ {
@@ -308,57 +308,68 @@ int main()
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow(); b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
window->setKeyboardCallback(keyCallback); window->setKeyboardCallback(keyCallback);
b3gWindowConstructionInfo wci; b3gWindowConstructionInfo wci;
wci.m_openglVersion = 2; wci.m_openglVersion = 3;
wci.m_width = sWidth; wci.m_width = sWidth;
wci.m_height = sHeight; wci.m_height = sHeight;
// wci.m_resizeCallback = MyResizeCallback; // wci.m_resizeCallback = MyResizeCallback;
window->createWindow(wci); window->createWindow(wci);
window->setResizeCallback(MyResizeCallback); window->setResizeCallback(MyResizeCallback);
window->setWindowTitle("render test"); window->setWindowTitle("render test");
int majorGlVersion, minorGlVersion; int majorGlVersion, minorGlVersion;
if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2) if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2)
{ {
printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n"); printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n");
exit(0); exit(0);
} }
if (majorGlVersion>=3) if (majorGlVersion>=3 && wci.m_openglVersion>=3)
{ {
float retinaScale = 1.f; float retinaScale = 1.f;
#ifndef __APPLE__ #ifndef __APPLE__
#ifndef _WIN32
//we need glewExperimental on Linux
glewExperimental = GL_TRUE;
#endif // _WIN32
glewInit(); glewInit();
#endif #endif
//we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue
GLuint err = glGetError();
err = glGetError();
assert(err==GL_NO_ERROR);
retinaScale = window->getRetinaScale(); retinaScale = window->getRetinaScale();
primRenderer = new GLPrimitiveRenderer(sWidth,sHeight); primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
sth_stash* font = initFont(primRenderer ); sth_stash* font = initFont(primRenderer );
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale); gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
} else } else
{ {
//OpenGL 2.x //OpenGL 2.x
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(); gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
skin.SetRender( gwenRenderer ); skin.SetRender( gwenRenderer );
pCanvas = new Gwen::Controls::Canvas( &skin ); pCanvas = new Gwen::Controls::Canvas( &skin );
pCanvas->SetSize( sWidth, sHeight); pCanvas->SetSize( sWidth, sHeight);
pCanvas->SetDrawBackground( true ); pCanvas->SetDrawBackground( true );
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) ); pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
glClearColor(1,0,0,1); glClearColor(1,0,0,1);
} }
// //
// Create a GWEN OpenGL Renderer // Create a GWEN OpenGL Renderer
@@ -368,7 +379,7 @@ int main()
// //
// Create a GWEN skin // Create a GWEN skin
// //
#ifdef USE_TEXTURED_SKIN #ifdef USE_TEXTURED_SKIN
Gwen::Skin::TexturedBase skin; Gwen::Skin::TexturedBase skin;
@@ -398,7 +409,7 @@ int main()
pUnit->SetPos( 10, 10 ); pUnit->SetPos( 10, 10 );
// //
// Create a Windows Control helper // Create a Windows Control helper
// (Processes Windows MSG's and fires input at GWEN) // (Processes Windows MSG's and fires input at GWEN)
// //
//Gwen::Input::Windows GwenInput; //Gwen::Input::Windows GwenInput;
@@ -410,7 +421,7 @@ int main()
// MSG msg; // MSG msg;
while( !window->requestedExit() ) while( !window->requestedExit() )
{ {
if (majorGlVersion<3) if (majorGlVersion<3 || wci.m_openglVersion<3)
{ {
saveOpenGLState(sWidth,sHeight); saveOpenGLState(sWidth,sHeight);
} }
@@ -437,7 +448,7 @@ int main()
} }
window->startRendering(); window->startRendering();
// Main OpenGL Render Loop // Main OpenGL Render Loop
{ {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
@@ -447,33 +458,33 @@ int main()
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
//glColor4ub(255,0,0,255); //glColor4ub(255,0,0,255);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
// saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight); // saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
@@ -485,25 +496,25 @@ int main()
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
glEnable(GL_BLEND); glEnable(GL_BLEND);
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
pCanvas->RenderCanvas(); pCanvas->RenderCanvas();
if (avoidUpdate<=0) if (avoidUpdate<=0)
avoidUpdate++; avoidUpdate++;
// SwapBuffers( GetDC( g_pHWND ) ); // SwapBuffers( GetDC( g_pHWND ) );
} }
window->endRendering(); window->endRendering();
if (majorGlVersion<3) if (majorGlVersion<3 || wci.m_openglVersion<3)
{ {
restoreOpenGLState(); restoreOpenGLState();
} }
@@ -511,6 +522,6 @@ int main()
window->closeWindow(); window->closeWindow();
delete window; delete window;
} }

View File

@@ -1,13 +1,26 @@
///See http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/ ///See http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/
bool gIntelLinuxglDrawBufferWorkaround=false;
#include "GLRenderToTexture.h" #include "GLRenderToTexture.h"
#include "Bullet3Common/b3Scalar.h" // for b3Assert #include "Bullet3Common/b3Scalar.h" // for b3Assert
#include <string.h>
#include <stdio.h>
bool gIntelLinuxglDrawBufferWorkaround=false;
GLRenderToTexture::GLRenderToTexture() GLRenderToTexture::GLRenderToTexture()
:m_framebufferName(0) :m_framebufferName(0)
{ {
const GLubyte* ven = glGetString(GL_VENDOR);
printf("ven = %s\n",ven);
if (strncmp((const char*)ven,"Intel",5)==0)
{
printf("Workaround for some crash in the Intel OpenGL driver on Linux/Ubuntu\n");
gIntelLinuxglDrawBufferWorkaround=true;
}
} }
void GLRenderToTexture::init(int width, int height, GLuint textureId, int renderTextureType) void GLRenderToTexture::init(int width, int height, GLuint textureId, int renderTextureType)

View File

@@ -17,7 +17,6 @@ struct GLRenderToTexture
bool m_initialized; bool m_initialized;
int m_renderTextureType; int m_renderTextureType;
public: public:
GLRenderToTexture(); GLRenderToTexture();
void init(int width, int height, GLuint textureId, int renderTextureType=RENDERTEXTURE_COLOR); void init(int width, int height, GLuint textureId, int renderTextureType=RENDERTEXTURE_COLOR);

View File

@@ -15,7 +15,6 @@
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
extern bool gIntelLinuxglDrawBufferWorkaround;
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
static bool forceOpenGL3 = true; static bool forceOpenGL3 = true;
@@ -235,11 +234,6 @@ void X11OpenGLWindow::enableOpenGL()
const GLubyte* ven = glGetString(GL_VENDOR); const GLubyte* ven = glGetString(GL_VENDOR);
printf("GL_VENDOR=%s\n", ven); printf("GL_VENDOR=%s\n", ven);
if (strncmp((const char*)ven,"Intel",5)==0)
{
printf("Workaround for some crash in the Intel OpenGL driver on Linux/Ubuntu\n");
gIntelLinuxglDrawBufferWorkaround=true;
}
const GLubyte* ren = glGetString(GL_RENDERER); const GLubyte* ren = glGetString(GL_RENDERER);
printf("GL_RENDERER=%s\n",ren); printf("GL_RENDERER=%s\n",ren);
const GLubyte* ver = glGetString(GL_VERSION); const GLubyte* ver = glGetString(GL_VERSION);
@@ -276,7 +270,10 @@ printf("createWindow\n");
m_data->m_root = DefaultRootWindow(m_data->m_dpy); m_data->m_root = DefaultRootWindow(m_data->m_dpy);
if (ci.m_openglVersion < 3)
{
forceOpenGL3 = false;
}
if (forceOpenGL3) if (forceOpenGL3)
{ {