Program Listing for File opengl-features.h

Return to documentation for file (include\gpu-utility\opengl-features.h)

/******************************************************************************
(c) Intel Corporation.

This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.

 This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.

******************************************************************************/

#pragma once

#include "opengl-version.h"

#include <bitset>
#include <set>
#include <string>

struct GPADispatchTable;

namespace gpa {
namespace gpu_utility {

enum class GLFeature : size_t {
    kVertexArrayObject,
    kVertexArrayOjectApple,
    kDrawBuffers,
    kDrawBuffersIndexedExt,
    kDrawBuffersBlendEquations,
    kDrawBuffersBlendMaskEnable,
    kBlendEquation,
    kSamplerObject,
    kPixelBufferObject,
    kPackSubImage,
    kUnpackSubImage,
    kTexture3D,
    kViewportArray,
    kAppleRowBytes,
    kFramebufferBlit,

    kCount  // Keep it at the end
};

// NOTE: GLFeatures is not thread safe!
// Methods of the single GLFeatures object should be called from the single thread (on per-context basis)
class GLFeatures
{
public:
    explicit GLFeatures(const GPADispatchTable& dispatchTable);

    GLFeatures(const GLFeatures&) = delete;
    GLFeatures& operator=(const GLFeatures&) = delete;

    GLFeatures(GLFeatures&&) noexcept = delete;
    GLFeatures& operator=(GLFeatures&&) noexcept = delete;

    bool IsAvailable(GLFeature feature) const
    {
        return mFeatureFlags[static_cast<size_t>(feature)];
    }

    void Update(const GLVersion::Desc& versionDesc);

private:
    void UpdateWithVersion(const GLVersion::Desc& versionDesc);
    void UpdateWithExtensions();

    std::set<std::string> GetCurrentExtensions(const GLVersion::Desc& versionDesc) const;

    const GPADispatchTable& mDispatchTable;
    std::bitset<static_cast<size_t>(GLFeature::kCount)> mFeatureFlags;
    std::set<std::string> mExtensions;
    GLVersion::Desc mVersionDesc;
};

}  // namespace gpu_utility
}  // namespace gpa