110
62
GLFramebufferTexture2DProc framebufferTexture2D = NULL;
111
63
GLGenerateMipmapProc generateMipmap = NULL;
113
GLBindBufferProc bindBuffer = NULL;
114
GLDeleteBuffersProc deleteBuffers = NULL;
115
GLGenBuffersProc genBuffers = NULL;
116
GLBufferDataProc bufferData = NULL;
117
GLBufferSubDataProc bufferSubData = NULL;
119
GLGetShaderivProc getShaderiv = NULL;
120
GLGetShaderInfoLogProc getShaderInfoLog = NULL;
121
GLGetProgramivProc getProgramiv = NULL;
122
GLGetProgramInfoLogProc getProgramInfoLog = NULL;
123
GLCreateShaderProc createShader = NULL;
124
GLShaderSourceProc shaderSource = NULL;
125
GLCompileShaderProc compileShader = NULL;
126
GLCreateProgramProc createProgram = NULL;
127
GLAttachShaderProc attachShader = NULL;
128
GLLinkProgramProc linkProgram = NULL;
129
GLValidateProgramProc validateProgram = NULL;
130
GLDeleteShaderProc deleteShader = NULL;
131
GLDeleteProgramProc deleteProgram = NULL;
132
GLUseProgramProc useProgram = NULL;
133
GLGetUniformLocationProc getUniformLocation = NULL;
134
GLUniform1fProc uniform1f = NULL;
135
GLUniform1iProc uniform1i = NULL;
136
GLUniform2fProc uniform2f = NULL;
137
GLUniform2iProc uniform2i = NULL;
138
GLUniform3fProc uniform3f = NULL;
139
GLUniform3iProc uniform3i = NULL;
140
GLUniform4fProc uniform4f = NULL;
141
GLUniform4iProc uniform4i = NULL;
142
GLUniformMatrix4fvProc uniformMatrix4fv = NULL;
143
GLGetAttribLocationProc getAttribLocation = NULL;
147
GLCreateShaderObjectARBProc createShaderObjectARB = NULL;
148
GLCreateProgramObjectARBProc createProgramObjectARB = NULL;
149
GLCompileShaderARBProc compileShaderARB = NULL;
150
GLShaderSourceARBProc shaderSourceARB = NULL;
151
GLValidateProgramARBProc validateProgramARB = NULL;
152
GLDeleteObjectARBProc deleteObjectARB = NULL;
153
GLAttachObjectARBProc attachObjectARB = NULL;
154
GLLinkProgramARBProc linkProgramARB = NULL;
155
GLUseProgramObjectARBProc useProgramObjectARB = NULL;
156
GLGetUniformLocationARBProc getUniformLocationARB = NULL;
157
GLGetAttribLocationARBProc getAttribLocationARB = NULL;
158
GLGetObjectParameterivProc getObjectParameteriv = NULL;
159
GLGetInfoLogProc getInfoLog = NULL;
163
GLEnableVertexAttribArrayProc enableVertexAttribArray = NULL;
164
GLDisableVertexAttribArrayProc disableVertexAttribArray = NULL;
165
GLVertexAttribPointerProc vertexAttribPointer = NULL;
167
GLGenRenderbuffersProc genRenderbuffers = NULL;
168
GLDeleteRenderbuffersProc deleteRenderbuffers = NULL;
169
GLFramebufferRenderbufferProc framebufferRenderbuffer = NULL;
170
GLBindRenderbufferProc bindRenderbuffer = NULL;
171
GLRenderbufferStorageProc renderbufferStorage = NULL;
173
65
bool textureFromPixmap = true;
174
66
bool textureRectangle = false;
175
67
bool textureNonPowerOfTwo = false;
176
bool textureNonPowerOfTwoMipmap = false;
177
68
bool textureEnvCombine = false;
178
69
bool textureEnvCrossbar = false;
179
70
bool textureBorderClamp = false;
180
71
bool textureCompression = false;
181
72
GLint maxTextureSize = 0;
182
bool fboSupported = false;
183
bool fboEnabled = false;
184
bool fboStencilSupported = false;
185
bool vboSupported = false;
186
bool vboEnabled = false;
187
bool shaders = false;
74
bool fragmentProgram = false;
188
75
GLint maxTextureUnits = 1;
190
77
bool canDoSaturated = false;
191
78
bool canDoSlightlySaturated = false;
193
80
unsigned int vsyncCount = 0;
195
bool stencilBuffer = false;
198
GLuint createShaderARBWrapper (GLenum type)
200
return static_cast <GLuint> ((GL::createShaderObjectARB) (type));
203
GLuint createProgramARBWrapper (GLenum type)
205
return static_cast <GLuint> ((GL::createProgramObjectARB) ());
208
void shaderSourceARBWrapper (GLuint shader, GLsizei count, const GLchar **string, const GLint *length)
210
(GL::shaderSourceARB) (static_cast <GLhandleARB> (shader), count, string, length);
213
void compileShaderARBWrapper (GLuint shader)
215
(GL::compileShaderARB) (static_cast <GLhandleARB> (shader));
218
void validateProgramARBWrapper (GLuint program)
220
(GL::validateProgramARB) (static_cast <GLhandleARB> (program));
223
void deleteShaderARBWrapper (GLuint shader)
225
(GL::deleteObjectARB) (static_cast <GLhandleARB> (shader));
228
void deleteProgramARBWrapper (GLuint program)
230
(GL::deleteObjectARB) (static_cast <GLhandleARB> (program));
233
void attachShaderARBWrapper (GLuint program, GLuint shader)
235
(GL::attachObjectARB) (static_cast <GLhandleARB> (program), static_cast <GLhandleARB> (shader));
238
void linkProgramARBWrapper (GLuint program)
240
(GL::linkProgramARB) (static_cast <GLhandleARB> (program));
243
void useProgramARBWrapper (GLuint program)
245
(GL::useProgramObjectARB) (static_cast <GLhandleARB> (program));
248
int getUniformLocationARBWrapper (GLuint program, const GLchar *name)
250
return (GL::getUniformLocationARB) (static_cast <GLhandleARB> (program), name);
253
int getAttribLocationARBWrapper (GLuint program, const GLchar *name)
255
return (GL::getAttribLocationARB) (static_cast <GLhandleARB> (program), name);
258
void getProgramInfoLogARBWrapper (GLuint object, int maxLen, int *len, char *log)
260
(GL::getInfoLog) (static_cast <GLhandleARB> (object), maxLen, len, log);
263
void getShaderInfoLogARBWrapper (GLuint object, int maxLen, int *len, char *log)
265
(GL::getInfoLog) (static_cast <GLhandleARB> (object), maxLen, len, log);
268
void getShaderivARBWrapper (GLuint object, GLenum type, int *param)
270
(GL::getObjectParameteriv) (static_cast <GLhandleARB> (object), type, param);
273
void getProgramivARBWrapper (GLuint object, GLenum type, int *param)
275
(GL::getObjectParameteriv) (static_cast <GLhandleARB> (object), type, param);
81
unsigned int unthrottledFrames = 0;
281
84
CompOutput *targetOutput = NULL;
284
* Callback object to create GLPrograms automatically when using GLVertexBuffer.
286
class GLScreenAutoProgram : public GLVertexBuffer::AutoProgram
289
GLScreenAutoProgram (GLScreen *gScreen) : gScreen(gScreen) {}
291
GLProgram *getProgram (GLShaderParameters ¶ms)
293
const GLShaderData *shaderData = gScreen->getShaderData (params);
294
std::list<const GLShaderData *> tempShaders;
295
tempShaders.push_back (shaderData);
296
return gScreen->getProgram (tempShaders);
308
void swapIntervalGLX (Display *d, int interval)
310
// Docs: http://www.opengl.org/registry/specs/SGI/swap_control.txt
311
if (GL::swapInterval)
312
GL::swapInterval (interval);
315
int waitVSyncGLX (int wait,
320
* While glXSwapBuffers/glXCopySubBufferMESA are meant to do a
321
* flush before they blit, it is best to not let that happen.
322
* Because that flush would occur after GL::waitVideoSync, causing
323
* a delay and the final blit to be slightly out of sync resulting
324
* in tearing. So we need to do a glFinish before we wait for
325
* vsync, to absolutely minimize tearing.
329
// Docs: http://www.opengl.org/registry/specs/SGI/video_sync.txt
330
if (GL::waitVideoSync)
331
return GL::waitVideoSync (wait, remainder, count);
344
void swapIntervalEGL (Display *display, int interval)
346
eglSwapInterval (eglGetDisplay (display), interval);
349
int waitVSyncEGL (int wait,
362
87
GLScreen::glInitContext (XVisualInfo *visinfo)
365
DetectionWorkaround workaround;
374
const char *eglExtensions, *glExtensions;
375
XWindowAttributes attr;
376
EGLint count, visualid;
377
EGLConfig configs[1024];
378
CompOption::Vector o (0);
380
const EGLint config_attribs[] = {
381
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
386
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
387
EGL_CONFIG_CAVEAT, EGL_NONE,
392
const EGLint context_attribs[] = {
393
EGL_CONTEXT_CLIENT_VERSION, 2,
397
xdpy = screen->dpy ();
398
dpy = eglGetDisplay ((EGLNativeDisplayType)xdpy);
399
if (!eglInitialize (dpy, &major, &minor))
401
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
405
eglBindAPI (EGL_OPENGL_ES_API);
407
if (!eglChooseConfig (dpy, config_attribs, configs, 1024, &count))
409
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
413
if (!XGetWindowAttributes (xdpy, screen->root (), &attr))
415
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
420
int msaaBuffers = MAXSHORT;
421
int msaaSamples = MAXSHORT;
422
visualid = XVisualIDFromVisual (attr.visual);
425
for (int i = 0; i < count; ++i)
427
eglGetConfigAttrib (dpy, configs[i], EGL_SAMPLE_BUFFERS, &val);
428
if (val > msaaBuffers)
433
eglGetConfigAttrib (dpy, configs[i], EGL_SAMPLES, &val);
434
if (val > msaaSamples)
439
eglGetConfigAttrib (dpy, configs[i], EGL_NATIVE_VISUAL_ID, &val);
447
overlay = CompositeScreen::get (screen)->overlay ();
448
priv->surface = eglCreateWindowSurface (dpy, config, overlay, 0);
449
if (priv->surface == EGL_NO_SURFACE)
451
compLogMessage ("opengl", CompLogLevelFatal,
452
"eglCreateWindowSurface failed");
453
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
457
// Do not preserve buffer contents on swap
458
eglSurfaceAttrib (dpy, priv->surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED);
460
priv->ctx = eglCreateContext (dpy, config, EGL_NO_CONTEXT, context_attribs);
461
if (priv->ctx == EGL_NO_CONTEXT)
463
compLogMessage ("opengl", CompLogLevelFatal, "eglCreateContext failed");
464
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
468
if (!eglMakeCurrent (dpy, priv->surface, priv->surface, priv->ctx))
470
compLogMessage ("opengl", CompLogLevelFatal,
471
"eglMakeCurrent failed");
472
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
476
eglExtensions = (const char *) eglQueryString (dpy, EGL_EXTENSIONS);
477
glExtensions = (const char *) glGetString (GL_EXTENSIONS);
479
if (!glExtensions || !eglExtensions)
481
compLogMessage ("opengl", CompLogLevelFatal,
482
"No valid GL extensions string found.");
483
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
487
GL::textureFromPixmap = true;
488
GL::textureNonPowerOfTwo = true;
489
GL::fboSupported = true;
490
GL::fboEnabled = true;
491
GL::vboSupported = true;
492
GL::vboEnabled = true;
494
GL::stencilBuffer = true;
495
GL::maxTextureUnits = 4;
496
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &GL::maxTextureSize);
498
GL::createImage = (GL::EGLCreateImageKHRProc)
499
eglGetProcAddress ("eglCreateImageKHR");
500
GL::destroyImage = (GL::EGLDestroyImageKHRProc)
501
eglGetProcAddress ("eglDestroyImageKHR");
502
GL::eglImageTargetTexture = (GL::GLEGLImageTargetTexture2DOESProc)
503
eglGetProcAddress ("glEGLImageTargetTexture2DOES");
505
if (!strstr (eglExtensions, "EGL_KHR_image_pixmap") ||
506
!strstr (glExtensions, "GL_OES_EGL_image") ||
507
!GL::createImage || !GL::destroyImage || !GL::eglImageTargetTexture)
509
compLogMessage ("opengl", CompLogLevelFatal,
510
"GL_OES_EGL_image is missing");
511
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
515
// work around efika supporting GL_BGRA directly instead of via this extension
517
if (!strstr (glExtensions, "GL_EXT_texture_format_BGRA8888"))
519
compLogMessage ("opengl", CompLogLevelFatal,
520
"GL_EXT_texture_format_BGRA8888 is missing");
521
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
526
if (strstr (glExtensions, "GL_OES_texture_npot"))
527
GL::textureNonPowerOfTwoMipmap = true;
529
if (strstr (eglExtensions, "EGL_NV_post_sub_buffer"))
530
GL::postSubBuffer = (GL::EGLPostSubBufferNVProc)
531
eglGetProcAddress ("eglPostSubBufferNV");
533
GL::fboStencilSupported = GL::fboSupported &&
534
strstr (glExtensions, "GL_OES_packed_depth_stencil");
536
if (!GL::fboSupported &&
539
compLogMessage ("opengl", CompLogLevelFatal,
540
"GL_EXT_framebuffer_object or EGL_NV_post_sub_buffer are required");
541
screen->handleCompizEvent ("opengl", "fatal_fallback", o);
545
GL::activeTexture = glActiveTexture;
546
GL::genFramebuffers = glGenFramebuffers;
547
GL::deleteFramebuffers = glDeleteFramebuffers;
548
GL::bindFramebuffer = glBindFramebuffer;
549
GL::checkFramebufferStatus = glCheckFramebufferStatus;
550
GL::framebufferTexture2D = glFramebufferTexture2D;
551
GL::generateMipmap = glGenerateMipmap;
553
GL::bindBuffer = glBindBuffer;
554
GL::deleteBuffers = glDeleteBuffers;
555
GL::genBuffers = glGenBuffers;
556
GL::bufferData = glBufferData;
557
GL::bufferSubData = glBufferSubData;
559
GL::getShaderiv = glGetShaderiv;
560
GL::getShaderInfoLog = glGetShaderInfoLog;
561
GL::getProgramiv = glGetProgramiv;
562
GL::getProgramInfoLog = glGetProgramInfoLog;
563
GL::createShader = glCreateShader;
564
GL::shaderSource = (GL::GLShaderSourceProc) glShaderSource;
565
GL::compileShader = glCompileShader;
566
GL::createProgram = glCreateProgram;
567
GL::attachShader = glAttachShader;
568
GL::linkProgram = glLinkProgram;
569
GL::validateProgram = glValidateProgram;
570
GL::deleteShader = glDeleteShader;
571
GL::deleteProgram = glDeleteProgram;
572
GL::useProgram = glUseProgram;
573
GL::getUniformLocation = glGetUniformLocation;
574
GL::uniform1f = glUniform1f;
575
GL::uniform1i = glUniform1i;
576
GL::uniform2f = glUniform2f;
577
GL::uniform2i = glUniform2i;
578
GL::uniform3f = glUniform3f;
579
GL::uniform3i = glUniform3i;
580
GL::uniform4f = glUniform4f;
581
GL::uniform4i = glUniform4i;
582
GL::uniformMatrix4fv = glUniformMatrix4fv;
583
GL::getAttribLocation = glGetAttribLocation;
585
GL::enableVertexAttribArray = glEnableVertexAttribArray;
586
GL::disableVertexAttribArray = glDisableVertexAttribArray;
587
GL::vertexAttribPointer = glVertexAttribPointer;
589
GL::genRenderbuffers = glGenRenderbuffers;
590
GL::deleteRenderbuffers = glDeleteRenderbuffers;
591
GL::bindRenderbuffer = glBindRenderbuffer;
592
GL::framebufferRenderbuffer = glFramebufferRenderbuffer;
593
GL::renderbufferStorage = glRenderbufferStorage;
595
glClearColor (0.0, 0.0, 0.0, 1.0);
596
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
598
glEnable (GL_CULL_FACE);
602
priv->lighting = false;
604
priv->filter[NOTHING_TRANS_FILTER] = GLTexture::Fast;
605
priv->filter[SCREEN_TRANS_FILTER] = GLTexture::Good;
606
priv->filter[WINDOW_TRANS_FILTER] = GLTexture::Good;
608
if (GL::textureFromPixmap)
609
registerBindPixmap (EglTexture::bindPixmapToTexture);
611
priv->incorrectRefreshRate = false;
615
89
Display *dpy = screen->dpy ();
616
90
const char *glExtensions;
617
91
GLfloat globalAmbient[] = { 0.1f, 0.1f, 0.1f, 0.1f };
618
92
GLfloat ambientLight[] = { 0.0f, 0.0f, 0.0f, 0.0f };
619
93
GLfloat diffuseLight[] = { 0.9f, 0.9f, 0.9f, 0.9f };
620
94
GLfloat light0Position[] = { -0.5f, 0.5f, -9.0f, 1.0f };
95
const char *glRenderer;
621
96
CompOption::Vector o (0);
623
98
priv->ctx = glXCreateContext (dpy, visinfo, NULL, True);
770
242
getProcAddress ("glFramebufferTexture2DEXT");
771
243
GL::generateMipmap = (GL::GLGenerateMipmapProc)
772
244
getProcAddress ("glGenerateMipmapEXT");
773
GL::genRenderbuffers = (GL::GLGenRenderbuffersProc)
774
getProcAddress ("glGenRenderbuffersEXT");
775
GL::deleteRenderbuffers = (GL::GLDeleteRenderbuffersProc)
776
getProcAddress ("glDeleteRenderbuffersEXT");
777
GL::bindRenderbuffer = (GL::GLBindRenderbufferProc)
778
getProcAddress ("glBindRenderbufferEXT");
779
GL::framebufferRenderbuffer = (GL::GLFramebufferRenderbufferProc)
780
getProcAddress ("glFramebufferRenderbufferEXT");
781
GL::renderbufferStorage = (GL::GLRenderbufferStorageProc)
782
getProcAddress ("glRenderbufferStorageEXT");
784
246
if (GL::genFramebuffers &&
785
247
GL::deleteFramebuffers &&
786
248
GL::bindFramebuffer &&
787
249
GL::checkFramebufferStatus &&
788
250
GL::framebufferTexture2D &&
789
GL::generateMipmap &&
790
GL::genRenderbuffers &&
791
GL::deleteRenderbuffers &&
792
GL::bindRenderbuffer &&
793
GL::framebufferRenderbuffer &&
794
GL::renderbufferStorage
796
GL::fboSupported = true;
799
GL::fboStencilSupported = GL::fboSupported &&
800
strstr (glExtensions, "GL_EXT_packed_depth_stencil");
802
if (strstr (glExtensions, "GL_ARB_vertex_buffer_object"))
804
GL::bindBuffer = (GL::GLBindBufferProc)
805
getProcAddress ("glBindBufferARB");
806
GL::deleteBuffers = (GL::GLDeleteBuffersProc)
807
getProcAddress ("glDeleteBuffersARB");
808
GL::genBuffers = (GL::GLGenBuffersProc)
809
getProcAddress ("glGenBuffersARB");
810
GL::bufferData = (GL::GLBufferDataProc)
811
getProcAddress ("glBufferDataARB");
812
GL::bufferSubData = (GL::GLBufferSubDataProc)
813
getProcAddress ("glBufferSubDataARB");
815
if (GL::bindBuffer &&
820
GL::vboSupported = true;
823
priv->updateRenderMode ();
825
if (strstr (glExtensions, "GL_ARB_fragment_shader") &&
826
strstr (glExtensions, "GL_ARB_vertex_shader") &&
827
strstr (glExtensions, "GL_ARB_shader_objects") &&
828
strstr (glExtensions, "GL_ARB_shading_language_100"))
830
GL::getShaderiv = (GL::GLGetShaderivProc) GL::getShaderivARBWrapper;
831
GL::getShaderInfoLog = (GL::GLGetShaderInfoLogProc) GL::getShaderInfoLogARBWrapper;
832
GL::getProgramiv = (GL::GLGetProgramivProc) GL::getProgramivARBWrapper;
833
GL::getProgramInfoLog = (GL::GLGetProgramInfoLogProc) GL::getProgramInfoLogARBWrapper;
834
GL::getObjectParameteriv = (GL::GLGetObjectParameterivProc) getProcAddress ("glGetObjectParameterivARB");
835
GL::getInfoLog = (GL::GLGetInfoLogProc) getProcAddress ("glGetInfoLogARB");
836
GL::createShader = (GL::GLCreateShaderProc) GL::createShaderARBWrapper;
837
GL::createShaderObjectARB = (GL::GLCreateShaderObjectARBProc) getProcAddress ("glCreateShaderObjectARB");
838
GL::shaderSource = (GL::GLShaderSourceProc) GL::shaderSourceARBWrapper;
839
GL::shaderSourceARB = (GL::GLShaderSourceARBProc) getProcAddress ("glShaderSourceARB");
840
GL::compileShader = (GL::GLCompileShaderProc) GL::compileShaderARBWrapper;
841
GL::compileShaderARB = (GL::GLCompileShaderARBProc) getProcAddress ("glCompileShaderARB");
842
GL::createProgram = (GL::GLCreateProgramProc) GL::createProgramARBWrapper;
843
GL::createProgramObjectARB = (GL::GLCreateProgramObjectARBProc) getProcAddress ("glCreateProgramObjectARB");
844
GL::attachShader = GL::attachShaderARBWrapper;
845
GL::attachObjectARB = (GL::GLAttachObjectARBProc) getProcAddress ("glAttachObjectARB");
846
GL::linkProgram = GL::linkProgramARBWrapper;
847
GL::linkProgramARB = (GL::GLLinkProgramARBProc) getProcAddress ("glLinkProgramARB");
848
GL::validateProgram = GL::validateProgramARBWrapper;
849
GL::validateProgramARB = (GL::GLValidateProgramARBProc) getProcAddress ("glValidateProgramARB");
850
GL::deleteShader = GL::deleteShaderARBWrapper;
851
GL::deleteProgram = GL::deleteProgramARBWrapper;
852
GL::deleteObjectARB = (GL::GLDeleteObjectARBProc) getProcAddress ("glDeleteObjectARB");
853
GL::useProgram = GL::useProgramARBWrapper;
854
GL::useProgramObjectARB = (GL::GLUseProgramObjectARBProc) getProcAddress ("glUseProgramObjectARB");
855
GL::getUniformLocation = GL::getUniformLocationARBWrapper;
856
GL::getUniformLocationARB = (GL::GLGetUniformLocationARBProc) getProcAddress ("glGetUniformLocationARB");
857
GL::uniform1f = (GL::GLUniform1fProc) getProcAddress ("glUniform1fARB");
858
GL::uniform1i = (GL::GLUniform1iProc) getProcAddress ("glUniform1iARB");
859
GL::uniform2f = (GL::GLUniform2fProc) getProcAddress ("glUniform2fARB");
860
GL::uniform2i = (GL::GLUniform2iProc) getProcAddress ("glUniform2iARB");
861
GL::uniform3f = (GL::GLUniform3fProc) getProcAddress ("glUniform3fARB");
862
GL::uniform3i = (GL::GLUniform3iProc) getProcAddress ("glUniform3iARB");
863
GL::uniform4f = (GL::GLUniform4fProc) getProcAddress ("glUniform4fARB");
864
GL::uniform4i = (GL::GLUniform4iProc) getProcAddress ("glUniform4iARB");
865
GL::uniformMatrix4fv = (GL::GLUniformMatrix4fvProc) getProcAddress ("glUniformMatrix4fvARB");
866
GL::getAttribLocation = (GL::GLGetAttribLocationProc) GL::getAttribLocationARBWrapper;
867
GL::getAttribLocationARB = (GL::GLGetAttribLocationARBProc) getProcAddress ("glGetAttribLocationARB");
869
GL::enableVertexAttribArray = (GL::GLEnableVertexAttribArrayProc) getProcAddress ("glEnableVertexAttribArrayARB");
870
GL::disableVertexAttribArray = (GL::GLDisableVertexAttribArrayProc) getProcAddress ("glDisableVertexAttribArrayARB");
871
GL::vertexAttribPointer = (GL::GLVertexAttribPointerProc) getProcAddress ("glVertexAttribPointerARB");
876
255
if (strstr (glExtensions, "GL_ARB_texture_compression"))
1800
1066
priv->lastViewport.height);
1805
GLScreen::getEGLContext ()
1812
GLScreen::getProgram (std::list<const GLShaderData*> shaders)
1814
return (*priv->programCache)(shaders);
1817
const GLShaderData *
1818
GLScreen::getShaderData (GLShaderParameters ¶ms)
1820
return &priv->shaderCache.getShaderData(params);
1823
GLDoubleBuffer::GLDoubleBuffer (Display *d,
1825
const compiz::opengl::impl::GLXSwapIntervalEXTFunc &swapIntervalFunc,
1826
const compiz::opengl::impl::GLXWaitVideoSyncSGIFunc &waitVideoSyncFunc) :
1827
compiz::opengl::DoubleBuffer (swapIntervalFunc, waitVideoSyncFunc),
1836
GLXDoubleBuffer::copyFrontToBack() const
1838
int w = screen->width ();
1839
int h = screen->height ();
1841
glMatrixMode (GL_PROJECTION);
1844
glOrtho (0, w, 0, h, -1.0, 1.0);
1845
glMatrixMode (GL_MODELVIEW);
1849
glReadBuffer (GL_FRONT);
1850
glRasterPos2i (0, 0);
1851
glCopyPixels (0, 0, w, h, GL_COLOR);
1852
glReadBuffer (GL_BACK);
1855
glMatrixMode (GL_PROJECTION);
1857
glMatrixMode (GL_MODELVIEW);
1860
GLXDoubleBuffer::GLXDoubleBuffer (Display *d,
1863
GLDoubleBuffer (d, s,
1864
boost::bind (compiz::opengl::swapIntervalGLX, d, _1),
1865
boost::bind (compiz::opengl::waitVSyncGLX, _1, _2, _3)),
1871
GLXDoubleBuffer::swap () const
1873
glXSwapBuffers (mDpy, mOutput);
1877
GLXDoubleBuffer::blitAvailable () const
1879
return GL::copySubBuffer ? true : false;
1883
GLXDoubleBuffer::blit (const CompRegion ®ion) const
1885
const CompRect::vector &blitRects (region.rects ());
1887
foreach (const CompRect &r, blitRects)
1889
int y = mSize.height () - r.y2 ();
1890
(*GL::copySubBuffer) (screen->dpy (), mOutput,
1891
r.x1 (), y, r.width (), r.height ());
1896
GLXDoubleBuffer::fallbackBlitAvailable () const
1902
GLXDoubleBuffer::fallbackBlit (const CompRegion ®ion) const
1904
const CompRect::vector &blitRects (region.rects ());
1905
int w = screen->width ();
1906
int h = screen->height ();
1908
glMatrixMode (GL_PROJECTION);
1911
glOrtho (0, w, 0, h, -1.0, 1.0);
1912
glMatrixMode (GL_MODELVIEW);
1916
glDrawBuffer (GL_FRONT);
1917
foreach (const CompRect &r, blitRects)
1921
glRasterPos2i (x, y);
1922
glCopyPixels (x, y, w, h, GL_COLOR);
1924
glDrawBuffer (GL_BACK);
1927
glMatrixMode (GL_PROJECTION);
1929
glMatrixMode (GL_MODELVIEW);
1937
EGLDoubleBuffer::EGLDoubleBuffer (Display *d,
1939
EGLSurface const &surface) :
1940
GLDoubleBuffer (d, s,
1941
boost::bind (compiz::opengl::swapIntervalEGL, d, _1),
1942
boost::bind (compiz::opengl::waitVSyncEGL, _1, _2, _3)),
1948
EGLDoubleBuffer::swap () const
1950
eglSwapBuffers (eglGetDisplay (mDpy), mSurface);
1954
EGLDoubleBuffer::blitAvailable () const
1956
return GL::postSubBuffer ? true : false;
1960
EGLDoubleBuffer::blit (const CompRegion ®ion) const
1962
CompRect::vector blitRects (region.rects ());
1965
foreach (const CompRect &r, blitRects)
1967
y = mSize.height () - r.y2 ();
1969
(*GL::postSubBuffer) (eglGetDisplay (screen->dpy ()),
1978
EGLDoubleBuffer::fallbackBlitAvailable () const
1984
EGLDoubleBuffer::fallbackBlit (const CompRegion ®ion) const
1989
EGLDoubleBuffer::copyFrontToBack() const
1075
GL::unthrottledFrames++;
1076
if (GL::waitVideoSync)
1078
// Don't wait twice. Just in case.
1079
if (GL::swapInterval)
1080
(*GL::swapInterval) (0);
1083
* While glXSwapBuffers/glXCopySubBufferMESA are meant to do a
1084
* flush before they blit, it is best to not let that happen.
1085
* Because that flush would occur after GL::waitVideoSync, causing
1086
* a delay and the final blit to be slightly out of sync resulting
1087
* in tearing. So we need to do a glFinish before we wait for
1088
* vsync, to absolutely minimize tearing.
1092
// Docs: http://www.opengl.org/registry/specs/SGI/video_sync.txt
1093
unsigned int oldCount = GL::vsyncCount;
1094
(*GL::waitVideoSync) (1, 0, &GL::vsyncCount);
1096
if (GL::vsyncCount != oldCount)
1097
GL::unthrottledFrames = 0;
1102
controlSwapVideoSync (bool sync)
1104
// Docs: http://www.opengl.org/registry/specs/SGI/swap_control.txt
1105
if (GL::swapInterval)
1107
(*GL::swapInterval) (sync ? 1 : 0);
1108
GL::unthrottledFrames++;
1111
waitForVideoSync ();
1117
PrivateGLScreen::waitForVideoSync ()
1119
if (optionGetSyncToVblank ())
1120
GL::waitForVideoSync ();
1996
1124
PrivateGLScreen::paintOutputs (CompOutput::ptrList &outputs,
1997
1125
unsigned int mask,
1998
1126
const CompRegion ®ion)
2000
1130
if (clearBuffers)
2002
1132
if (mask & COMPOSITE_SCREEN_DAMAGE_ALL_MASK)
2003
1133
glClear (GL_COLOR_BUFFER_BIT);
2006
// Disable everything that we don't usually need and could slow us down
2007
glDisable (GL_BLEND);
2008
glDisable (GL_STENCIL_TEST);
2009
glDisable (GL_DEPTH_TEST);
2010
glDepthMask (GL_FALSE);
2013
GLFramebufferObject *oldFbo = NULL;
2014
bool useFbo = false;
2016
/* Clear the color buffer where appropriate */
2017
if (GL::fboEnabled && scratchFbo)
2019
oldFbo = scratchFbo->bind ();
2020
useFbo = scratchFbo->checkStatus () && scratchFbo->tex ();
2022
GLFramebufferObject::rebind (oldFbo);
2025
#ifdef UNSAFE_ARM_SGX_FIXME
2026
refreshSubBuffer = ((lastMask & COMPOSITE_SCREEN_DAMAGE_ALL_MASK) &&
2027
!(mask & COMPOSITE_SCREEN_DAMAGE_ALL_MASK) &&
2028
(mask & COMPOSITE_SCREEN_DAMAGE_REGION_MASK));
2030
if (refreshSubBuffer)
2032
// FIXME: We shouldn't have to substract a 1X1 pixel region here !!
2033
// This is an ugly workaround for what appears to be a bug in the SGX
2034
// X11 driver (e.g. on Pandaboard OMAP4 platform).
2035
// Posting a fullscreen damage region to the SGX seems to reset the
2036
// framebuffer, causing the screen to blackout.
2037
cScreen->damageRegion (CompRegion (screen->fullscreenOutput ()) -
2038
CompRegion (CompRect(0, 0, 1, 1)));
2042
CompRegion tmpRegion = (mask & COMPOSITE_SCREEN_DAMAGE_ALL_MASK) ?
2043
screen->region () : region;
1136
CompRegion tmpRegion (region);
2045
1138
foreach (CompOutput *output, outputs)
2048
1140
targetOutput = output;
2050
1142
r.x = output->x1 ();