Hash :
8c5b31c2
Author :
Date :
2017-09-26T18:07:44
Make query extensions enableable. BUG=angleproject:1523 Change-Id: If2da4bff180664de997c981165672858c19ebe78 Reviewed-on: https://chromium-review.googlesource.com/685649 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// gl_raii:
// Helper methods for containing GL objects like buffers and textures.
#ifndef ANGLE_TESTS_GL_RAII_H_
#define ANGLE_TESTS_GL_RAII_H_
#include <functional>
#include "angle_gl.h"
namespace angle
{
// This is a bit of hack to work around a bug in MSVS intellisense, and make it very easy to
// use the correct function pointer type without worrying about the various definitions of
// GL_APICALL.
using GLGen = decltype(glGenBuffers);
using GLDelete = decltype(glDeleteBuffers);
template <GLGen GenF, GLDelete DeleteF>
class GLWrapper : angle::NonCopyable
{
public:
GLWrapper() {}
~GLWrapper() { DeleteF(1, &mHandle); }
// The move-constructor and move-assignment operators are necessary so that the data within a
// GLWrapper object can be relocated.
GLWrapper(GLWrapper &&rht) : mHandle(rht.mHandle) { rht.mHandle = 0u; }
GLWrapper &operator=(GLWrapper &&rht)
{
if (this != &rht)
{
std::swap(mHandle, rht.mHandle);
}
return *this;
}
void reset()
{
if (mHandle != 0u)
{
DeleteF(1, &mHandle);
mHandle = 0u;
}
}
GLuint get()
{
if (!mHandle)
{
GenF(1, &mHandle);
}
return mHandle;
}
operator GLuint() { return get(); }
private:
GLuint mHandle = 0u;
};
using GLVertexArray = GLWrapper<glGenVertexArrays, glDeleteVertexArrays>;
using GLBuffer = GLWrapper<glGenBuffers, glDeleteBuffers>;
using GLTexture = GLWrapper<glGenTextures, glDeleteTextures>;
using GLFramebuffer = GLWrapper<glGenFramebuffers, glDeleteFramebuffers>;
using GLRenderbuffer = GLWrapper<glGenRenderbuffers, glDeleteRenderbuffers>;
using GLSampler = GLWrapper<glGenSamplers, glDeleteSamplers>;
using GLTransformFeedback = GLWrapper<glGenTransformFeedbacks, glDeleteTransformFeedbacks>;
using GLProgramPipeline = GLWrapper<glGenProgramPipelines, glDeleteProgramPipelines>;
using GLQueryEXT = GLWrapper<glGenQueriesEXT, glDeleteQueriesEXT>;
// Don't use GLProgram directly, use ANGLE_GL_PROGRAM.
namespace priv
{
class GLProgram
{
public:
GLProgram() : mHandle(0) {}
~GLProgram() { glDeleteProgram(mHandle); }
void makeCompute(const std::string &computeShader)
{
mHandle = CompileComputeProgram(computeShader);
}
void makeRaster(const std::string &vertexShader, const std::string &fragmentShader)
{
mHandle = CompileProgram(vertexShader, fragmentShader);
}
void makeBinaryOES(const std::vector<uint8_t> &binary, GLenum binaryFormat)
{
mHandle = LoadBinaryProgramOES(binary, binaryFormat);
}
void makeBinaryES3(const std::vector<uint8_t> &binary, GLenum binaryFormat)
{
mHandle = LoadBinaryProgramES3(binary, binaryFormat);
}
bool valid() const { return mHandle != 0; }
GLuint get()
{
ASSERT(valid());
return mHandle;
}
operator GLuint() { return get(); }
private:
GLuint mHandle;
};
} // namespace priv
#define ANGLE_GL_PROGRAM(name, vertex, fragment) \
priv::GLProgram name; \
name.makeRaster(vertex, fragment); \
ASSERT_TRUE(name.valid());
#define ANGLE_GL_COMPUTE_PROGRAM(name, compute) \
priv::GLProgram name; \
name.makeCompute(compute); \
ASSERT_TRUE(name.valid());
#define ANGLE_GL_BINARY_OES_PROGRAM(name, binary, binaryFormat) \
priv::GLProgram name; \
name.makeBinaryOES(binary, binaryFormat); \
ASSERT_TRUE(name.valid());
#define ANGLE_GL_BINARY_ES3_PROGRAM(name, binary, binaryFormat) \
priv::GLProgram name; \
name.makeBinaryES3(binary, binaryFormat); \
ASSERT_TRUE(name.valid());
} // namespace angle
#endif // ANGLE_TESTS_GL_RAII_H_