12#ifndef GAMP_GLPROFILE_HPP_
13#define GAMP_GLPROFILE_HPP_
30 using namespace gamp::render;
45 constexpr static std::string_view
GL4bc =
"GL4bc";
48 constexpr static std::string_view
GL4 =
"GL4";
52 constexpr static std::string_view
GL3bc =
"GL3bc";
55 constexpr static std::string_view
GL3 =
"GL3";
58 constexpr static std::string_view
GL2 =
"GL2";
61 constexpr static std::string_view
GLES1 =
"GLES1";
64 constexpr static std::string_view
GLES2 =
"GLES2";
67 constexpr static std::string_view
GLES3 =
"GLES3";
70 constexpr static std::string_view
GL_UNDEF =
"undef";
75 ERR_PRINT(
"GLProfileMask %s invalid, should have exactly 1 bit set",
to_string(mask).c_str());
80 }
else if(
version.major() < 3 ) {
88 }
else if(
version.major() < 4 ) {
105 }
else if(
GL3 == tag ||
GL3bc == tag ) {
107 }
else if(
GL2 == tag ) {
109 }
else if(
GLES3 == tag ) {
111 }
else if(
GLES2 == tag ) {
113 }
else if(
GLES1 == tag ) {
118 constexpr GLProfileMask mapTag2Mask(std::string_view tag)
noexcept {
121 }
else if(
GL4bc == tag ) {
123 }
else if(
GL3 == tag ) {
125 }
else if(
GL3bc == tag ) {
127 }
else if(
GL2 == tag ) {
129 }
else if(
GLES3 == tag ) {
131 }
else if(
GLES2 == tag ) {
133 }
else if(
GLES1 == tag ) {
139 jau::util::VersionNumber m_glslVersion;
161 m_profileMask(mapTag2Mask(tag)),
171 return static_cast<const GLProfile&
>(rp);
185 constexpr bool isGL4() const noexcept {
195 constexpr bool isGL3() const noexcept {
200 constexpr bool isGL2() const noexcept {
339 case GL_UNSIGNED_BYTE:
341 case GL_UNSIGNED_SHORT:
347 case GL_UNSIGNED_INT:
373 bool isVertexAttribPointer,
bool throwException)
const;
398 if( m_glslVersion.isZero() ) {
401 const int minor = m_glslVersion.minor();
402 std::string profileOpt;
404 profileOpt = m_glslVersion >=
Version3_0 ?
" es" :
"";
406 profileOpt = m_glslVersion >=
Version1_50 ?
" core" :
"";
408 profileOpt = m_glslVersion >=
Version1_50 ?
" compatibility" :
"";
412 return "#version " + std::to_string(m_glslVersion.major()) + (minor < 10 ?
"0" + std::to_string(minor) : std::to_string(minor)) + profileOpt +
"\n";
416 return std::string(
"GLProfile[")
418 .append(
to_string(
profileMask())).append(
", glsl ").append(m_glslVersion.toString()).append(
"]");
428 static thread_local GLContext* m_current;
443 m_glprofile(std::move(profile)), m_glversion(std::move(
glVersion)) {}
449 m_glprofile(std::move(profile)), m_glversion(std::move(
glVersion))
500 if(
nullptr != m_current ) {
506 if( makeCurrentImpl(s,
context()) ) {
518 bool isCurrent() const noexcept {
return this == m_current; }
529 void dispose() noexcept override;
539 return std::string(
"GL[")
RenderContext(Private) noexcept
Private: Create an invalid instance.
virtual std::string toString() const
gamp::wt::SurfaceRef m_surface
virtual const jau::type_info & signature() const noexcept
constexpr gamp::handle_t context() const noexcept
virtual void disposedNotify()
virtual void releaseContext() noexcept
Release this context (used for OpenGL, but a NOP on Vulkan)
constexpr RenderContextFlags contextFlags() const noexcept
virtual bool makeCurrent(const gamp::wt::SurfaceRef &s) noexcept
Make this context current (used for OpenGL, but a NOP on Vulkan)
Specifies the render profile.
virtual std::string toString() const
constexpr const jau::util::VersionNumber & version() const noexcept
constexpr const std::string_view & name() const noexcept
virtual void clear() noexcept
virtual const jau::type_info & signature() const noexcept
constexpr RenderProfile() noexcept
Create an undefined instance.
OpenGL Rendering Context.
~GLContext() noexcept override
GLContext(Private, const wt::SurfaceRef &surface, gamp::handle_t context, GLProfile profile, RenderContextFlags contextFlags, GLVersionNumber glVersion) noexcept
Private: Create a new instance of a current context.
bool makeCurrent(const gamp::wt::SurfaceRef &s) noexcept override
Make this context current (used for OpenGL, but a NOP on Vulkan)
const jau::type_info & signature() const noexcept override
bool isExtensionAvailable(GLenum name) const noexcept
bool isCurrent() const noexcept
static GLContext & getInvalid() noexcept
Returns an invalid GLContext reference.
GLContext(Private, gamp::handle_t context, GLProfile profile, RenderContextFlags contextFlags, GLVersionNumber glVersion) noexcept
Private: Create a new instance of a non-current context.
bool isExtensionAvailable(const char *name) const noexcept
GLContext(Private) noexcept
Private: Create an invalid instance.
void dispose() noexcept override
static GLContext & downcast(RenderContext *rc)
Downcast dereferenced given RenderContext* to GLContext&, throws exception if signature doesn't match...
void disposedNotify() override
static RenderContextPtr create(const wt::SurfaceRef &surface, gamp::handle_t context, GLProfile profile, RenderContextFlags contextFlags, const char *gl_version_cstr) noexcept
Create a new instance of a current.
void releaseContext() noexcept override
Release this context (used for OpenGL, but a NOP on Vulkan)
static GLContext & getCurrent() noexcept
Return thread local GLContext or an invalid GLContext, see isValid()
constexpr const GLProfile & glProfile() const noexcept
static RenderContextPtr create(gamp::handle_t context, GLProfile profile, RenderContextFlags contextFlags, const char *gl_version_cstr) noexcept
Create a new instance of a non-current context.
std::string toString() const override
constexpr const GLVersionNumber & glVersion() const
constexpr const RenderProfile & renderProfile() const noexcept override
static const jau::type_info & GLSignature() noexcept
Specifies the OpenGL profile.
constexpr bool isGLES1() const noexcept
Indicates whether this profile is capable of GLES1.
constexpr GLProfile() noexcept
constexpr bool nativeGLES2() const noexcept
Indicates whether the native OpenGL ES3 or ES2 profile is in use.
static constexpr std::string_view GLES1
The embedded OpenGL profile ES 1.x, with x >= 0.
constexpr GLProfileMask profileMask() const noexcept
static constexpr std::string_view GL3
The desktop OpenGL core profile 3.x, with x >= 1.
constexpr bool isGL2ES1() const noexcept
Indicates whether this profile is capable of GL2ES1.
std::string toString() const override
constexpr bool nativeGLCore() const noexcept
Indicates whether either of the native OpenGL core profiles are in use.
static constexpr std::string_view GL2
The desktop OpenGL profile 1.x up to 3.0.
bool isValidArrayDataType(GLenum index, GLsizei comps, GLenum type, bool isVertexAttribPointer, bool throwException) const
General validation if index, comps and type are valid for the current profile.
constexpr bool isGLES() const noexcept
Indicates whether this profile is capable of GLES.
constexpr bool isGL4() const noexcept
Indicates whether this profile is capable of GL4.
constexpr bool isGL2ES3() const noexcept
Indicates whether this profile is capable of GL2ES3.
constexpr bool nativeGLES1() const noexcept
Indicates whether the native OpenGL ES1 profile is in use.
void clear() noexcept override
constexpr bool isGL4ES3() const noexcept
Indicates whether this profile is capable of GL4ES3.
static constexpr std::string_view GLES3
The embedded OpenGL profile ES 3.x, with x >= 0.
static constexpr std::string_view GL4
The desktop OpenGL core profile 4.x, with x >= 0.
constexpr bool hasGLSL() const noexcept
Indicates whether this profile supports GLSL, i.e.
constexpr bool isGL3bc() const noexcept
Indicates whether this profile is capable of GL3bc.
const jau::type_info & signature() const noexcept override
constexpr const jau::util::VersionNumber & glslVersion() const noexcept
constexpr bool isGL2() const noexcept
Indicates whether this profile is capable of GL2 .
constexpr GLProfile(const jau::util::VersionNumber &version, GLProfileMask profileMask) noexcept
Create a new instance.
constexpr bool isGLES2() const noexcept
Indicates whether this profile is capable of GLES2.
std::string getGLSLVersionString() const
Returns the GLSL version string as to be used in a shader program, including a terminating newline ' ...
constexpr bool nativeGLES3() const noexcept
Indicates whether the native OpenGL ES2 profile is in use.
constexpr bool nativeGLCompat() const noexcept
Indicates whether either of the native OpenGL compatibility profiles are in use.
constexpr GLProfile(std::string_view tag) noexcept
Create a new instance, merely deriving from given tag.
constexpr bool isGL2GL3() const noexcept
Indicates whether this profile is capable of GL2GL3.
constexpr bool isValidDataType(GLenum type) const noexcept
General validation if type is a valid GL data type for the current profile.
constexpr bool isGL4bc() const noexcept
Indicates whether this profile is capable of GL4bc.
constexpr bool isGL3() const noexcept
Indicates whether this profile is capable of GL3.
static constexpr std::string_view GL_UNDEF
The default profile, used for the device default profile map.
static constexpr std::string_view GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
static const GLProfile & downcast(const RenderProfile &rp)
Downcast dereferenced given const RenderProfile& to const GLProfile&, throws exception if signature d...
static const jau::type_info & GLSignature() noexcept
constexpr bool isGL3ES3() const noexcept
Indicates whether this profile is capable of GL3ES3.
constexpr bool isGLES3() const noexcept
Indicates whether this profile is capable of GLES3.
static constexpr std::string_view GL3bc
The desktop OpenGL compatibility profile 3.x, with x >= 1, ie GL2 plus GL3.
constexpr bool nativeGLES() const noexcept
Indicates whether either of the native OpenGL ES profiles are in use.
constexpr bool isGL2ES2() const noexcept
Indicates whether this profile is capable of GL2ES2.
static constexpr std::string_view GL4bc
The desktop OpenGL compatibility profile 4.x, with x >= 0, ie GL2 plus GL4.
A class for storing and comparing OpenGL version numbers.
static GLVersionNumber create(const std::string &versionString) noexcept
Generic type information using either Runtime type information (RTTI) or Compile time type informatio...
Simple version number class containing a version number either being defined explicit or derived from...
constexpr int major() const noexcept
#define ERR_PRINT(...)
Use for unconditional error messages, prefix '[elapsed_time] Error @ FILE:LINE FUNC: '.
constexpr uint32_t ct_bit_count(uint32_t n) noexcept
Returns the number of set bits within given 32bit integer (w/o branching) in O(1) and constant time (...
consteval_cxx20 std::string_view name() noexcept
constexpr bool has_any(const E mask, const E bits) noexcept
constexpr std::underlying_type_t< E > number(const E v) noexcept
const jau::type_info & static_ctti() noexcept
Returns a static global reference of make_ctti<T>(true) w/ identity instance.
GLProfileMask
OpenGL profile-mask bits.
static constexpr jau::util::VersionNumber Version4_0
Version 4.0.
static constexpr jau::util::VersionNumber Version2_0
Version 2.0.
static constexpr jau::util::VersionNumber Version1_0
Version 1.00, i.e.
static constexpr jau::util::VersionNumber Version1_50
Version 1.50, i.e.
constexpr jau::util::VersionNumber getGLSLVersionNumber(const jau::util::VersionNumber &glVersion, GLProfileMask mask)
static constexpr jau::util::VersionNumber Version3_1
Version 3.1.
static constexpr jau::util::VersionNumber Version0_0
Version 0.00, i.e.
static constexpr jau::util::VersionNumber Version3_0
Version 3.0.
@ compat
Desktop compatibility profile.
@ core
Desktop core profile.
std::unique_ptr< RenderContext > RenderContextPtr
RenderContextFlags
OpenGL context flags.
std::shared_ptr< Surface > SurfaceRef
uintptr_t handle_t
A native handle type, big enough to store a pointer.
std::string to_string(const math_error_t v) noexcept
Returns std::string representation of math_error_t.
std::string to_hexstring(value_type const &v, const bool skipLeading0x=false) noexcept
Produce a lower-case hexadecimal string representation with leading 0x in MSB of the given pointer.