Browse Source

Mentioned version-aware extension queries in portability documentation.

pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
136e5c08fc
  1. 26
      doc/portability.dox
  2. 2
      src/AbstractShaderProgram.h

26
doc/portability.dox

@ -37,7 +37,7 @@ make porting easier -- it is better to fail at compile time on e.g. undefined
enum value than fail at runtime in some corner case because given texture enum value than fail at runtime in some corner case because given texture
format is not supported. format is not supported.
If you include Magnum.h, you get these predefined macros: If you include @ref Magnum.h, you get these predefined macros:
- @ref MAGNUM_TARGET_GLES if targeting OpenGL ES - @ref MAGNUM_TARGET_GLES if targeting OpenGL ES
- @ref MAGNUM_TARGET_GLES2 if targeting OpenGL ES 2.0 - @ref MAGNUM_TARGET_GLES2 if targeting OpenGL ES 2.0
@ -109,7 +109,7 @@ available, but also have proper fallback when it's not, see for example
@ref AbstractTexture-performance-optimization "AbstractTexture" or @ref AbstractTexture-performance-optimization "AbstractTexture" or
@ref Mesh-performance-optimization "Mesh". See also @ref required-extensions. @ref Mesh-performance-optimization "Mesh". See also @ref required-extensions.
@section portability-shaders Portable shaders @section portability-shaders Writing portable shaders
%Shaders are probably the most painful thing to port. There are many issues to %Shaders are probably the most painful thing to port. There are many issues to
address - different shader syntax (`in`/`out` vs. `attribute` and `varying` address - different shader syntax (`in`/`out` vs. `attribute` and `varying`
@ -121,6 +121,11 @@ you can decide on the syntax in your shader code. You can also use
@ref Context::supportedVersion() to conveniently select highest supported @ref Context::supportedVersion() to conveniently select highest supported
version from a list: version from a list:
@code @code
// MyShader.cpp
Version version = Context::instance()->supportedVersion({Version::GL430, Version::GL330, Version::GL210});
attachShader(Shader::fromFile(version, "MyShader.vert"));
@endcode
@code
// MyShader.vert // MyShader.vert
#if __VERSION__ < 130 #if __VERSION__ < 130
#define in attribute #define in attribute
@ -136,12 +141,23 @@ void main() {
// ... // ...
} }
@endcode @endcode
It is often desirable to query extension presence based on actually used GLSL
version -- while the extension might be supported in the driver, it might not
be available in given GLSL version (e.g. causing compilation errors). You can
use @ref Context::isExtensionSupported(Version) to check that the extension
is present in given version:
@code @code
// MyShader.cpp if(!Context::instance()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>(version)) {
Version version = Context::instance()->supportedVersion({Version::GL430, Version::GL330, Version::GL210}); bindAttributeLocation(Position::Location, "position");
attachShader(Shader::fromFile(version, "MyShader.vert")); // ...
}
@endcode @endcode
See also @ref AbstractShaderProgram class documentation for information about
specifying attribute location, uniform location and texture layer in various
OpenGL versions.
All shaders in @ref Shaders namespace support desktop OpenGL starting from All shaders in @ref Shaders namespace support desktop OpenGL starting from
version 2.1 and also OpenGL ES 2.0 and 3.0. Feel free to look into their version 2.1 and also OpenGL ES 2.0 and 3.0. Feel free to look into their
sources to see how portability is handled there. sources to see how portability is handled there.

2
src/AbstractShaderProgram.h

@ -283,6 +283,8 @@ setUniform() documentation for more information.
To achieve least state changes, set all uniforms in one run -- method chaining To achieve least state changes, set all uniforms in one run -- method chaining
comes in handy. comes in handy.
@see @ref portability-shaders
@todo Compiling and linking more than one shader in parallel, then checking @todo Compiling and linking more than one shader in parallel, then checking
status, should be faster -- https://twitter.com/g_truc/status/352778836657700866 status, should be faster -- https://twitter.com/g_truc/status/352778836657700866
*/ */

Loading…
Cancel
Save