Skip to content

Commit

Permalink
OpenGL|Client|libgui: Compiling for OpenGL ES 2
Browse files Browse the repository at this point in the history
Todo: Must implement glBlitFramebuffer manually.
  • Loading branch information
skyjake committed May 2, 2017
1 parent df88dd7 commit 04f4033
Show file tree
Hide file tree
Showing 22 changed files with 220 additions and 52 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/render/rend_main.h
Expand Up @@ -78,7 +78,9 @@ extern FogParams fogParams;
DENG_EXTERN_C byte smoothTexAnim, devMobjVLights;

DENG_EXTERN_C int renderTextures; /// @c 0= no textures, @c 1= normal mode, @c 2= lighting debug
#if defined (DENG_OPENGL)
DENG_EXTERN_C int renderWireframe;
#endif
//DENG_EXTERN_C int useMultiTexLights;
//DENG_EXTERN_C int useMultiTexDetails;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/ui/zonedebug.h
Expand Up @@ -23,7 +23,7 @@
#define CLIENT_ZONEDEBUG_H

#include <de/liblegacy.h>
#ifdef DENG_DEBUG
#if defined (DENG_DEBUG) && defined (DENG_OPENGL)

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/src/gl/dgl_common.cpp
Expand Up @@ -712,7 +712,9 @@ dd_bool DGL_SetFloat(int name, float value)

case DGL_POINT_SIZE:
GL_state.currentPointSize = value;
#if defined (DENG_OPENGL)
LIBGUI_GL.glPointSize(value);
#endif
break;

default:
Expand Down
24 changes: 22 additions & 2 deletions doomsday/apps/client/src/gl/dgl_draw.cpp
Expand Up @@ -94,7 +94,9 @@ struct DGLDrawState

void release()
{
#if defined (DENG_HAVE_VAOS)
LIBGUI_GL.glDeleteVertexArrays(1, &vertexArray);
#endif
arrayData.clear();
}
};
Expand Down Expand Up @@ -235,6 +237,7 @@ struct DGLDrawState
auto *dbuf = new GLData::DrawBuffer;

// Vertex array object.
#if defined (DENG_HAVE_VAOS)
{
auto &GL = LIBGUI_GL;
GL.glGenVertexArrays(1, &dbuf->vertexArray);
Expand All @@ -245,6 +248,7 @@ struct DGLDrawState
}
GL.glBindVertexArray(0);
}
#endif

gl->buffers.append(dbuf);
}
Expand All @@ -260,7 +264,14 @@ struct DGLDrawState
GLData::DrawBuffer &buf = nextBuffer();
buf.arrayData.setData(&vertices[0], sizeof(Vertex) * vertices.size(), gl::Stream);

#if defined (DENG_HAVE_VAOS)
GL.glBindVertexArray(buf.vertexArray);
#else
for (uint i = 0; i < NUM_VERTEX_ATTRIB_ARRAYS; ++i)
{
GL.glEnableVertexAttribArray(i);
}
#endif
LIBGUI_ASSERT_GL_OK();

GL.glBindBuffer(GL_ARRAY_BUFFER, buf.arrayData.glName());
Expand All @@ -280,8 +291,17 @@ struct DGLDrawState

void glUnbindArrays()
{
LIBGUI_GL.glBindVertexArray(0);
LIBGUI_ASSERT_GL_OK();
auto &GL = LIBGUI_GL;

#if defined (DENG_HAVE_VAOS)
GL.glBindVertexArray(0);
#else
for (uint i = 0; i < NUM_VERTEX_ATTRIB_ARRAYS; ++i)
{
GL.glDisableVertexAttribArray(i);
LIBGUI_ASSERT_GL_OK();
}
#endif
}

GLenum glPrimitive() const
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/src/gl/gl_main.cpp
Expand Up @@ -1477,7 +1477,9 @@ D_CMD(Fog)
void GL_Register()
{
// Cvars
#if defined (DENG_OPENGL)
C_VAR_INT ("rend-dev-wireframe", &renderWireframe, CVF_NO_ARCHIVE, 0, 2);
#endif
C_VAR_INT ("rend-fog-default", &fogModeDefault, 0, 0, 2);

// * Render-HUD
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/src/gl/sys_opengl.cpp
Expand Up @@ -274,8 +274,10 @@ void Sys_GLConfigureDefaultState(void)

//LIBGUI_GL.glEnable(GL_POINT_SMOOTH);
//LIBGUI_GL.glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
#if defined (DENG_OPENGL)
LIBGUI_GL.glPointSize(GL_state.currentPointSize);
LIBGUI_ASSERT_GL_OK();
#endif

//LIBGUI_GL.glShadeModel(GL_SMOOTH);

Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/src/gl/texturecontent.cpp
Expand Up @@ -57,6 +57,7 @@ static int BytesPerPixelFmt(dgltexformat_t format)
}
}

