Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review implementation strategies (fixes #394) #397

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions source/globjects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,43 @@ set(sources
${source_path}/implementations/FramebufferImplementation_Legacy.cpp
${source_path}/implementations/FramebufferImplementation_Legacy.h

${source_path}/implementations/AbstractProgramImplementation.cpp
${source_path}/implementations/AbstractProgramImplementation.h
${source_path}/implementations/ProgramImplementation_Legacy.cpp
${source_path}/implementations/ProgramImplementation_Legacy.h

${source_path}/implementations/AbstractProgramPipelineImplementation.cpp
${source_path}/implementations/AbstractProgramPipelineImplementation.h
${source_path}/implementations/ProgramPipelineImplementation_Legacy.cpp
${source_path}/implementations/ProgramPipelineImplementation_Legacy.h

${source_path}/implementations/AbstractProgramBinaryImplementation.cpp
${source_path}/implementations/AbstractProgramBinaryImplementation.h
${source_path}/implementations/ProgramBinaryImplementation_GetProgramBinaryARB.cpp
${source_path}/implementations/ProgramBinaryImplementation_GetProgramBinaryARB.h
${source_path}/implementations/ProgramBinaryImplementation_None.cpp
${source_path}/implementations/ProgramBinaryImplementation_None.h

${source_path}/implementations/AbstractQueryImplementation.cpp
${source_path}/implementations/AbstractQueryImplementation.h
${source_path}/implementations/QueryImplementation_Legacy.cpp
${source_path}/implementations/QueryImplementation_Legacy.h

${source_path}/implementations/AbstractRenderbufferImplementation.cpp
${source_path}/implementations/AbstractRenderbufferImplementation.h
${source_path}/implementations/RenderbufferImplementation_Legacy.cpp
${source_path}/implementations/RenderbufferImplementation_Legacy.h

${source_path}/implementations/AbstractSamplerImplementation.cpp
${source_path}/implementations/AbstractSamplerImplementation.h
${source_path}/implementations/SamplerImplementation_Legacy.cpp
${source_path}/implementations/SamplerImplementation_Legacy.h

${source_path}/implementations/AbstractShaderImplementation.cpp
${source_path}/implementations/AbstractShaderImplementation.h
${source_path}/implementations/ShaderImplementation_Legacy.cpp
${source_path}/implementations/ShaderImplementation_Legacy.h

${source_path}/implementations/AbstractShadingLanguageIncludeImplementation.cpp
${source_path}/implementations/AbstractShadingLanguageIncludeImplementation.h
${source_path}/implementations/ShadingLanguageIncludeImplementation_ShadingLanguageIncludeARB.cpp
Expand Down Expand Up @@ -206,6 +236,11 @@ set(sources
${source_path}/implementations/TextureStorageMultisampleImplementation_Fallback.cpp
${source_path}/implementations/TextureStorageMultisampleImplementation_Fallback.h

${source_path}/implementations/AbstractTransformFeedbackImplementation.cpp
${source_path}/implementations/AbstractTransformFeedbackImplementation.h
${source_path}/implementations/TransformFeedbackImplementation_Legacy.cpp
${source_path}/implementations/TransformFeedbackImplementation_Legacy.h

${source_path}/implementations/AbstractUniformImplementation.cpp
${source_path}/implementations/AbstractUniformImplementation.h
${source_path}/implementations/UniformImplementation_Legacy.cpp
Expand Down
8 changes: 0 additions & 8 deletions source/globjects/include/globjects/Framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ class GLOBJECTS_API Framebuffer : public Object, public Instantiator<Framebuffer
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, int value);
void clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, float value);

static void colorMask(gl::GLboolean red, gl::GLboolean green, gl::GLboolean blue, gl::GLboolean alpha);
static void colorMask(const glm::bvec4 & mask);
static void colorMaski(gl::GLuint buffer, gl::GLboolean red, gl::GLboolean green, gl::GLboolean blue, gl::GLboolean alpha);
static void colorMaski(gl::GLuint buffer, const glm::bvec4 & mask);
static void clearColor(gl::GLfloat red, gl::GLfloat green, gl::GLfloat blue, gl::GLfloat alpha);
static void clearColor(const glm::vec4 & color);
static void clearDepth(gl::GLdouble depth);

void readPixels(gl::GLint x, gl::GLint y, gl::GLsizei width, gl::GLsizei height, gl::GLenum format, gl::GLenum type, gl::GLvoid * data = nullptr) const;
void readPixels(const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type, gl::GLvoid * data = nullptr) const;
void readPixels(gl::GLenum readBuffer, const std::array<gl::GLint, 4> & rect, gl::GLenum format, gl::GLenum type, gl::GLvoid * data = nullptr) const;
Expand Down
8 changes: 8 additions & 0 deletions source/globjects/include/globjects/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ class GLOBJECTS_API Program : public Object, public Instantiator<Program>


public:
enum class Implementation
{
Legacy
};

enum class BinaryImplementation
{
None,
GetProgramBinaryARB
};

static void hintImplementation(Implementation impl);
static void hintBinaryImplementation(BinaryImplementation impl);


Expand Down Expand Up @@ -128,6 +134,8 @@ class GLOBJECTS_API Program : public Object, public Instantiator<Program>
template <size_t Count>
std::array<gl::GLint, Count> get(gl::GLenum pname) const;

void get(gl::GLenum pname, std::size_t count, gl::GLint * values) const;

bool isValid() const;
void validate();

Expand Down
2 changes: 1 addition & 1 deletion source/globjects/include/globjects/Program.inl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ std::array<gl::GLint, Count> Program::get(gl::GLenum pname) const
{
std::array<gl::GLint, Count> values;

glGetProgramiv(id(), pname, values.data());
get(pname, Count, values.data());

return values;
}
Expand Down
7 changes: 7 additions & 0 deletions source/globjects/include/globjects/ProgramPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class Program;

class GLOBJECTS_API ProgramPipeline : public Object, public Instantiator<ProgramPipeline>
{
public:
enum class Implementation
{
Legacy
};


public:
ProgramPipeline();
virtual ~ProgramPipeline();
Expand Down
9 changes: 7 additions & 2 deletions source/globjects/include/globjects/Query.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ namespace globjects
*/
class GLOBJECTS_API Query : public Object, public Instantiator<Query>
{
public:
enum class Implementation
{
Legacy
};


public:
Query();

Expand Down Expand Up @@ -113,8 +120,6 @@ class GLOBJECTS_API Query : public Object, public Instantiator<Query>
protected:
Query(std::unique_ptr<IDResource> && resource);

static gl::GLuint genQuery();

void counter(gl::GLenum target) const;
};

Expand Down
7 changes: 7 additions & 0 deletions source/globjects/include/globjects/Renderbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace globjects
*/
class GLOBJECTS_API Renderbuffer : public Object, public Instantiator<Renderbuffer>
{
public:
enum class Implementation
{
Legacy
};


public:
Renderbuffer();

Expand Down
7 changes: 7 additions & 0 deletions source/globjects/include/globjects/Sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ namespace globjects
*/
class GLOBJECTS_API Sampler : public Object, public Instantiator<Sampler>
{
public:
enum class Implementation
{
Legacy
};


public:
Sampler();

Expand Down
5 changes: 5 additions & 0 deletions source/globjects/include/globjects/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class GLOBJECTS_API Shader : public Object, public Instantiator<Shader>


public:
enum class Implementation
{
Legacy
};

enum class IncludeImplementation
{
Fallback,
Expand Down
7 changes: 7 additions & 0 deletions source/globjects/include/globjects/TransformFeedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class Program;
*/
class GLOBJECTS_API TransformFeedback : public Object, public Instantiator<TransformFeedback>
{
public:
enum class Implementation
{
Legacy
};


public:
TransformFeedback();

Expand Down
10 changes: 5 additions & 5 deletions source/globjects/source/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ Buffer::~Buffer()

void Buffer::bind(const GLenum target) const
{
glBindBuffer(target, id());
return implementation().bind(this, target);
}

void Buffer::unbind(const GLenum target)
{
glBindBuffer(target, 0);
return implementation().unbind(target);
}

void Buffer::unbind(const GLenum target, const GLuint index)
{
glBindBufferBase(target, index, 0);
return implementation().unbindBase(target, index);
}

const void * Buffer::map() const
Expand Down Expand Up @@ -143,12 +143,12 @@ GLint64 Buffer::getParameter64(const GLenum pname) const

void Buffer::bindBase(const GLenum target, const GLuint index) const
{
glBindBufferBase(target, index, id());
return implementation().bindBase(this, target, index);
}

void Buffer::bindRange(const GLenum target, const GLuint index, const GLintptr offset, const GLsizeiptr size) const
{
glBindBufferRange(target, index, id(), offset, size);
return implementation().bindRange(this, target, index, offset, size);
}

void Buffer::copySubData(Buffer * buffer, const GLintptr readOffset, const GLintptr writeOffset, const GLsizeiptr size) const
Expand Down
43 changes: 4 additions & 39 deletions source/globjects/source/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ Framebuffer::~Framebuffer()

void Framebuffer::bind() const
{
glBindFramebuffer(GL_FRAMEBUFFER, id());
implementation().bind(this);
}

void Framebuffer::bind(const GLenum target) const
{
glBindFramebuffer(target, id());
implementation().bind(this, target);
}

void Framebuffer::unbind()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
implementation().unbind();
}

void Framebuffer::unbind(const GLenum target)
{
glBindFramebuffer(target, 0);
implementation().unbind(target);
}

void Framebuffer::setParameter(const GLenum pname, const GLint param)
Expand Down Expand Up @@ -239,41 +239,6 @@ void Framebuffer::clearBuffer(gl::GLenum buffer, gl::GLint drawBuffer, float val
clearBuffer(buffer, drawBuffer, &value);
}

void Framebuffer::colorMask(const GLboolean red, const GLboolean green, const GLboolean blue, const GLboolean alpha)
{
glColorMask(red, green, blue, alpha);
}

void Framebuffer::colorMask(const glm::bvec4 & mask)
{
colorMask(static_cast<GLboolean>(mask[0]), static_cast<GLboolean>(mask[1]), static_cast<GLboolean>(mask[2]), static_cast<GLboolean>(mask[3]));
}

void Framebuffer::colorMaski(const GLuint buffer, const GLboolean red, const GLboolean green, const GLboolean blue, const GLboolean alpha)
{
glColorMaski(buffer, red, green, blue, alpha);
}

void Framebuffer::colorMaski(const GLuint buffer, const glm::bvec4 & mask)
{
colorMaski(buffer, static_cast<GLboolean>(mask[0]), static_cast<GLboolean>(mask[1]), static_cast<GLboolean>(mask[2]), static_cast<GLboolean>(mask[3]));
}

void Framebuffer::clearColor(const GLfloat red, const GLfloat green, const GLfloat blue, const GLfloat alpha)
{
glClearColor(red, green, blue, alpha);
}

void Framebuffer::clearColor(const glm::vec4 & color)
{
clearColor(color.r, color.g, color.b, color.a);
}

void Framebuffer::clearDepth(const GLdouble depth)
{
glClearDepth(depth);
}

void Framebuffer::readPixels(const GLint x, const GLint y, const GLsizei width, const GLsizei height, const GLenum format, const GLenum type, GLvoid * data) const
{
implementation().readPixels(this, x, y, width, height, format, type, data);
Expand Down
6 changes: 3 additions & 3 deletions source/globjects/source/IncludeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace
// From http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
inline std::string trim(const std::string &s)
{
auto wsfront=std::find_if_not(s.begin(),s.end(),[](int c){return std::isspace(c);});
auto wsback=std::find_if_not(s.rbegin(),s.rend(),[](int c){return std::isspace(c);}).base();
return (wsback<=wsfront ? std::string() : std::string(wsfront,wsback));
auto wsfront=std::find_if_not(s.begin(),s.end(),[](int c){return std::isspace(c);});
auto wsback=std::find_if_not(s.rbegin(),s.rend(),[](int c){return std::isspace(c);}).base();
return (wsback<=wsfront ? std::string() : std::string(wsfront,wsback));
}

inline bool contains(const std::string& string, const std::string& search)
Expand Down
15 changes: 15 additions & 0 deletions source/globjects/source/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ namespace
{


const globjects::AbstractProgramImplementation & implementation()
{
return globjects::ImplementationRegistry::current().programImplementation();
}

const globjects::AbstractProgramBinaryImplementation & binaryImplementation()
{
return globjects::ImplementationRegistry::current().programBinaryImplementation();
Expand All @@ -44,6 +49,11 @@ namespace globjects
{


void Program::hintImplementation(const Implementation impl)
{
ImplementationRegistry::current().initialize(impl);
}

void Program::hintBinaryImplementation(const BinaryImplementation impl)
{
ImplementationRegistry::current().initialize(impl);
Expand Down Expand Up @@ -593,6 +603,11 @@ GLint Program::get(const GLenum pname) const
return value;
}

void Program::get(gl::GLenum pname, std::size_t /*count*/, gl::GLint * values) const
{
glGetProgramiv(id(), pname, values);
}

void Program::getActiveAttrib(gl::GLuint index, gl::GLsizei bufSize, gl::GLsizei * length, gl::GLint * size, gl::GLenum * type, gl::GLchar * name) const
{
checkDirty();
Expand Down
Loading