Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libgui: Added stubs for GL classes, with basic implementation for GLB…
…uffer These classes encapsulate the GL(ES2) API for managing GL state, textures, shaders, and buffers. All use of OpenGL will go through these classes -- no direct OpenGL API calls should be done outside libgui.
- Loading branch information
Showing
23 changed files
with
856 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "gui/glbuffer.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "gui/glprogram.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "gui/glshader.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "gui/glstate.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "gui/gltarget.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "gui/gltexture.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "gui/gluniform.h" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/** @file glbuffer.h GL vertex buffer. | ||
* | ||
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBGUI_GLBUFFER_H | ||
#define LIBGUI_GLBUFFER_H | ||
|
||
#include <de/libdeng2.h> | ||
#include <de/Vector> | ||
#include <QtOpenGL> | ||
#include <vector> | ||
|
||
#include "libgui.h" | ||
|
||
namespace de { | ||
|
||
namespace internal | ||
{ | ||
/// Describes an attribute array inside a GL buffer. | ||
struct AttribSpec | ||
{ | ||
dint size; ///< Number of components in an element. | ||
GLenum type; ///< Data type. | ||
bool normalized; ///< Whether to normalize non-floats to [0.f, 1.f]. | ||
dsize stride; ///< Number of bytes between elements. | ||
duint startOffset; ///< Offset in bytes from the start of the buffer. | ||
}; | ||
|
||
typedef std::pair<AttribSpec const *, duint> AttribSpecs; | ||
} | ||
|
||
/** | ||
* Vertex format with 2D coordinates, one set of texture coordinates, and an | ||
* RGBA color. | ||
*/ | ||
struct Vertex2TexRgba | ||
{ | ||
Vector2f pos; | ||
Vector2f texCoord; | ||
Vector4f rgba; | ||
|
||
static internal::AttribSpecs formatSpec(); | ||
|
||
private: | ||
static internal::AttribSpec const _spec[3]; | ||
}; | ||
|
||
/** | ||
* GL vertex buffer. | ||
* | ||
* Supports both indexed and non-indexed drawing. The primitive type has to be | ||
* specified either when setting the vertices (for non-indexed drawing) or when | ||
* specifying the indices (for indexed drawing). | ||
* | ||
* @note Compatible with OpenGL ES 2.0. | ||
* | ||
* @ingroup gl | ||
*/ | ||
class LIBGUI_PUBLIC GLBuffer | ||
{ | ||
public: | ||
enum Usage | ||
{ | ||
Static, | ||
Dynamic, | ||
Stream | ||
}; | ||
|
||
enum Primitive | ||
{ | ||
Points, | ||
LineStrip, | ||
LineLoop, | ||
Lines, | ||
TriangleStrip, | ||
TriangleFan, | ||
Triangles | ||
}; | ||
|
||
typedef duint16 Index; | ||
|
||
public: | ||
GLBuffer(); | ||
|
||
void clear(); | ||
|
||
void setVertices(dsize count, void const *data, dsize dataSize, Usage usage); | ||
|
||
void setVertices(Primitive primitive, dsize count, void const *data, dsize dataSize, Usage usage); | ||
|
||
void setIndices(Primitive primitive, dsize count, Index const *indices, Usage usage); | ||
|
||
void draw(duint first = 0, dint count = -1); | ||
|
||
protected: | ||
void setFormat(internal::AttribSpecs const &format); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
/** | ||
* Template for a vertex buffer with a specific vertex format. | ||
*/ | ||
template <typename VertexType> | ||
class GLBufferT : public GLBuffer | ||
{ | ||
public: | ||
typedef std::vector<VertexType> Vertices; | ||
|
||
public: | ||
GLBufferT() { | ||
setFormat(VertexType::formatSpec()); | ||
} | ||
|
||
void setVertices(VertexType const *vertices, dsize count, Usage usage) { | ||
GLBuffer::setVertices(count, vertices, sizeof(VertexType) * count, usage); | ||
} | ||
|
||
void setVertices(Vertices const &vertices, Usage usage) { | ||
GLBuffer::setVertices(vertices.size(), &vertices[0], sizeof(VertexType) * vertices.size(), usage); | ||
} | ||
|
||
void setVertices(Primitive primitive, VertexType const *vertices, dsize count, Usage usage) { | ||
GLBuffer::setVertices(primitive, count, vertices, sizeof(VertexType) * count, usage); | ||
} | ||
|
||
void setVertices(Primitive primitive, Vertices const &vertices, Usage usage) { | ||
GLBuffer::setVertices(primitive, vertices.size(), &vertices[0], sizeof(VertexType) * vertices.size(), usage); | ||
} | ||
}; | ||
|
||
} // namespace de | ||
|
||
#endif // LIBGUI_GLBUFFER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** @file glprogram.h GL shader program. | ||
* | ||
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBGUI_GLPROGRAM_H | ||
#define LIBGUI_GLPROGRAM_H | ||
|
||
#include <de/libdeng2.h> | ||
|
||
#include "libgui.h" | ||
|
||
namespace de { | ||
|
||
/** | ||
* GL shader program. | ||
* | ||
* @ingroup gl | ||
*/ | ||
class LIBGUI_PUBLIC GLProgram | ||
{ | ||
public: | ||
GLProgram(); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace de | ||
|
||
#endif // LIBGUI_GLPROGRAM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** @file glshader.h GL shader. | ||
* | ||
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBGUI_GLSHADER_H | ||
#define LIBGUI_GLSHADER_H | ||
|
||
#include <de/libdeng2.h> | ||
|
||
#include "libgui.h" | ||
|
||
namespace de { | ||
|
||
/** | ||
* GL shader. | ||
* | ||
* @ingroup gl | ||
*/ | ||
class LIBGUI_PUBLIC GLShader | ||
{ | ||
public: | ||
GLShader(); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace de | ||
|
||
#endif // LIBGUI_GLSHADER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** @file glstate.h GL state. | ||
* | ||
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBGUI_GLSTATE_H | ||
#define LIBGUI_GLSTATE_H | ||
|
||
#include <de/libdeng2.h> | ||
|
||
#include "libgui.h" | ||
|
||
namespace de { | ||
|
||
/** | ||
* GL state. | ||
* | ||
* @ingroup gl | ||
*/ | ||
class LIBGUI_PUBLIC GLState | ||
{ | ||
public: | ||
GLState(); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace de | ||
|
||
#endif // LIBGUI_GLSTATE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** @file gltarget.h GL render target. | ||
* | ||
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBGUI_GLTARGET_H | ||
#define LIBGUI_GLTARGET_H | ||
|
||
#include <de/libdeng2.h> | ||
|
||
#include "libgui.h" | ||
|
||
namespace de { | ||
|
||
/** | ||
* GL render target. | ||
* | ||
* @ingroup gl | ||
*/ | ||
class LIBGUI_PUBLIC GLTarget | ||
{ | ||
public: | ||
GLTarget(); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace de | ||
|
||
#endif // LIBGUI_GLTARGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** @file gltexture.h GL texture atlas. | ||
* | ||
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef LIBGUI_GLTEXTURE_H | ||
#define LIBGUI_GLTEXTURE_H | ||
|
||
#include <de/libdeng2.h> | ||
|
||
#include "libgui.h" | ||
|
||
namespace de { | ||
|
||
/** | ||
* GL texture atlas. | ||
* | ||
* @ingroup gl | ||
*/ | ||
class LIBGUI_PUBLIC GLTexture | ||
{ | ||
public: | ||
GLTexture(); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace de | ||
|
||
#endif // LIBGUI_GLTEXTURE_H |
Oops, something went wrong.