Skip to content

Commit

Permalink
Review texture storage implementations and add fallback mode
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibel committed Apr 8, 2016
1 parent ca1978c commit f08a2b0
Show file tree
Hide file tree
Showing 23 changed files with 472 additions and 103 deletions.
11 changes: 11 additions & 0 deletions source/globjects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ set(sources
${source_path}/implementations/TextureImplementation_DirectStateAccessEXT.h
${source_path}/implementations/TextureImplementation_Legacy.cpp
${source_path}/implementations/TextureImplementation_Legacy.h

${source_path}/implementations/AbstractTextureStorageImplementation.cpp
${source_path}/implementations/AbstractTextureStorageImplementation.h
${source_path}/implementations/TextureStorageImplementation_DirectStateAccessARB.cpp
${source_path}/implementations/TextureStorageImplementation_DirectStateAccessARB.h
${source_path}/implementations/TextureStorageImplementation_DirectStateAccessEXT.cpp
${source_path}/implementations/TextureStorageImplementation_DirectStateAccessEXT.h
${source_path}/implementations/TextureStorageImplementation_Legacy.cpp
${source_path}/implementations/TextureStorageImplementation_Legacy.h
${source_path}/implementations/TextureStorageImplementation_Fallback.cpp
${source_path}/implementations/TextureStorageImplementation_Fallback.h

${source_path}/implementations/AbstractUniformImplementation.cpp
${source_path}/implementations/AbstractUniformImplementation.h
Expand Down
9 changes: 9 additions & 0 deletions source/globjects/include/globjects/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ class GLOBJECTS_API Texture : public Object
, Legacy
};

enum class StorageImplementation
{
DirectStateAccessARB
, DirectStateAccessEXT
, Legacy
, Fallback
};

static void hintBindlessImplementation(BindlessImplementation impl);
static void hintStorageImplementation(StorageImplementation impl);

Texture();
Texture(gl::GLenum target);
Expand Down
4 changes: 2 additions & 2 deletions source/globjects/source/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ ShaderResource::~ShaderResource()


TextureResource::TextureResource(GLenum target)
: IDResource(ImplementationRegistry::current().textureImplementation().create(target))
: IDResource(ImplementationRegistry::current().textureBindlessImplementation().create(target))
{
}

TextureResource::~TextureResource()
{
if (hasOwnership())
ImplementationRegistry::current().textureImplementation().destroy(id());
ImplementationRegistry::current().textureBindlessImplementation().destroy(id());
}


Expand Down
58 changes: 32 additions & 26 deletions source/globjects/source/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@

#include "registry/ImplementationRegistry.h"
#include "implementations/AbstractTextureImplementation.h"
#include "implementations/AbstractTextureStorageImplementation.h"


namespace
{

const globjects::AbstractTextureImplementation & implementation()
const globjects::AbstractTextureImplementation & bindlessImplementation()
{
return globjects::ImplementationRegistry::current().textureImplementation();
return globjects::ImplementationRegistry::current().textureBindlessImplementation();
}

const globjects::AbstractTextureStorageImplementation & storageImplementation()
{
return globjects::ImplementationRegistry::current().textureStorageImplementation();
}

}
Expand Down Expand Up @@ -132,27 +138,27 @@ void Texture::setParameter(const GLenum name, const GLenum value)

void Texture::setParameter(const GLenum name, const GLint value)
{
implementation().setParameter(this, name, value);
bindlessImplementation().setParameter(this, name, value);
}

void Texture::setParameter(const GLenum name, const GLfloat value)
{
implementation().setParameter(this, name, value);
bindlessImplementation().setParameter(this, name, value);
}

void Texture::setParameter(gl::GLenum name, const glm::vec4 & value)
{
implementation().setParameter(this, name, value);
bindlessImplementation().setParameter(this, name, value);
}

GLint Texture::getParameter(const GLenum pname) const
{
return implementation().getParameter(this, pname);
return bindlessImplementation().getParameter(this, pname);
}

GLint Texture::getLevelParameter(const GLint level, const GLenum pname) const
{
return implementation().getLevelParameter(this, level, pname);
return bindlessImplementation().getLevelParameter(this, level, pname);
}

void Texture::getImage(const GLint level, const GLenum format, const GLenum type, GLvoid * image) const
Expand Down Expand Up @@ -195,22 +201,22 @@ std::vector<unsigned char> Texture::getCompressedImage(const GLint lod) const

