Passing pointer as function parameter will now mean that it is possible
to pass `nullptr`. Some code examples now look like the parameter is
copied instead of referenced, which is misleading. Updated the
documentation to reflect that more clearly.
Makes some cases less consistent (and some convenience shortcuts
impossible), but goes well with the attitude "don't use pointer when it
can't be null".
Avoids some nullptr-related errors and leads to simpler implementation,
as we need to only handle ImageReference and BufferImage types. All
other Image classes are implicitly convertible to ImageReference and
implicit conversion works only with references, not with pointers. The
usage might be clumsy at this point, as Trade::*Importer classes return
pointer to Trade::ImageData which then needs to be dereferenced.
Hopefully introducing C++14's std::optional (or equivalent) might help
solve that issue.
Also removed "convenience" overloads for setting e.g. 2D subdata of 3D
texture. The convenience overload doesn't cover all subdata cases (only
XY plane, not YZ or XZ ones) and overly complicates the implementation.
This can be done in the future in Image classes themselves.
It's now possible to call *Texture::setStorage() even if
OpenGL 4.2, ARB_texture_storage, OpenGL ES 3.0 or EXT_texture_storage in
ES 2.0 is not available, the function will internally use sequence of
setImage() calls as fallback.
It seems to me that this behavior is better than forcing the user to
always check for extension presence and then implementing this
functionality again and again. The huge switches for setting proper
image format and type are ugly though, but according to specs they must
be set even if we are sending no data (which is weird).
Solves another trivial choice (similar to the one with TextureFormat
etc. in 7de45c98b1), less typing and also
preparation for ARB_sampler_objects extension.
Advantages:
* The enums were large (600-800 lines) and they polluted the header,
now they are in separate files (except for BufferTexture, which has
the enum small enough to be left in the same file).
* Image classes now don't need to include OpenGL headers, as they were
needed only for the enum values. With advantage of C++11's forward
enum declarations there is no need to include the enum headers
anywhere in implementation, only when particular values are needed.
* The values are now less verbose:
AbstractTexture::InternalFormat::RGB8 // before
TextureFormat::RGB8 // now
* Resolved another "trivial choice" problem (thanks @JanDupal for
introducing this term to me): how to specify the format if there are
ten ways to do it (some being massively confusing):
Image2D::Format f = AbstractImage::Format::RGB; // too long...
Image2D::Format f = Image3D::Format::RGBA; // why 3D? this works?
Image2D::Format f = BufferImage1D::Format::RGBA; // wat?
It is even worse (and more verbose) with textures:
Texture2D::InternalFormat f =
CubeMapTextureArray::InternalFormat::RGB8; // this is allowed?
To have consistent naming this change was done also with
BufferTexture::InternalFormat (now BufferTextureFormat), although there
were no trivial choice issues and the enum isn't too large. But at least
it is now less typing.
If ARB_invalidate_subdata is not available, these functions do nothing,
instead of crashing on null pointer dereference. It results in more
convenient usage, enabling users to call them whenever they want,
improving performance on implementations which supports that.
Got rid of InternalFormat class, now it is all in one big enum, as each
version (desktop, ES2, ES3) has different requirements and it can't be
done that way anymore (moreover that was terribly ugly solution).
Allows simple and convenient call with one value for all axes instead of
that unholy mess:
texture.setWrapping(Texture2D::Wrapping::ClampToEdge);
Previous way (for entertainment purposes):
textute.setWrapping(Math::Vector2<Texture2D::Wrapping>(
Texture2D::Wrapping::ClampToEdge));
Some target platforms supply their own OpenGL headers, thus we cannot
use our own from ES 3.0 and compilation fails.
On the other hand, this will be better for users as usage of unsupported
features will be catched right during compilation and not at runtime.
Desktop OpenGL and OpenGL ES 2 support can be switched using CMake
TARGET_GLES option. All functionality not supported in ES is marked in
documentation.
If targetting OpenGL ES, GLES2/gl2.h is included instead of GLEW.
Mesh class now uses VAOs only in desktop OpenGL, in ES the buffers are
bound on each draw call.
According to OpenGL specification the sampler uniform takes only texture
layer and not any particular texture. In OpenGL 4.2 it is possible to
explicitly specify desired texture layer in the uniform, so I suppose
it's desired to have shader with fixed texture layers and on the other
hand be able to bind texture to any layer, not only one -- the exact
opposite of how it was in Magnum before.
The shader should now specify in its public API which texture is on
which layer and explicitly set the layer uniforms upon construction. All
setUniform() functions taking textures as argument were thus removed, as
they confuse things a lot.
The textures now have bind() function which takes layer as argument, so
it's now sufficient to only bind the texture before drawing the mesh
without messing with sampler uniform.
Long-standing TODO. It is better to have size first, because it is more
significant than type (e.g. because there are Vector4<T> specializations
and not VectorT<4> specializations). It is also IMHO easier for user to
distinguish/read the type than before:
Vector<float, 4> -> Vector4<float> // before
Vector<4, float> -> Vector4<float> // now
Texture now doesn't have it's own redundant copy of target, but uses the
one from AbstractTexture. Subsequently, all DataHelper functions now
accept "untyped" GLenum as target for better flexibility.
CubeMapTexture is not based on Texture2D anymore, all references to cube
map textures were removed from Target enums, so it's now not possible to
create cube map texture other way than using CubeMapTexture class, which
is how it should be done in first place. The wrapping mode fix is thus
now trivial.
* Added asserts for unsupported mipmap and wrapping modes instead of
previous blind behavior, moved more-than-one-liner functions into
*.cpp
* Updated documentation to reflect the rectangle texture inabilities to
user, changed "unusable" to "incomplete" to be consistent with OpenGL
terminology.
* Removed some unneeded rows in documentation.