Skip to content

Commit

Permalink
Refactor|GL|Client: Use libgui’s GLInfo instead of sys_opengl
Browse files Browse the repository at this point in the history
Available extensions and OpenGL limits come now from libgui.

Also cleaned up old/dead code from sys_opengl.
  • Loading branch information
skyjake committed Dec 5, 2013
1 parent 8065cbf commit 1707244
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 362 deletions.
28 changes: 0 additions & 28 deletions doomsday/client/include/gl/sys_opengl.h
Expand Up @@ -87,10 +87,6 @@
*/
typedef struct gl_state_s {
/// Global config:
boolean forceFinishBeforeSwap;
int maxTexFilterAniso;
int maxTexSize; // Pixels.
int maxTexUnits;
int multisampleFormat;

/// Current state:
Expand All @@ -110,25 +106,6 @@ typedef struct gl_state_s {
uint texNonPowTwo : 1;
uint vsync : 1;
} features;

/// Extension availability bits:
struct {
uint blendSub : 1;
uint genMipmapSGIS : 1;
uint lockArray : 1;
#ifdef USE_TEXTURE_COMPRESSION_S3
uint texCompressionS3 : 1;
#endif
uint texEnvComb : 1;
uint texEnvCombNV : 1;
uint texEnvCombATI : 1;
uint texFilterAniso : 1;
uint texNonPowTwo : 1;
#if WIN32
uint wglMultisampleARB : 1;
uint wglSwapIntervalEXT : 1;
#endif
} extensions;
} gl_state_t;

typedef enum arraytype_e {
Expand Down Expand Up @@ -195,11 +172,6 @@ void Sys_GLConfigureDefaultState(void);
*/
void Sys_GLPrintExtensions(void);

/**
* @return Non-zero iff the extension is found.
*/
boolean Sys_GLQueryExtension(const char* name, const GLubyte* extensions);

boolean Sys_GLCheckError(void);

#endif // __CLIENT__
Expand Down
12 changes: 6 additions & 6 deletions doomsday/client/src/gl/dgl_common.cpp
Expand Up @@ -35,6 +35,7 @@
#include "api_gl.h"

#include <de/GLState>
#include <de/GLInfo>

using namespace de;

Expand All @@ -51,11 +52,11 @@ static void envAddColoredAlpha(int activate, GLenum addFactor)
if(activate)
{
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
GL_state.extensions.texEnvCombNV ? GL_COMBINE4_NV : GL_COMBINE);
GLInfo::extensions().NV_texture_env_combine4? GL_COMBINE4_NV : GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);

// Combine: texAlpha * constRGB + 1 * prevRGB.
if(GL_state.extensions.texEnvCombNV)
if(GLInfo::extensions().NV_texture_env_combine4)
{
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
Expand All @@ -67,7 +68,7 @@ static void envAddColoredAlpha(int activate, GLenum addFactor)
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE3_RGB_NV, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND3_RGB_NV, GL_SRC_COLOR);
}
else if(GL_state.extensions.texEnvCombATI)
else if(GLInfo::extensions().ATI_texture_env_combine3)
{ // MODULATE_ADD_ATI: Arg0 * Arg2 + Arg1.
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE_ADD_ATI);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
Expand Down Expand Up @@ -205,7 +206,7 @@ void GL_ModulateTexture(int mode)
envAddColoredAlpha(true, mode == 5 ? GL_SRC_ALPHA : GL_SRC_COLOR);

// Alpha remains unchanged.
if(GL_state.extensions.texEnvCombNV)
if(GLInfo::extensions().NV_texture_env_combine4)
{
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_ZERO);
Expand Down Expand Up @@ -398,11 +399,10 @@ boolean DGL_GetIntegerv(int name, int *v)
switch(name)
{
case DGL_MODULATE_ADD_COMBINE:
*v = GL_state.extensions.texEnvCombNV || GL_state.extensions.texEnvCombATI;
*v = GLInfo::extensions().NV_texture_env_combine4 || GLInfo::extensions().ATI_texture_env_combine3;
break;

case DGL_SCISSOR_TEST:
//glGetIntegerv(GL_SCISSOR_TEST, (GLint*) v);
*(GLint *) v = GLState::current().scissor();
break;

Expand Down
27 changes: 7 additions & 20 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -48,6 +48,7 @@
#include "render/vr.h"

#include <de/DisplayMode>
#include <de/GLInfo>
#include <de/GLState>

D_CMD(Fog);
Expand Down Expand Up @@ -299,10 +300,6 @@ static void printConfiguration()
LOG_VERBOSE(" Texture Anisotropy: %s") << (GL_state.features.texFilterAniso? "variable" : "fixed");
LOG_VERBOSE(" Texture Compression: %b") << GL_state.features.texCompression;
LOG_VERBOSE(" Texture NPOT: %b") << GL_state.features.texNonPowTwo;
if(GL_state.forceFinishBeforeSwap)
{
LOG_VERBOSE(" glFinish() forced before swapping buffers.");
}
}

boolean GL_EarlyInit()
Expand All @@ -315,8 +312,9 @@ boolean GL_EarlyInit()
gamma_support = !CommandLine_Check("-noramp");

// We are simple people; two texture units is enough.
numTexUnits = MIN_OF(GL_state.maxTexUnits, MAX_TEX_UNITS);
envModAdd = (GL_state.extensions.texEnvCombNV || GL_state.extensions.texEnvCombATI);
numTexUnits = MIN_OF(GLInfo::limits().maxTexUnits, MAX_TEX_UNITS);
envModAdd = (GLInfo::extensions().NV_texture_env_combine4 ||
GLInfo::extensions().ATI_texture_env_combine3);