void Texture::image1D(const GLint level, const GLenum internalFormat, const GLsizei width, const GLint border, const GLenum format, const GLenum type, const GLvoid * data)
{
implementation().image1D(this, level, internalFormat, width, border, format, type, data);
bindlessImplementation().image1D(this, level, internalFormat, width, border, format, type, data);
}

void Texture::compressedImage1D(const GLint level, const GLenum internalFormat, const GLsizei width, const GLint border, const GLsizei imageSize, const GLvoid * data)
{
implementation().compressedImage1D(this, level, internalFormat, width, border, imageSize, data);
bindlessImplementation().compressedImage1D(this, level, internalFormat, width, border, imageSize, data);
}

void Texture::subImage1D(const GLint level, const GLint xOffset, const GLsizei width, const GLenum format, const GLenum type, const GLvoid * data)
{
implementation().subImage1D(this, level, xOffset, width, format, type, data);
bindlessImplementation().subImage1D(this, level, xOffset, width, format, type, data);
}

void Texture::image2D(const GLint level, const GLenum internalFormat, const GLsizei width, const GLsizei height, const GLint border, const GLenum format, const GLenum type, const GLvoid* data)
{
implementation().image2D(this, level, internalFormat, width, height, border, format, type, data);
bindlessImplementation().image2D(this, level, internalFormat, width, height, border, format, type, data);
}

