Browse Source

Enabled new shader functionality in ES 3.1.

pull/68/head
Vladimír Vondruš 12 years ago
parent
commit
4bc4a40c70
  1. 36
      src/Magnum/AbstractShaderProgram.cpp
  2. 83
      src/Magnum/AbstractShaderProgram.h
  3. 8
      src/Magnum/Implementation/ShaderProgramState.cpp
  4. 12
      src/Magnum/Implementation/ShaderProgramState.h
  5. 7
      src/Magnum/Implementation/ShaderState.h
  6. 124
      src/Magnum/Shader.cpp
  7. 105
      src/Magnum/Shader.h

36
src/Magnum/AbstractShaderProgram.cpp

@ -50,9 +50,13 @@ Int AbstractShaderProgram::maxVertexAttributes() {
return value;
}
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
Int AbstractShaderProgram::maxAtomicCounterBufferSize() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shaderProgram->maxAtomicCounterBufferSize;
@ -64,7 +68,11 @@ Int AbstractShaderProgram::maxAtomicCounterBufferSize() {
}
Int AbstractShaderProgram::maxComputeSharedMemorySize() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::compute_shader>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shaderProgram->maxComputeSharedMemorySize;
@ -76,7 +84,11 @@ Int AbstractShaderProgram::maxComputeSharedMemorySize() {
}
Int AbstractShaderProgram::maxComputeWorkGroupInvocations() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::compute_shader>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shaderProgram->maxComputeWorkGroupInvocations;
@ -88,7 +100,11 @@ Int AbstractShaderProgram::maxComputeWorkGroupInvocations() {
}
Int AbstractShaderProgram::maxImageUnits() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_image_load_store>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shaderProgram->maxImageUnits;
@ -98,7 +114,9 @@ Int AbstractShaderProgram::maxImageUnits() {
return value;
}
#endif
#ifndef MAGNUM_TARGET_GLES
Int AbstractShaderProgram::maxImageSamples() {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_image_load_store>())
return 0;
@ -110,9 +128,15 @@ Int AbstractShaderProgram::maxImageSamples() {
return value;
}
#endif
#ifndef MAGNUM_TARGET_GLES2
Int AbstractShaderProgram::maxCombinedShaderOutputResources() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_storage_buffer_object>() || !Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_image_load_store>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shaderProgram->maxCombinedShaderOutputResources;
@ -124,7 +148,11 @@ Int AbstractShaderProgram::maxCombinedShaderOutputResources() {
}
Long AbstractShaderProgram::maxShaderStorageBlockSize() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_storage_buffer_object>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint64& value = Context::current()->state().shaderProgram->maxShaderStorageBlockSize;
@ -152,9 +180,13 @@ Int AbstractShaderProgram::maxUniformBlockSize() {
}
#endif
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
Int AbstractShaderProgram::maxUniformLocations() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shaderProgram->maxUniformLocations;

83
src/Magnum/AbstractShaderProgram.h