#if 0
/**
* Given a pixel format return the number of bytes to store one pixel.
* @pre Input data is of GL_UNSIGNED_BYTE type.
Expand Down Expand Up @@ -89,6 +90,7 @@ static int BytesPerPixel(GLint format)
return 0; // Unreachable.
}
}
#endif

void GL_InitTextureContent(texturecontent_t *content)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/network/base/net_main.cpp
Expand Up @@ -619,7 +619,7 @@ void Net_Drawer()
// Draw the demo recording overlay.
Net_DrawDemoOverlay();

# ifdef DENG2_DEBUG
# if defined (DENG2_DEBUG) && defined (DENG_OPENGL)
Z_DebugDrawer();
# endif
#endif // __CLIENT__
Expand Down
12 changes: 11 additions & 1 deletion doomsday/apps/client/src/render/rend_fakeradio.cpp
Expand Up @@ -988,7 +988,11 @@ static uint makeFlatShadowGeometry(DrawList::Indices &indices, Store &verts, gl:
verts.posCoords[indices[order[2]]] = edges[1].inner();
verts.posCoords[indices[order[3]]] = edges[0].inner();
// Set uniform color.
#if defined (DENG_OPENGL)
Vector4ub const &uniformColor = (::renderWireframe? white : black); // White to assist visual debugging.
#else
Vector4ub const &uniformColor = black;
#endif
for(duint i = 0; i < 4; ++i)
{
verts.colorCoords[indices[i]] = uniformColor;
Expand Down Expand Up @@ -1024,7 +1028,13 @@ void Rend_DrawFlatRadio(ConvexSubspace const &subspace)
auto const eyeToSubspace = Vector2f(Rend_EyeOrigin().xz() - subspace.poly().center());

// All shadow geometry uses the same texture (i.e., none) - use the same list.
DrawList &shadowList = ClientApp::renderSystem().drawLists().find(DrawListSpec(::renderWireframe? UnlitGeom : ShadowGeom));
DrawList &shadowList = ClientApp::renderSystem().drawLists().find(
#if defined (DENG_OPENGL)
DrawListSpec(renderWireframe? UnlitGeom : ShadowGeom)
#else
DrawListSpec(ShadowGeom)
#endif
);

// Process all LineSides linked to this subspace as potential shadow casters.
subspace.forAllShadowLines([&subsec, &shadowDark, &eyeToSubspace, &shadowList] (LineSide &side)
Expand Down
4 changes: 4 additions & 0 deletions doomsday/apps/client/src/render/rend_font.cpp
Expand Up @@ -568,6 +568,7 @@ static void textFragmentDrawer(const char* fragment, int x, int y, int alignFlag
flashColor[CB] = (1 + 2 * sat->rgba[CB]) / 3;
}

#if defined (DENG_OPENGL)
if (renderWireframe > 1)
{
DENG_ASSERT_IN_MAIN_THREAD();
Expand All @@ -576,6 +577,7 @@ static void textFragmentDrawer(const char* fragment, int x, int y, int alignFlag
LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
DGL_Disable(DGL_TEXTURE_2D);
}
#endif
if (BitmapFont *bmapFont = font->maybeAs<BitmapFont>())
{
if (bmapFont->textureGLName())
Expand Down Expand Up @@ -739,12 +741,14 @@ static void textFragmentDrawer(const char* fragment, int x, int y, int alignFlag
DGL_PopMatrix();
}
}
#if defined (DENG_OPENGL)
if (renderWireframe > 1)
{
/// @todo do not assume previous state.
DGL_Enable(DGL_TEXTURE_2D);
LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
#endif
}

static void drawChar(uchar ch, float x, float y, AbstractFont *font,
Expand Down
5 changes: 2 additions & 3 deletions doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -168,14 +168,13 @@ dfloat fieldOfView = 95.0f;
dbyte smoothTexAnim = true;

dint renderTextures = true;
#if defined (DENG_OPENGL)
dint renderWireframe;
//dint useMultiTexLights = true;
//dint useMultiTexDetails = true;
#endif

dint dynlightBlend;

Vector3f torchColor(1, 1, 1);
//dint torchAdditive = true;

dint useShinySurfaces = true;

Expand Down
8 changes: 8 additions & 0 deletions doomsday/apps/client/src/render/viewports.cpp
Expand Up @@ -1053,10 +1053,12 @@ DENG_EXTERN_C void R_RenderPlayerView(dint num)
}

// Go to wireframe mode?
#if defined (DENG_OPENGL)
if (renderWireframe)
{
LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
#endif

DGL_MatrixMode(DGL_PROJECTION);
DGL_PushMatrix();
Expand All @@ -1074,17 +1076,21 @@ DENG_EXTERN_C void R_RenderPlayerView(dint num)
changeViewState(PlayerSprite2D);

// Don't render in wireframe mode with 2D psprites.
#if defined (DENG_OPENGL)
if (renderWireframe)
{
LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
#endif

Rend_Draw2DPlayerSprites(); // If the 2D versions are needed.

#if defined (DENG_OPENGL)
if (renderWireframe)
{
LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
#endif

// Do we need to render any 3D psprites?
if (psp3d)
Expand All @@ -1103,11 +1109,13 @@ DENG_EXTERN_C void R_RenderPlayerView(dint num)
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();

#if defined (DENG_OPENGL)
// Back from wireframe mode?
if (renderWireframe)
{
LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
#endif

// Now we can show the viewPlayer's mobj again.
if (!(player->publicData().flags & DDPF_CHASECAM))
Expand Down
10 changes: 10 additions & 0 deletions doomsday/apps/client/src/ui/infine/finalepagewidget.cpp
Expand Up @@ -158,8 +158,13 @@ void FinalePageWidget::draw() const
// Clear Z buffer (prevent the objects being clipped by nearby polygons).
LIBGUI_GL.glClear(GL_DEPTH_BUFFER_BIT);

#if defined (DENG_OPENGL)
if (renderWireframe > 1)
{
LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
#endif

//glEnable(GL_ALPHA_TEST);
GLState::push().setAlphaTest(true);

Expand All @@ -175,9 +180,14 @@ void FinalePageWidget::draw() const
// Restore original matrices and state: back to normal 2D.
//glDisable(GL_ALPHA_TEST);
GLState::pop();

#if defined (DENG_OPENGL)
// Back from wireframe mode?
if (renderWireframe > 1)
{
LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
#endif

// Filter on top of everything. Only draw if necessary.
if (d->filter[3].value > 0)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/zonedebug.cpp
Expand Up @@ -24,7 +24,7 @@

#include "de_base.h"

#ifdef DENG_DEBUG
#if defined (DENG_DEBUG) && defined (DENG_OPENGL)

#include <cmath>
#include <de/GLState>
Expand Down
4 changes: 2 additions & 2 deletions doomsday/cmake/Options.cmake
Expand Up @@ -11,9 +11,9 @@ else ()
endif ()
endif ()

option (DENG_ENABLE_TURBO "Enable/disable Turbo mode (source merging)"
${DENG_ENABLE_TURBO_DEFAULT})
option (DENG_ENABLE_TURBO "Enable/disable Turbo mode (source merging)" ${DENG_ENABLE_TURBO_DEFAULT})
option (DENG_ENABLE_GUI "Enable/disable the client and all GUI related functionality" ON)
option (DENG_ENABLE_SERVER "Enable/disable the server executable" ON)
option (DENG_ENABLE_SDK "Enable/disable installation of the Doomsday 2 SDK" ON)
option (DENG_ENABLE_TOOLS "Compile the Doomsday tools" ON)
option (DENG_ENABLE_DEPLOYQT "Enable/disable the *deployqt tool" ON)
Expand Down
12 changes: 11 additions & 1 deletion doomsday/cmake/config/DengGuiConfig.cmake
@@ -1,10 +1,20 @@
# find_package (Qt5 COMPONENTS Gui OpenGL REQUIRED)
find_package (DengCore REQUIRED)

# Deng::libgui may exist in the current build, in which case using
# Deng::libgui may exist in the current build, in which case using
# a previously installed version is inappropriate.
if (NOT TARGET Deng::libgui)
include ("${CMAKE_CURRENT_LIST_DIR}/DengGui.cmake")
endif ()

list (APPEND DENG_REQUIRED_PACKAGES net.dengine.stdlib.gui)

if (DENG_OPENGL_API STREQUAL "3.3")
add_definitions (-DDENG_OPENGL=330)
elseif (DENG_OPENGL_API STREQUAL "GLES3")
add_definitions (-DDENG_OPENGL_ES=30)
elseif (DENG_OPENGL_API STREQUAL "GLES2")
add_definitions (-DDENG_OPENGL_ES=20)
else ()
message (FATAL_ERROR "Invalid value for OpenGL API: ${DENG_OPENGL_API}")
endif ()
11 changes: 9 additions & 2 deletions doomsday/sdk/libgui/include/de/graphics/opengl.h
Expand Up @@ -30,25 +30,32 @@
*/
#if (DENG_OPENGL == 330)
# include <QOpenGLFunctions_3_3_Core>
# include <QOpenGLExtensions>
# define QOpenGLFunctions_Doomsday QOpenGLFunctions_3_3_Core
# ifndef GL_VERSION_3_3
# error "OpenGL 3.3 (or newer) headers not found"
# endif

#elif (DENG_OPENGL_ES == 30)
# include <QOpenGLExtraFunctions>
# include <QOpenGLExtensions>
# define QOpenGLFunctions_Doomsday QOpenGLExtraFunctions

#elif (DENG_OPENGL_ES == 20)
# include <QOpenGLFunctions>
# include <QOpenGLExtensions>
# define QOpenGLFunctions_Doomsday QOpenGLFunctions
#endif

#include <QOpenGLExtensions>

// Defined in GLES2.
#ifndef GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS
# define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9
#endif

#if !defined (DENG_OPENGL_ES) || DENG_OPENGL_ES > 20
# define DENG_HAVE_VAOS
# define DENG_HAVE_INSTANCES
# define DENG_HAVE_BLIT_FRAMEBUFFER
#endif

#endif // LIBGUI_SYSTEM_OPENGL_H

0 comments on commit 04f4033

Please sign in to comment.