void Texture::image2D(const GLint level, const GLenum internalFormat, const glm::ivec2 & size, const GLint border, const GLenum format, const GLenum type, const GLvoid* data)
Expand All @@ -220,7 +226,7 @@ void Texture::image2D(const GLint level, const GLenum internalFormat, const glm:

void Texture::compressedImage2D(const GLint level, const GLenum internalFormat, const GLsizei width, const GLsizei height, const GLint border, const GLsizei imageSize, const GLvoid * data)
{
implementation().compressedImage2D(this, level, internalFormat, width, height, border, imageSize, data);
bindlessImplementation().compressedImage2D(this, level, internalFormat, width, height, border, imageSize, data);
}

void Texture::compressedImage2D(const GLint level, const GLenum internalFormat, const glm::ivec2 & size, const GLint border, const GLsizei imageSize, const GLvoid * data)
Expand All @@ -230,7 +236,7 @@ void Texture::compressedImage2D(const GLint level, const GLenum internalFormat,

void Texture::subImage2D(const GLint level, const GLint xOffset, const GLint yOffset, const GLsizei width, const GLsizei height, const GLenum format, const GLenum type, const GLvoid * data)
{
implementation().subImage2D(this, level, xOffset, yOffset, width, height, format, type, data);
bindlessImplementation().subImage2D(this, level, xOffset, yOffset, width, height, format, type, data);
}

void Texture::subImage2D(const GLint level, const glm::ivec2& offset, const glm::ivec2& size, const GLenum format, const GLenum type, const GLvoid * data)
Expand All @@ -240,7 +246,7 @@ void Texture::subImage2D(const GLint level, const glm::ivec2& offset, const glm:

void Texture::image3D(const GLint level, const GLenum internalFormat, const GLsizei width, const GLsizei height, const GLsizei depth, const GLint border, const GLenum format, const GLenum type, const GLvoid* data)
{
implementation().image3D(this, level, internalFormat, width, height, depth, border, format, type, data);
bindlessImplementation().image3D(this, level, internalFormat, width, height, depth, border, format, type, data);
}

void Texture::image3D(const GLint level, const GLenum internalFormat, const glm::ivec3 & size, const GLint border, const GLenum format, const GLenum type, const GLvoid* data)
Expand All @@ -250,7 +256,7 @@ void Texture::image3D(const GLint level, const GLenum internalFormat, const glm:

void Texture::compressedImage3D(const GLint level, const GLenum internalFormat, const GLsizei width, const GLsizei height, const GLsizei depth, const GLint border, const GLsizei imageSize, const GLvoid * data)
{
implementation().compressedImage3D(this, level, internalFormat, width, height, depth, border, imageSize, data);
bindlessImplementation().compressedImage3D(this, level, internalFormat, width, height, depth, border, imageSize, data);
}

void Texture::compressedImage3D(GLint level, GLenum internalFormat, const glm::ivec3 & size, GLint border, GLsizei imageSize, const GLvoid * data)
Expand All @@ -260,7 +266,7 @@ void Texture::compressedImage3D(GLint level, GLenum internalFormat, const glm::i

void Texture::subImage3D(const GLint level, const GLint xOffset, const GLint yOffset, const GLint zOffset, const GLsizei width, const GLsizei height, const GLsizei depth, const GLenum format, const GLenum type, const GLvoid * data)
{
implementation().subImage3D(this, level, xOffset, yOffset, zOffset, width, height, depth, format, type, data);
bindlessImplementation().subImage3D(this, level, xOffset, yOffset, zOffset, width, height, depth, format, type, data);
}

void Texture::subImage3D(const GLint level, const glm::ivec3& offset, const glm::ivec3& size, const GLenum format, const GLenum type, const GLvoid * data)
Expand All @@ -270,7 +276,7 @@ void Texture::subImage3D(const GLint level, const glm::ivec3& offset, const glm:

void Texture::image2DMultisample(const GLsizei samples, const GLenum internalFormat, const GLsizei width, const GLsizei height, const GLboolean fixedSamplesLocations)
{
implementation().image2DMultisample(this, samples, internalFormat, width, height, fixedSamplesLocations);
bindlessImplementation().image2DMultisample(this, samples, internalFormat, width, height, fixedSamplesLocations);
}

void Texture::image2DMultisample(const GLsizei samples, const GLenum internalFormat, const glm::ivec2 & size, const GLboolean fixedSamplesLocations)
Expand All @@ -280,7 +286,7 @@ void Texture::image2DMultisample(const GLsizei samples, const GLenum internalFor

void Texture::image3DMultisample(const GLsizei samples, const GLenum internalFormat, const GLsizei width, const GLsizei height, const GLsizei depth, const GLboolean fixedSamplesLocations)
{
implementation().image3DMultisample(this, samples, internalFormat, width, height, depth, fixedSamplesLocations);
bindlessImplementation().image3DMultisample(this, samples, internalFormat, width, height, depth, fixedSamplesLocations);
}

void Texture::image3DMultisample(const GLsizei samples, const GLenum internalFormat, const glm::ivec3 & size, const GLboolean fixedSamplesLocations)
Expand All @@ -290,12 +296,12 @@ void Texture::image3DMultisample(const GLsizei samples, const GLenum internalFor

void Texture::storage1D(const GLsizei levels, const GLenum internalFormat, const GLsizei width)
{
implementation().storage1D(this, levels, internalFormat, width);
storageImplementation().storage1D(this, levels, internalFormat, width);
}

void Texture::storage2D(const GLsizei levels, const GLenum internalFormat, const GLsizei width, const GLsizei height)
{
implementation().storage2D(this, levels, internalFormat, width, height);
storageImplementation().storage2D(this, levels, internalFormat, width, height);
}

void Texture::storage2D(const GLsizei levels, const GLenum internalFormat, const glm::ivec2 & size)
Expand All @@ -305,7 +311,7 @@ void Texture::storage2D(const GLsizei levels, const GLenum internalFormat, const

void Texture::storage3D(const GLsizei levels, const GLenum internalFormat, const GLsizei width, const GLsizei height, const GLsizei depth)
{
implementation().storage3D(this, levels, internalFormat, width, height, depth);
storageImplementation().storage3D(this, levels, internalFormat, width, height, depth);
}

void Texture::storage3D(const GLsizei levels, const GLenum internalFormat, const glm::ivec3 & size)
Expand All @@ -320,12 +326,12 @@ void Texture::textureView(const GLuint originalTexture, const GLenum internalFor

void Texture::texBuffer(const GLenum internalFormat, Buffer * buffer)
{
implementation().texBuffer(this, internalFormat, buffer);
bindlessImplementation().texBuffer(this, internalFormat, buffer);
}

void Texture::texBufferRange(const GLenum internalFormat, Buffer * buffer, const GLintptr offset, const GLsizeiptr size)
{
implementation().texBufferRange(this, internalFormat, buffer, offset, size);
bindlessImplementation().texBufferRange(this, internalFormat, buffer, offset, size);
}

void Texture::clearImage(const GLint level, const GLenum format, const GLenum type, const void * data)
Expand Down Expand Up @@ -401,12 +407,12 @@ void Texture::unbindImageTexture(const GLuint unit)

void Texture::generateMipmap()
{
implementation().generateMipMap(this);
bindlessImplementation().generateMipMap(this);
}

void Texture::cubeMapImage(gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data)
{
implementation().cubeMapImage(this, level, internalFormat, width, height, border, format, type, data);
bindlessImplementation().cubeMapImage(this, level, internalFormat, width, height, border, format, type, data);
}

void Texture::cubeMapImage(gl::GLint level, gl::GLenum internalFormat, const glm::ivec2 & size, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data)
Expand All @@ -431,7 +437,7 @@ TextureHandle Texture::textureHandle(Sampler * sampler) const

void Texture::pageCommitment(const GLint level, const GLint xOffset, const GLint yOffset, const GLint zOffset, const GLsizei width, const GLsizei height, const GLsizei depth, const GLboolean commit) const
{
implementation().pageCommitment(this, level, xOffset, yOffset, zOffset, width, height, depth, commit);
bindlessImplementation().pageCommitment(this, level, xOffset, yOffset, zOffset, width, height, depth, commit);
}

void Texture::pageCommitment(const GLint level, const glm::ivec3& offset, const glm::ivec3& size, const GLboolean commit) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class AbstractTextureImplementation
virtual void image2DMultisample(const Texture * texture, gl::GLsizei samples, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLboolean fixedSamplesLocations) const = 0;
virtual void image3DMultisample(const Texture * texture, gl::GLsizei samples, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLsizei depth, gl::GLboolean fixedSamplesLocations) const = 0;

virtual void storage1D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width) const = 0;
virtual void storage2D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height) const = 0;
virtual void storage3D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLsizei depth) const = 0;

virtual void cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const = 0;

virtual void texBuffer(const Texture * texture, const gl::GLenum internalFormat, Buffer * buffer) const = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#include "AbstractTextureStorageImplementation.h"

#include <glbinding/gl/enum.h>
#include <glbinding/gl/extension.h>

#include <globjects/globjects.h>

#include "TextureStorageImplementation_DirectStateAccessARB.h"
#include "TextureStorageImplementation_DirectStateAccessEXT.h"
#include "TextureStorageImplementation_Legacy.h"
#include "TextureStorageImplementation_Fallback.h"


using namespace gl;

namespace globjects
{

AbstractTextureStorageImplementation::AbstractTextureStorageImplementation()
{
}

AbstractTextureStorageImplementation::~AbstractTextureStorageImplementation()
{
}

AbstractTextureStorageImplementation * AbstractTextureStorageImplementation::get(const Texture::StorageImplementation impl)
{
if (!hasExtension(GLextension::GL_ARB_texture_storage))
{
return TextureStorageImplementation_Fallback::instance();
}

if (impl == Texture::StorageImplementation::DirectStateAccessARB
&& hasExtension(GLextension::GL_ARB_direct_state_access))
{
return TextureStorageImplementation_DirectStateAccessARB::instance();
}
else if (impl >= Texture::StorageImplementation::DirectStateAccessEXT
&& hasExtension(GLextension::GL_EXT_direct_state_access))
{
return TextureStorageImplementation_DirectStateAccessEXT::instance();
}
else
{
return TextureStorageImplementation_Legacy::instance();
}
}

} // namespace globjects
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <glbinding/gl/types.h>

#include <globjects/Texture.h>

namespace globjects
{

class AbstractTextureStorageImplementation
{
public:
AbstractTextureStorageImplementation();
virtual ~AbstractTextureStorageImplementation();

static AbstractTextureStorageImplementation * get(Texture::StorageImplementation impl =
Texture::StorageImplementation::DirectStateAccessARB);

virtual void storage1D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width) const = 0;
virtual void storage2D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height) const = 0;
virtual void storage3D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLsizei depth) const = 0;

virtual void cubeMapStorage(const Texture * texture, gl::GLint levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height) const = 0;
};

} // namespace globjects
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,6 @@ void TextureImplementation_DirectStateAccessARB::image3DMultisample(const Textur
gl::glTextureImage3DMultisampleNV(texture->id(), texture->target(), samples, static_cast<gl::GLint>(internalFormat), width, height, depth, fixedSamplesLocations);
}

void TextureImplementation_DirectStateAccessARB::storage1D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width) const
{
gl::glTextureStorage1D(texture->id(), levels, internalFormat, width);
}

void TextureImplementation_DirectStateAccessARB::storage2D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height) const
{
gl::glTextureStorage2D(texture->id(), levels, internalFormat, width, height);
}

void TextureImplementation_DirectStateAccessARB::storage3D(const Texture * texture, gl::GLsizei levels, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLsizei depth) const
{
gl::glTextureStorage3D(texture->id(), levels, internalFormat, width, height, depth);
}

void TextureImplementation_DirectStateAccessARB::cubeMapImage(const Texture * texture, gl::GLint level, gl::GLenum internalFormat, gl::GLsizei width, gl::GLsizei height, gl::GLint border, gl::GLenum format, gl::GLenum type, const gl::GLvoid * data) const
{
get(Texture::BindlessImplementation::DirectStateAccessEXT)->cubeMapImage(texture, level, internalFormat, width, height, border, format, type, data);
Expand Down
Loading

0 comments on commit f08a2b0

Please sign in to comment.