Turn compile time checks to runtime check in kwinglutils.cpp

Only those which truly are different are kept as compile time checks.
In addition the index buffer is made available to GLES as in principle
all required functionality is available on gles.

REVIEW: 125865
This commit is contained in:
Martin Gräßlin 2015-10-29 17:11:14 +01:00
parent 99ddcfbac0
commit fc2805d218

View file

@ -294,20 +294,16 @@ const QByteArray GLShader::prepareSource(GLenum shaderType, const QByteArray &so
{
// Prepare the source code
QByteArray ba;
#ifdef KWIN_HAVE_OPENGLES
if (GLPlatform::instance()->glslVersion() < kVersionNumber(3, 0)) {
if (GLPlatform::instance()->isGLES() && GLPlatform::instance()->glslVersion() < kVersionNumber(3, 0)) {
ba.append("precision highp float;\n");
}
#endif
if (ShaderManager::instance()->isShaderDebug()) {
ba.append("#define KWIN_SHADER_DEBUG 1\n");
}
ba.append(source);
#ifdef KWIN_HAVE_OPENGLES
if (GLPlatform::instance()->glslVersion() >= kVersionNumber(3, 0)) {
if (GLPlatform::instance()->isGLES() && GLPlatform::instance()->glslVersion() >= kVersionNumber(3, 0)) {
ba.replace("#version 140", "#version 300 es\n\nprecision highp float;\n");
}
#endif
// Inject color correction code for fragment shaders, if possible
if (shaderType == GL_FRAGMENT_SHADER && sColorCorrect)
@ -353,13 +349,11 @@ bool GLShader::compile(GLuint program, GLenum shaderType, const QByteArray &sour
bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSource)
{
#ifndef KWIN_HAVE_OPENGLES
// Make sure shaders are actually supported
if (!GLPlatform::instance()->supports(GLSL) || GLPlatform::instance()->supports(LimitedNPOT)) {
qCCritical(LIBKWINGLUTILS) << "Shaders are not supported";
return false;
}
#endif
mValid = false;
@ -1192,11 +1186,7 @@ void ShaderManager::initShaders()
"scene-color-fragment.glsl",
};
#ifdef KWIN_HAVE_OPENGLES
const qint64 coreVersionNumber = kVersionNumber(3, 0);
#else
const qint64 coreVersionNumber = kVersionNumber(1, 40);
#endif
const qint64 coreVersionNumber = GLPlatform::instance()->isGLES() ? kVersionNumber(3, 0) : kVersionNumber(1, 40);
if (GLPlatform::instance()->glslVersion() >= coreVersionNumber)
m_shaderDir = ":/resources/shaders/1.40/";
else
@ -1292,18 +1282,18 @@ QSize GLRenderTarget::s_virtualScreenSize;
void GLRenderTarget::initStatic()
{
#ifdef KWIN_HAVE_OPENGLES
sSupported = true;
s_blitSupported = hasGLVersion(3, 0);
#else
sSupported = hasGLVersion(3, 0) ||
hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) ||
hasGLExtension(QByteArrayLiteral("GL_EXT_framebuffer_object"));
if (GLPlatform::instance()->isGLES()) {
sSupported = true;
s_blitSupported = hasGLVersion(3, 0);
} else {
sSupported = hasGLVersion(3, 0) ||
hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) ||
hasGLExtension(QByteArrayLiteral("GL_EXT_framebuffer_object"));
s_blitSupported = hasGLVersion(3, 0) ||
hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) ||
hasGLExtension(QByteArrayLiteral("GL_EXT_framebuffer_blit"));
#endif
s_blitSupported = hasGLVersion(3, 0) ||
hasGLExtension(QByteArrayLiteral("GL_ARB_framebuffer_object")) ||
hasGLExtension(QByteArrayLiteral("GL_EXT_framebuffer_blit"));
}
}
void GLRenderTarget::cleanup()
@ -1516,9 +1506,6 @@ void GLRenderTarget::attachTexture(const GLTexture& target)
// ------------------------------------------------------------------
#ifndef KWIN_HAVE_OPENGLES
static const uint16_t indices[] = {
1, 0, 3, 3, 2, 1, 5, 4, 7, 7, 6, 5, 9, 8, 11, 11, 10, 9,
13, 12, 15, 15, 14, 13, 17, 16, 19, 19, 18, 17, 21, 20, 23, 23, 22, 21,
@ -1693,18 +1680,12 @@ static const uint16_t indices[] = {
2041, 2040, 2043, 2043, 2042, 2041, 2045, 2044, 2047, 2047, 2046, 2045
};
#endif // KWIN_HAVE_OPENGLES
template <typename T>
T align(T value, int bytes)
{
return (value + bytes - 1) & ~T(bytes - 1);
}
#ifndef KWIN_HAVE_OPENGLES
// This class is not be used with OpenGL ES for now, since we need
// GL_ARB_draw_elements_base_vertex and GL_ARB_copy_buffer.
class IndexBuffer
{
public:
@ -1779,8 +1760,6 @@ void IndexBuffer::bind()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
}
#endif // KWIN_HAVE_OPENGLES
// ------------------------------------------------------------------
@ -1995,9 +1974,7 @@ public:
FrameSizesArray<4> frameSizes;
VertexAttrib attrib[VertexAttributeCount];
Bitfield enabledArrays;
#ifndef KWIN_HAVE_OPENGLES
static IndexBuffer *s_indexBuffer;
#endif
};
bool GLVertexBufferPrivate::hasMapBufferRange = false;
@ -2005,9 +1982,7 @@ bool GLVertexBufferPrivate::supportsIndexedQuads = false;
GLVertexBuffer *GLVertexBufferPrivate::streamingBuffer = nullptr;
bool GLVertexBufferPrivate::haveBufferStorage = false;
bool GLVertexBufferPrivate::haveSyncFences = false;
#ifndef KWIN_HAVE_OPENGLES
IndexBuffer *GLVertexBufferPrivate::s_indexBuffer = nullptr;
#endif
void GLVertexBufferPrivate::interleaveArrays(float *dst, int dim,
const float *vertices, const float *texcoords,
@ -2356,7 +2331,6 @@ void GLVertexBuffer::draw(GLenum primitiveMode, int first, int count)
void GLVertexBuffer::draw(const QRegion &region, GLenum primitiveMode, int first, int count, bool hardwareClipping)
{
#ifndef KWIN_HAVE_OPENGLES
if (primitiveMode == GL_QUADS) {
IndexBuffer *&indexBuffer = GLVertexBufferPrivate::s_indexBuffer;
@ -2379,7 +2353,6 @@ void GLVertexBuffer::draw(const QRegion &region, GLenum primitiveMode, int first
}
return;
}
#endif
if (!hardwareClipping) {
glDrawArrays(primitiveMode, first, count);
@ -2467,22 +2440,26 @@ void GLVertexBuffer::framePosted()
void GLVertexBuffer::initStatic()
{
#ifdef KWIN_HAVE_OPENGLES
GLVertexBufferPrivate::hasMapBufferRange = hasGLExtension(QByteArrayLiteral("GL_EXT_map_buffer_range"));
GLVertexBufferPrivate::supportsIndexedQuads = false;
GLVertexBufferPrivate::haveBufferStorage = false;
GLVertexBufferPrivate::haveSyncFences = false;
#else
bool haveBaseVertex = hasGLVersion(3, 2) || hasGLExtension(QByteArrayLiteral("GL_ARB_draw_elements_base_vertex"));
bool haveCopyBuffer = hasGLVersion(3, 1) || hasGLExtension(QByteArrayLiteral("GL_ARB_copy_buffer"));
bool haveMapBufferRange = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_ARB_map_buffer_range"));
if (GLPlatform::instance()->isGLES()) {
bool haveBaseVertex = hasGLExtension(QByteArrayLiteral("GL_OES_draw_elements_base_vertex"));
bool haveCopyBuffer = hasGLVersion(3, 0);
bool haveMapBufferRange = hasGLExtension(QByteArrayLiteral("GL_EXT_map_buffer_range"));
GLVertexBufferPrivate::hasMapBufferRange = haveMapBufferRange;
GLVertexBufferPrivate::supportsIndexedQuads = haveBaseVertex && haveCopyBuffer && haveMapBufferRange;
GLVertexBufferPrivate::hasMapBufferRange = haveMapBufferRange;
GLVertexBufferPrivate::supportsIndexedQuads = haveBaseVertex && haveCopyBuffer && haveMapBufferRange;
GLVertexBufferPrivate::haveBufferStorage = hasGLExtension("GL_EXT_buffer_storage");
GLVertexBufferPrivate::haveSyncFences = hasGLVersion(3, 0);
} else {
bool haveBaseVertex = hasGLVersion(3, 2) || hasGLExtension(QByteArrayLiteral("GL_ARB_draw_elements_base_vertex"));
bool haveCopyBuffer = hasGLVersion(3, 1) || hasGLExtension(QByteArrayLiteral("GL_ARB_copy_buffer"));
bool haveMapBufferRange = hasGLVersion(3, 0) || hasGLExtension(QByteArrayLiteral("GL_ARB_map_buffer_range"));
GLVertexBufferPrivate::hasMapBufferRange = haveMapBufferRange;
GLVertexBufferPrivate::supportsIndexedQuads = haveBaseVertex && haveCopyBuffer && haveMapBufferRange;
GLVertexBufferPrivate::haveBufferStorage = hasGLVersion(4, 4) || hasGLExtension("GL_ARB_buffer_storage");
GLVertexBufferPrivate::haveSyncFences = hasGLVersion(3, 2) || hasGLExtension("GL_ARB_sync");
}
GLVertexBufferPrivate::s_indexBuffer = nullptr;
GLVertexBufferPrivate::haveBufferStorage = hasGLVersion(4, 4) || hasGLExtension("GL_ARB_buffer_storage");
GLVertexBufferPrivate::haveSyncFences = hasGLVersion(3, 2) || hasGLExtension("GL_ARB_sync");
#endif
GLVertexBufferPrivate::streamingBuffer = new GLVertexBuffer(GLVertexBuffer::Stream);
if (GLVertexBufferPrivate::haveBufferStorage && GLVertexBufferPrivate::haveSyncFences) {
@ -2494,10 +2471,8 @@ void GLVertexBuffer::initStatic()
void GLVertexBuffer::cleanup()
{
#ifndef KWIN_HAVE_OPENGLES
delete GLVertexBufferPrivate::s_indexBuffer;
GLVertexBufferPrivate::s_indexBuffer = nullptr;
#endif
GLVertexBufferPrivate::hasMapBufferRange = false;
GLVertexBufferPrivate::supportsIndexedQuads = false;
delete GLVertexBufferPrivate::streamingBuffer;