@ -219,8 +219,8 @@ Int normalMatrixUniform = uniformLocation("normalMatrix");
@requires_gl43 %Extension @extension{ARB,explicit_uniform_location} for
explicit uniform location instead of using
@ref Magnum::AbstractShaderProgram::uniformLocation() "uniformLocation()".
@requires_gl Explicit uniform location is not supported in OpenGL ES. Use
@ref Magnum::AbstractShaderProgram::uniformLocation() "uniformLocation()"
@requires_gles31 Explicit uniform location is not supported in OpenGL ES 3.0
and older. Use @ref Magnum::AbstractShaderProgram::uniformLocation() "uniformLocation()"
instead.
@anchor AbstractShaderProgram-texture-units
@ -252,8 +252,8 @@ setUniform(uniformLocation("specularTexture"), 1);
@requires_gl42 %Extension @extension{ARB,shading_language_420pack} for explicit
texture binding unit instead of using
@ref Magnum::AbstractShaderProgram::setUniform(Int, const T&) "setUniform(Int, Int)".
@requires_gl Explicit texture binding unit is not supported in OpenGL ES. Use
@ref Magnum::AbstractShaderProgram::setUniform(Int, const T&) "setUniform(Int, Int)"
@requires_gles31 Explicit texture binding unit is not supported in OpenGL ES
3.0 and older. Use @ref Magnum::AbstractShaderProgram::setUniform(Int, const T&) "setUniform(Int, Int)"
instead.
@anchor AbstractShaderProgram-rendering-workflow
@ -352,15 +352,15 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject {
*/
static Int maxVertexAttributes();
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Max supported atomic counter buffer size
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_atomic_counters} is
* not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_atomic_counters}
* (part of OpenGL 4.2) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_ATOMIC_COUNTER_BUFFER_SIZE}
* @requires_gl Atomic counters are not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxAtomicCounterBufferSize();
@ -368,10 +368,10 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject {
* @brief Max supported compute shared memory size
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,compute_shader} is not
* available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,compute_shader}
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_COMPUTE_SHARED_MEMORY_SIZE}
* @requires_gl Compute shaders are not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxComputeSharedMemorySize();
@ -379,10 +379,10 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject {
* @brief Max supported compute work group invocation count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,compute_shader} is not
* available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,compute_shader}
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_COMPUTE_WORK_GROUP_INVOCATIONS}
* @requires_gl Compute shaders are not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxComputeWorkGroupInvocations();
@ -393,32 +393,37 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject {
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_image_load_store}
* is not available, returns `0`.
* (part of OpenGL 4.2) or OpenGL ES 3.1 is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_IMAGE_UNITS}
* @requires_gl %Image load/store is not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxImageUnits();
#endif
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Max supported image sample count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_image_load_store}
* is not available, returns `0`.
* (part of OpenGL 4.2) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_IMAGE_SAMPLES}
* @requires_gl %Image load/store is not available in OpenGL ES.
* @requires_gl Multisample image load/store is not available in OpenGL
* ES.
*/
static Int maxImageSamples();
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Max supported combined shader output resource count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If neither @extension{ARB,shader_image_load_store}
* nor @extension{ARB,shader_storage_buffer_object} extension is
* available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_image_load_store}
* (part of OpenGL 4.2) nor extension @extension{ARB,shader_storage_buffer_object}
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_COMBINED_SHADER_OUTPUT_RESOURCES}
* @requires_gl %Image load/store is not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxCombinedShaderOutputResources();
@ -426,50 +431,44 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject {
* @brief Max supported shader storage block size
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_storage_buffer_object}
* is not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_storage_buffer_object}
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_SHADER_STORAGE_BLOCK_SIZE}
* @requires_gl %Shader storage is not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Long maxShaderStorageBlockSize();
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Max supported uniform block size
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,uniform_buffer_object}
* is not available, returns `0`.
* (part of OpenGL 3.1) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_UNIFORM_BLOCK_SIZE}
* @requires_gles30 Uniform blocks are not available in OpenGL ES 2.0.
* @requires_gles30 Uniform blocks are not available in OpenGL ES 2.0
*/
static Int maxUniformBlockSize();
#endif
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Max supported explicit uniform location count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,explicit_uniform_location}
* is not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,explicit_uniform_location}
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_UNIFORM_LOCATIONS}
* @requires_gl Explicit uniform location is not supported in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxUniformLocations();
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Min supported program texel offset
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{EXT,gpu_shader4} is not
* available, returns `0`.
* OpenGL calls. If extension @extension{EXT,gpu_shader4} (part of
* OpenGL 3.0) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MIN_PROGRAM_TEXEL_OFFSET}
* @requires_gles30 %Texture lookup with offset is not available in
* OpenGL ES 2.0.
* OpenGL ES 2.0
*/
static Int minTexelOffset();
@ -477,11 +476,11 @@ class MAGNUM_EXPORT AbstractShaderProgram: public AbstractObject {
* @brief Max supported program texel offset
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{EXT,gpu_shader4} is not
* available, returns `0`.
* OpenGL calls. If extension @extension{EXT,gpu_shader4} (part of
* OpenGL 3.0) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_PROGRAM_TEXEL_OFFSET}
* @requires_gles30 %Texture lookup with offset is not available in
* OpenGL ES 2.0.
* OpenGL ES 2.0
*/
static Int maxTexelOffset();
#endif