GL_InitDeferredTask();

Expand All @@ -325,21 +323,11 @@ boolean GL_EarlyInit()
Rend_ModelInit();

// Check the maximum texture size.
if(GL_state.maxTexSize == 256)
if(GLInfo::limits().maxTexSize == 256)
{
LOG_WARNING("Using restricted texture w/h ratio (1:8)");
ratioLimit = 8;
}
// Set a custom maximum size?
if(CommandLine_CheckWith("-maxtex", 1))
{
int customSize = M_CeilPow2(strtol(CommandLine_Next(), 0, 0));

if(GL_state.maxTexSize < customSize)
customSize = GL_state.maxTexSize;
GL_state.maxTexSize = customSize;
LOG_INFO("Using maximum texture size of %i x %i") << GL_state.maxTexSize << GL_state.maxTexSize;
}
if(CommandLine_Check("-outlines"))
{
fillOutlines = false;
Expand Down Expand Up @@ -822,7 +810,7 @@ int GL_GetTexAnisoMul(int level)
{
if(level < 0)
{ // Go with the maximum!
mul = GL_state.maxTexFilterAniso;
mul = GLInfo::limits().maxTexFilterAniso;
}
else
{ // Convert from a DGL aniso level to a multiplier.
Expand All @@ -841,8 +829,7 @@ int GL_GetTexAnisoMul(int level)
}

// Clamp.
if(mul > GL_state.maxTexFilterAniso)
mul = GL_state.maxTexFilterAniso;
mul = MIN_OF(mul, GLInfo::limits().maxTexFilterAniso);
}
}

Expand Down
21 changes: 11 additions & 10 deletions doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -46,6 +46,7 @@

#include <QSize>
#include <de/ByteRefArray>
#include <de/GLInfo>
#include <de/mathutil.h>
#include <de/memory.h>
#include <de/memoryzone.h>
Expand Down Expand Up @@ -1280,7 +1281,7 @@ static GLint ChooseTextureFormat(dgltexformat_t format, boolean allowCompression
if(!compress)
return GL_RGB8;
#if USE_TEXTURE_COMPRESSION_S3
if(GL_state.extensions.texCompressionS3)
if(GLInfo::extensions().EXT_texture_compression_s3tc)
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
#endif
return GL_COMPRESSED_RGB;
Expand All @@ -1290,7 +1291,7 @@ static GLint ChooseTextureFormat(dgltexformat_t format, boolean allowCompression
if(!compress)
return GL_RGBA8;
#if USE_TEXTURE_COMPRESSION_S3
if(GL_state.extensions.texCompressionS3)
if(GLInfo::extensions().EXT_texture_compression_s3tc)
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
#endif
return GL_COMPRESSED_RGBA;
Expand Down Expand Up @@ -1330,7 +1331,7 @@ boolean GL_UploadTextureGrayMipmap(int glFormat, int loadFormat, const uint8_t*
(width != M_CeilPow2(width) || height != M_CeilPow2(height)))
return false;

if(width > GL_state.maxTexSize || height > GL_state.maxTexSize)
if(width > GLInfo::limits().maxTexSize || height > GLInfo::limits().maxTexSize)
return false;

numLevels = GL_NumMipmapLevels(width, height);
Expand Down Expand Up @@ -1396,7 +1397,7 @@ boolean GL_UploadTexture(int glFormat, int loadFormat, const uint8_t* pixels,
return false;

// Check that the texture dimensions are valid.
if(width > GL_state.maxTexSize || height > GL_state.maxTexSize)
if(width > GLInfo::limits().maxTexSize || height > GLInfo::limits().maxTexSize)
return false;

if(!GL_state.features.texNonPowTwo &&
Expand All @@ -1414,7 +1415,7 @@ boolean GL_UploadTexture(int glFormat, int loadFormat, const uint8_t* pixels,
DENG_ASSERT_GL_CONTEXT_ACTIVE();

// Automatic mipmap generation?
if(GL_state.extensions.genMipmapSGIS && genMipmaps)
if(GLInfo::extensions().SGIS_generate_mipmap && genMipmaps)
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);

glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
Expand All @@ -1427,7 +1428,7 @@ boolean GL_UploadTexture(int glFormat, int loadFormat, const uint8_t* pixels,
glPixelStorei(GL_UNPACK_SKIP_ROWS, (GLint)unpackSkipRows);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, (GLint)unpackSkipPixels);

if(genMipmaps && !GL_state.extensions.genMipmapSGIS)
if(genMipmaps && !GLInfo::extensions().SGIS_generate_mipmap)
{ // Build all mipmap levels.
int neww, newh, bpp, w, h;
void* image, *newimage;
Expand Down Expand Up @@ -2320,14 +2321,14 @@ boolean GL_OptimalTextureSize(int width, int height, boolean noStretch, boolean
}

// Hardware limitations may force us to modify the preferred size.
if(*optWidth > GL_state.maxTexSize)
if(*optWidth > GLInfo::limits().maxTexSize)
{
*optWidth = GL_state.maxTexSize;
*optWidth = GLInfo::limits().maxTexSize;
noStretch = false;
}
if(*optHeight > GL_state.maxTexSize)
if(*optHeight > GLInfo::limits().maxTexSize)
{
*optHeight = GL_state.maxTexSize;
*optHeight = GLInfo::limits().maxTexSize;
noStretch = false;
}

Expand Down

0 comments on commit 1707244

Please sign in to comment.