Skip to content

Commit

Permalink
libgui: Added stubs for GL classes, with basic implementation for GLB…
Browse files Browse the repository at this point in the history
…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
skyjake committed Apr 15, 2013
1 parent 221df9f commit 49589fb
Show file tree
Hide file tree
Showing 23 changed files with 856 additions and 1 deletion.
1 change: 1 addition & 0 deletions doomsday/libgui/include/de/GLBuffer
@@ -0,0 +1 @@
#include "gui/glbuffer.h"
1 change: 1 addition & 0 deletions doomsday/libgui/include/de/GLProgram
@@ -0,0 +1 @@
#include "gui/glprogram.h"
1 change: 1 addition & 0 deletions doomsday/libgui/include/de/GLShader
@@ -0,0 +1 @@
#include "gui/glshader.h"
1 change: 1 addition & 0 deletions doomsday/libgui/include/de/GLState
@@ -0,0 +1 @@
#include "gui/glstate.h"
1 change: 1 addition & 0 deletions doomsday/libgui/include/de/GLTarget
@@ -0,0 +1 @@
#include "gui/gltarget.h"
1 change: 1 addition & 0 deletions doomsday/libgui/include/de/GLTexture
@@ -0,0 +1 @@
#include "gui/gltexture.h"
1 change: 1 addition & 0 deletions doomsday/libgui/include/de/GLUniform
@@ -0,0 +1 @@
#include "gui/gluniform.h"
1 change: 0 additions & 1 deletion doomsday/libgui/include/de/Window

This file was deleted.

149 changes: 149 additions & 0 deletions doomsday/libgui/include/de/gui/glbuffer.h
@@ -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
44 changes: 44 additions & 0 deletions doomsday/libgui/include/de/gui/glprogram.h
@@ -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
44 changes: 44 additions & 0 deletions doomsday/libgui/include/de/gui/glshader.h
@@ -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
44 changes: 44 additions & 0 deletions doomsday/libgui/include/de/gui/glstate.h
@@ -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
44 changes: 44 additions & 0 deletions doomsday/libgui/include/de/gui/gltarget.h
@@ -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
44 changes: 44 additions & 0 deletions doomsday/libgui/include/de/gui/gltexture.h
@@ -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

0 comments on commit 49589fb

Please sign in to comment.