8
src/Magnum/Implementation/ShaderProgramState.cpp

@ -34,11 +34,11 @@
namespace Magnum { namespace Implementation {
ShaderProgramState::ShaderProgramState(Context& context, std::vector<std::string>& extensions): current(0), maxVertexAttributes(0)
#ifndef MAGNUM_TARGET_GLES
, maxAtomicCounterBufferSize(0), maxComputeSharedMemorySize(0), maxComputeWorkGroupInvocations(0), maxImageUnits(0), maxImageSamples(0), maxCombinedShaderOutputResources(0), maxUniformLocations(0), maxShaderStorageBlockSize(0)
#endif
#ifndef MAGNUM_TARGET_GLES2
, minTexelOffset(0), maxTexelOffset(0), maxUniformBlockSize(0)
, maxAtomicCounterBufferSize(0), maxComputeSharedMemorySize(0), maxComputeWorkGroupInvocations(0), maxImageUnits(0), maxCombinedShaderOutputResources(0), maxUniformLocations(0), minTexelOffset(0), maxTexelOffset(0), maxUniformBlockSize(0), maxShaderStorageBlockSize(0)
#endif
#ifndef MAGNUM_TARGET_GLES
, maxImageSamples(0)
#endif
{
#ifndef MAGNUM_TARGET_GLES

12
src/Magnum/Implementation/ShaderProgramState.h

@ -86,19 +86,21 @@ struct ShaderProgramState {
GLuint current;
GLint maxVertexAttributes;
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
GLint maxAtomicCounterBufferSize,
maxComputeSharedMemorySize,
maxComputeWorkGroupInvocations,
maxImageUnits,
maxImageSamples,
maxCombinedShaderOutputResources,
maxUniformLocations;
maxUniformLocations,
minTexelOffset,
maxTexelOffset,
maxUniformBlockSize;
GLint64 maxShaderStorageBlockSize;
#endif
#ifndef MAGNUM_TARGET_GLES2
GLint minTexelOffset, maxTexelOffset, maxUniformBlockSize;
#ifndef MAGNUM_TARGET_GLES
GLint maxImageSamples;
#endif
};

7
src/Magnum/Implementation/ShaderState.h

@ -35,7 +35,10 @@ struct ShaderState {
explicit ShaderState():
maxVertexOutputComponents{}, maxFragmentInputComponents{},
#ifndef MAGNUM_TARGET_GLES
maxTessellationControlInputComponents{}, maxTessellationControlOutputComponents{}, maxTessellationControlTotalOutputComponents{}, maxTessellationEvaluationInputComponents{}, maxTessellationEvaluationOutputComponents{}, maxGeometryInputComponents{}, maxGeometryOutputComponents{}, maxGeometryTotalOutputComponents{}, maxAtomicCounterBuffers{}, maxCombinedAtomicCounterBuffers{}, maxAtomicCounters{}, maxCombinedAtomicCounters{}, maxImageUniforms{}, maxCombinedImageUniforms{}, maxShaderStorageBlocks{}, maxCombinedShaderStorageBlocks{},
maxTessellationControlInputComponents{}, maxTessellationControlOutputComponents{}, maxTessellationControlTotalOutputComponents{}, maxTessellationEvaluationInputComponents{}, maxTessellationEvaluationOutputComponents{}, maxGeometryInputComponents{}, maxGeometryOutputComponents{}, maxGeometryTotalOutputComponents{},
#endif
#ifndef MAGNUM_TARGET_GLES2
maxAtomicCounterBuffers{}, maxCombinedAtomicCounterBuffers{}, maxAtomicCounters{}, maxCombinedAtomicCounters{}, maxImageUniforms{}, maxCombinedImageUniforms{}, maxShaderStorageBlocks{}, maxCombinedShaderStorageBlocks{},
#endif
maxTextureImageUnits{}, maxTextureImageUnitsCombined{},
#ifndef MAGNUM_TARGET_GLES2
@ -66,6 +69,8 @@ struct ShaderState {
maxGeometryInputComponents,
maxGeometryOutputComponents,
maxGeometryTotalOutputComponents;
#endif
#ifndef MAGNUM_TARGET_GLES2
GLint maxAtomicCounterBuffers[StageCount];
GLint maxCombinedAtomicCounterBuffers;
GLint maxAtomicCounters[StageCount];

124
src/Magnum/Shader.cpp

@ -56,6 +56,8 @@ std::string shaderName(const Shader::Type type) {
case Shader::Type::Geometry: return "geometry";
case Shader::Type::TessellationControl: return "tessellation control";
case Shader::Type::TessellationEvaluation: return "tessellation evaluation";
#endif
#ifndef MAGNUM_TARGET_GLES2
case Shader::Type::Compute: return "compute";
#endif
case Shader::Type::Fragment: return "fragment";
@ -68,11 +70,13 @@ UnsignedInt typeToIndex(const Shader::Type type) {
switch(type) {
case Shader::Type::Vertex: return 0;
case Shader::Type::Fragment: return 1;
#ifndef MAGNUM_TARGET_GLES2
case Shader::Type::Compute: return 2;
#endif
#ifndef MAGNUM_TARGET_GLES
case Shader::Type::Geometry: return 2;
case Shader::Type::TessellationControl: return 3;
case Shader::Type::TessellationEvaluation: return 4;
case Shader::Type::Compute: return 5;
case Shader::Type::Geometry: return 3;
case Shader::Type::TessellationControl: return 4;
case Shader::Type::TessellationEvaluation: return 5;
#endif
}
@ -248,10 +252,18 @@ Int Shader::maxFragmentInputComponents() {
return value;
}
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
Int Shader::maxAtomicCounterBuffers(const Type type) {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>() || !isTypeSupported(type))
if(
#ifndef MAGNUM_TARGET_GLES
!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>() ||
#else
!Context::current()->isVersionSupported(Version::GLES310) ||
#endif
!isTypeSupported(type))
{
return 0;
}
const UnsignedInt index = typeToIndex(type);
GLint& value = Context::current()->state().shader->maxAtomicCounterBuffers[index];
@ -260,10 +272,14 @@ Int Shader::maxAtomicCounterBuffers(const Type type) {
constexpr static GLenum what[] = {
GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS,
GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS,
#ifndef MAGNUM_TARGET_GLES2
GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS,
#endif
#ifndef MAGNUM_TARGET_GLES
GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS,
GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS,
GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS,
GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS
GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS
#endif
};
if(value == 0)
glGetIntegerv(what[index], &value);
@ -272,7 +288,11 @@ Int Shader::maxAtomicCounterBuffers(const Type type) {
}
Int Shader::maxCombinedAtomicCounterBuffers() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shader->maxCombinedAtomicCounterBuffers;
@ -285,8 +305,16 @@ Int Shader::maxCombinedAtomicCounterBuffers() {
}
Int Shader::maxAtomicCounters(const Type type) {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>() || !isTypeSupported(type))
if(
#ifndef MAGNUM_TARGET_GLES
!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>() ||
#else
!Context::current()->isVersionSupported(Version::GLES310) ||
#endif
!isTypeSupported(type))
{
return 0;
}
const UnsignedInt index = typeToIndex(type);
GLint& value = Context::current()->state().shader->maxAtomicCounters[index];
@ -295,10 +323,14 @@ Int Shader::maxAtomicCounters(const Type type) {
constexpr static GLenum what[] = {
GL_MAX_VERTEX_ATOMIC_COUNTERS,
GL_MAX_FRAGMENT_ATOMIC_COUNTERS,
#ifndef MAGNUM_TARGET_GLES2
GL_MAX_COMPUTE_ATOMIC_COUNTERS,
#endif
#ifndef MAGNUM_TARGET_GLES
GL_MAX_GEOMETRY_ATOMIC_COUNTERS,
GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS,
GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS,
GL_MAX_COMPUTE_ATOMIC_COUNTERS
#endif
};
if(value == 0)
glGetIntegerv(what[index], &value);
@ -307,7 +339,11 @@ Int Shader::maxAtomicCounters(const Type type) {
}
Int Shader::maxCombinedAtomicCounters() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shader->maxCombinedAtomicCounters;
@ -320,8 +356,16 @@ Int Shader::maxCombinedAtomicCounters() {
}
Int Shader::maxImageUniforms(const Type type) {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_image_load_store>() || !isTypeSupported(type))
if(
#ifndef MAGNUM_TARGET_GLES
!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_image_load_store>() ||
#else
!Context::current()->isVersionSupported(Version::GLES310) ||
#endif
!isTypeSupported(type))
{
return 0;
}
const UnsignedInt index = typeToIndex(type);
GLint& value = Context::current()->state().shader->maxImageUniforms[index];
@ -330,10 +374,14 @@ Int Shader::maxImageUniforms(const Type type) {
constexpr static GLenum what[] = {
GL_MAX_VERTEX_IMAGE_UNIFORMS,
GL_MAX_FRAGMENT_IMAGE_UNIFORMS,
#ifndef MAGNUM_TARGET_GLES2
GL_MAX_COMPUTE_IMAGE_UNIFORMS,
#endif
#ifndef MAGNUM_TARGET_GLES
GL_MAX_GEOMETRY_IMAGE_UNIFORMS,
GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS,
GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS,
GL_MAX_COMPUTE_IMAGE_UNIFORMS
GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS
#endif
};
if(value == 0)
glGetIntegerv(what[index], &value);
@ -342,7 +390,11 @@ Int Shader::maxImageUniforms(const Type type) {
}
Int Shader::maxCombinedImageUniforms() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_image_load_store>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shader->maxCombinedImageUniforms;
@ -355,8 +407,16 @@ Int Shader::maxCombinedImageUniforms() {
}
Int Shader::maxShaderStorageBlocks(const Type type) {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_storage_buffer_object>() || !isTypeSupported(type))
if(
#ifndef MAGNUM_TARGET_GLES
!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_storage_buffer_object>() ||
#else
!Context::current()->isVersionSupported(Version::GLES310) ||
#endif
!isTypeSupported(type))
{
return 0;
}
const UnsignedInt index = typeToIndex(type);
GLint& value = Context::current()->state().shader->maxShaderStorageBlocks[index];
@ -365,10 +425,14 @@ Int Shader::maxShaderStorageBlocks(const Type type) {
constexpr static GLenum what[] = {
GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS,
GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS,
#ifndef MAGNUM_TARGET_GLES2
GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS,
#endif
#ifndef MAGNUM_TARGET_GLES
GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS,
GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS,
GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS,
GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS
GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS
#endif
};
if(value == 0)
glGetIntegerv(what[index], &value);
@ -377,7 +441,11 @@ Int Shader::maxShaderStorageBlocks(const Type type) {
}
Int Shader::maxCombinedShaderStorageBlocks() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shader_atomic_counters>())
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return 0;
GLint& value = Context::current()->state().shader->maxCombinedShaderStorageBlocks;
@ -401,11 +469,13 @@ Int Shader::maxTextureImageUnits(const Type type) {
constexpr static GLenum what[] = {
GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS,
GL_MAX_TEXTURE_IMAGE_UNITS,
#ifndef MAGNUM_TARGET_GLES2
GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS,
#endif
#ifndef MAGNUM_TARGET_GLES
GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS,
GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS,
GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS,
GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS
GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS
#endif
};
if(value == 0)
@ -440,11 +510,13 @@ Int Shader::maxUniformBlocks(const Type type) {
constexpr static GLenum what[] = {
GL_MAX_VERTEX_UNIFORM_BLOCKS,
GL_MAX_FRAGMENT_UNIFORM_BLOCKS,
#ifndef MAGNUM_TARGET_GLES2
GL_MAX_COMPUTE_UNIFORM_BLOCKS,
#endif
#ifndef MAGNUM_TARGET_GLES
GL_MAX_GEOMETRY_UNIFORM_BLOCKS,
GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS,
GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS,
GL_MAX_COMPUTE_UNIFORM_BLOCKS
GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS
#endif
};
if(value == 0)
@ -481,11 +553,11 @@ Int Shader::maxUniformComponents(const Type type) {
constexpr static GLenum what[] = {
GL_MAX_VERTEX_UNIFORM_COMPONENTS,
GL_MAX_FRAGMENT_UNIFORM_COMPONENTS,
GL_MAX_COMPUTE_UNIFORM_COMPONENTS,
#ifndef MAGNUM_TARGET_GLES
GL_MAX_GEOMETRY_UNIFORM_COMPONENTS,
GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS,
GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS,
GL_MAX_COMPUTE_UNIFORM_COMPONENTS
GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS
#endif
};
if(value == 0)
@ -522,11 +594,13 @@ Int Shader::maxCombinedUniformComponents(const Type type) {
constexpr static GLenum what[] = {
GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS,
GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS,
#ifndef MAGNUM_TARGET_GLES2
GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS,
#endif
#ifndef MAGNUM_TARGET_GLES
GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS,
GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS,
GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS,
GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS
GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS
#endif
};
if(value == 0)
@ -719,6 +793,8 @@ Debug operator<<(Debug debug, const Shader::Type value) {
_c(TessellationControl)
_c(TessellationEvaluation)
_c(Geometry)
#endif
#ifndef MAGNUM_TARGET_GLES2
_c(Compute)
#endif
_c(Fragment)

105
src/Magnum/Shader.h

@ -88,11 +88,14 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @requires_gl Geometry shaders are not available in OpenGL ES.
*/
Geometry = GL_GEOMETRY_SHADER,
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* Compute shader
* @requires_gl43 %Extension @extension{ARB,compute_shader}
* @requires_gl Compute shaders are not available in OpenGL ES.
* @requires_gles31 Compute shaders are not available in OpenGL ES
* 3.0 and older
*/
Compute = GL_COMPUTE_SHADER,
#endif
@ -119,8 +122,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported component count of tessellation control shader input vertex
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,tessellation_shader}
* is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,tessellation_shader} (part
* of OpenGL 4.0) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_TESS_CONTROL_INPUT_COMPONENTS}
* @requires_gl Tessellation shaders are not available in OpenGL ES.
*/
@ -130,8 +133,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported component count of tessellation control shader output vertex
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,tessellation_shader}
* is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,tessellation_shader} (part
* of OpenGL 4.0) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_TESS_CONTROL_OUTPUT_COMPONENTS}
* @requires_gl Tessellation shaders are not available in OpenGL ES.
*/
@ -141,8 +144,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported component count of all tessellation control shader output vertices combined
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,tessellation_shader}
* is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,tessellation_shader} (part
* of OpenGL 4.0) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS}
* @requires_gl Tessellation shaders are not available in OpenGL ES.
*/
@ -152,8 +155,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported component count of tessellation evaluation shader input vertex
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,tessellation_shader}
* is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,tessellation_shader} (part
* of OpenGL 4.0) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_TESS_EVALUATION_INPUT_COMPONENTS}
* @requires_gl Tessellation shaders are not available in OpenGL ES.
*/
@ -163,8 +166,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported component count of tessellation evaluation shader output vertex
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,tessellation_shader}
* is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,tessellation_shader} (part
* of OpenGL 4.0) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_TESS_EVALUATION_OUTPUT_COMPONENTS}
* @requires_gl Tessellation shaders are not available in OpenGL ES.
*/
@ -174,8 +177,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported component count of geometry shader input vertex
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,geometry_shader4}
* is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,geometry_shader4} (part of
* OpenGL 3.2) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_GEOMETRY_INPUT_COMPONENTS}
* @requires_gl Geometry shaders are not available in OpenGL ES.
*/
@ -185,8 +188,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported component count of geometry shader output vertex
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,geometry_shader4}
* is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,geometry_shader4} (part of
* OpenGL 3.2) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_GEOMETRY_OUTPUT_COMPONENTS}
* @requires_gl Geometry shaders are not available in OpenGL ES.
*/
@ -196,8 +199,8 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported component count of all geometry shader output vertices combined
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,geometry_shader4}
* is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,geometry_shader4} (part of
* OpenGL 3.2) is not available, returns `0`.
* @see @fn_gl{Get} with @def_gl{MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS}
* @requires_gl Geometry shaders are not available in OpenGL ES.
*/
@ -235,13 +238,14 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
*/
static Int maxUniformComponents(Type type);
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Max supported atomic counter buffer count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_atomic_counters} or
* particular shader stage is not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_atomic_counters}
* (part of OpenGL 4.2) nor OpenGL ES 3.1 is available or if particular
* shader stage is not available, returns `0`.
* @see @ref maxCombinedAtomicCounterBuffers(), @ref maxAtomicCounters(),
* @fn_gl{Get} with @def_gl{MAX_VERTEX_ATOMIC_COUNTER_BUFFERS},
* @def_gl{MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS},
@ -249,7 +253,7 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @def_gl{MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS},
* @def_gl{MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS} or
* @def_gl{MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS}
* @requires_gl Atomic counters are not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxAtomicCounterBuffers(Type type);
@ -257,11 +261,11 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported atomic counter buffer count for all stages combined
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_atomic_counters} is
* not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_atomic_counters}
* (part of OpenGL 4.2) nor OpenGL ES 3.1 is available, returns `0`.
* @see @ref maxAtomicCounterBuffers(), @ref maxCombinedAtomicCounters(),
* @fn_gl{Get} with @def_gl{MAX_COMBINED_ATOMIC_COUNTER_BUFFERS}
* @requires_gl Atomic counters are not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxCombinedAtomicCounterBuffers();
@ -269,8 +273,9 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported atomic counter count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_atomic_counters} or
* particular shader stage is not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_atomic_counters}
* (part of OpenGL 4.2) nor OpenGL ES 3.1 is available or if particular
* shader stage is not available, returns `0`.
* @see @ref maxCombinedAtomicCounters(), @ref maxAtomicCounterBuffers(),
* @fn_gl{Get} with @def_gl{MAX_VERTEX_ATOMIC_COUNTERS},
* @def_gl{MAX_TESS_CONTROL_ATOMIC_COUNTERS},
@ -278,7 +283,7 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @def_gl{MAX_GEOMETRY_ATOMIC_COUNTERS},
* @def_gl{MAX_COMPUTE_ATOMIC_COUNTERS} or
* @def_gl{MAX_FRAGMENT_ATOMIC_COUNTERS}
* @requires_gl Atomic counters are not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxAtomicCounters(Type type);
@ -286,11 +291,11 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported atomic counter count for all stages combined
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_atomic_counters} is
* not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_atomic_counters}
* (part of OpenGL 4.2) nor OpenGL ES 3.1 is available, returns `0`.
* @see @ref maxAtomicCounters(), @ref maxCombinedAtomicCounterBuffers(),
* @fn_gl{Get} with @def_gl{MAX_COMBINED_ATOMIC_COUNTERS}
* @requires_gl Atomic counters are not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxCombinedAtomicCounters();
@ -298,8 +303,9 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported image uniform count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_image_load_store}
* or particular shader stage is not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_image_load_store}
* (part of OpenGL 4.2) nor OpenGL ES 3.1 is available or if particular
* shader stage is not available, returns `0`.
* @see @ref maxCombinedImageUniforms(),
* @fn_gl{Get} with @def_gl{MAX_VERTEX_IMAGE_UNIFORMS},
* @def_gl{MAX_TESS_CONTROL_IMAGE_UNIFORMS},
@ -307,7 +313,7 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @def_gl{MAX_GEOMETRY_IMAGE_UNIFORMS},
* @def_gl{MAX_COMPUTE_IMAGE_UNIFORMS} or
* @def_gl{MAX_FRAGMENT_IMAGE_UNIFORMS}
* @requires_gl %Image load/store is not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxImageUniforms(Type type);
@ -315,11 +321,11 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported image uniform count for all stages combined
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_image_load_store}
* is not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_image_load_store}
* (part of OpenGL 4.2) nor OpenGL ES 3.1 is available, returns `0`.
* @see @ref maxImageUniforms(),
* @fn_gl{Get} with @def_gl{MAX_COMBINED_IMAGE_UNIFORMS}
* @requires_gl %Image load/store is not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxCombinedImageUniforms();
@ -327,8 +333,9 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported shader storage block count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_storage_buffer_object}
* or particular shader stage is not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_storage_buffer_object}
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available or if particular
* shader stage is not available, returns `0`.
* @see @ref maxCombinedShaderStorageBlocks(),
* @fn_gl{Get} with @def_gl{MAX_VERTEX_SHADER_STORAGE_BLOCKS},
* @def_gl{MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS},
@ -336,7 +343,7 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @def_gl{MAX_GEOMETRY_SHADER_STORAGE_BLOCKS},
* @def_gl{MAX_COMPUTE_SHADER_STORAGE_BLOCKS} or
* @def_gl{MAX_FRAGMENT_SHADER_STORAGE_BLOCKS}
* @requires_gl %Shader storage is not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxShaderStorageBlocks(Type type);
@ -344,11 +351,11 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported shader storage block count for all stages combined
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,shader_storage_buffer_object}
* is not available, returns `0`.
* OpenGL calls. If neither extension @extension{ARB,shader_storage_buffer_object}
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns `0`.
* @see @ref maxShaderStorageBlocks(),
* @fn_gl{Get} with @def_gl{MAX_COMBINED_SHADER_STORAGE_BLOCKS}
* @requires_gl %Shader storage is not available in OpenGL ES.
* @requires_gles30 Not defined in OpenGL ES 2.0
*/
static Int maxCombinedShaderStorageBlocks();
#endif
@ -384,8 +391,9 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported uniform block count
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,uniform_buffer_objects} or
* particular shader stage is not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,uniform_buffer_objects}
* (part of OpenGL 3.1) or particular shader stage is not available,
* returns `0`.
* @see @ref maxCombinedUniformBlocks(), @ref maxUniformComponents(),
* @ref maxCombinedUniformComponents(),
* @fn_gl{Get} with @def_gl{MAX_VERTEX_UNIFORM_BLOCKS},
@ -402,23 +410,22 @@ class MAGNUM_EXPORT Shader: public AbstractObject {
* @brief Max supported uniform block count for all stages combined
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,uniform_buffer_objects} is
* not available, returns `0`.
* OpenGL calls. If extension @extension{ARB,uniform_buffer_objects}
* (part of OpenGL 3.1) is not available, returns `0`.
* @see @ref maxUniformBlocks(), @ref maxUniformComponents(),
* @ref maxCombinedUniformComponents(),
* @fn_gl{Get} with @def_gl{MAX_COMBINED_UNIFORM_BLOCKS}
* @requires_gles30 Uniform blocks are not available in OpenGL ES 2.0.
*/
static Int maxCombinedUniformBlocks();
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Max supported uniform component count in all blocks combined
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,uniform_buffer_objects}
* or particular shader stage is not available, returns `0`.
* (part of OpenGL 3.1) or particular shader stage is not available,
* returns `0`.
* @see @ref maxUniformComponents(), @ref maxUniformBlocks(),
* @fn_gl{Get} with @def_gl{MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS},
* @def_gl{MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS},

Loading…
Cancel
Save