Skip to content

Commit

Permalink
Refactor|GL: gl_texmanager.h no longer depends on sys_opengl.h
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 21, 2013
1 parent ec70eba commit 7dcdc50
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 91 deletions.
11 changes: 11 additions & 0 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -247,6 +247,17 @@ int GL_GetTexAnisoMul(int level);
*/
int GL_NumMipmapLevels(int width, int height);

/**
* Determine the optimal size for a texture. Usually the dimensions are scaled
* upwards to the next power of two.
*
* @param noStretch If @c true, the stretching can be skipped.
* @param isMipMapped If @c true, we will require mipmaps (this has an effect
* on the optimal size).
*/
boolean GL_OptimalTextureSize(int width, int height, boolean noStretch, boolean isMipMapped,
int *optWidth, int *optHeight);

/**
* @param width Width of the image in pixels.
* @param height Height of the image in pixels.
Expand Down
17 changes: 1 addition & 16 deletions doomsday/client/include/gl/gl_texmanager.h
Expand Up @@ -29,13 +29,9 @@
# error "gl/gl_texmanager.h requires C++"
#endif

#include "sys_opengl.h"

#include "gl/gl_defer.h"
#include "gl/texturecontent.h"
#include "api_gl.h"
#include "resource/image.h"
#include "resource/rawtexture.h"
#include "TextureManifest"
#include "TextureVariantSpec"
#include "uri.hh"

Expand Down Expand Up @@ -90,17 +86,6 @@ void GL_ResetTextureManager();

void GL_TexReset();

/**
* Determine the optimal size for a texture. Usually the dimensions are scaled
* upwards to the next power of two.
*
* @param noStretch If @c true, the stretching can be skipped.
* @param isMipMapped If @c true, we will require mipmaps (this has an effect
* on the optimal size).
*/
boolean GL_OptimalTextureSize(int width, int height, boolean noStretch, boolean isMipMapped,
int *optWidth, int *optHeight);

/**
* Change the GL minification filter for all prepared textures.
*/
Expand Down
75 changes: 75 additions & 0 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -769,6 +769,81 @@ int GL_NumMipmapLevels(int width, int height)
return numLevels;
}

boolean GL_OptimalTextureSize(int width, int height, boolean noStretch, boolean isMipMapped,
int *optWidth, int *optHeight)
{
DENG_ASSERT(optWidth && optHeight);
if(GL_state.features.texNonPowTwo && !isMipMapped)
{
*optWidth = width;
*optHeight = height;
}
else if(noStretch)
{
*optWidth = M_CeilPow2(width);
*optHeight = M_CeilPow2(height);
}
else
{
// Determine the most favorable size for the texture.
if(texQuality == TEXQ_BEST) // The best quality.
{
// At the best texture quality *opt, all textures are
// sized *upwards*, so no details are lost. This takes
// more memory, but naturally looks better.
*optWidth = M_CeilPow2(width);
*optHeight = M_CeilPow2(height);
}
else if(texQuality == 0)
{
// At the lowest quality, all textures are sized down to the
// nearest power of 2.
*optWidth = M_FloorPow2(width);
*optHeight = M_FloorPow2(height);
}
else
{
// At the other quality *opts, a weighted rounding is used.
*optWidth = M_WeightPow2(width, 1 - texQuality / (float) TEXQ_BEST);
*optHeight = M_WeightPow2(height, 1 - texQuality / (float) TEXQ_BEST);
}
}

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

// Some GL drivers seem to have problems with VERY small textures.
if(*optWidth < MINTEXWIDTH)
*optWidth = MINTEXWIDTH;
if(*optHeight < MINTEXHEIGHT)
*optHeight = MINTEXHEIGHT;

if(ratioLimit)
{
if(*optWidth > *optHeight) // Wide texture.
{
if(*optHeight < *optWidth / ratioLimit)
*optHeight = *optWidth / ratioLimit;
}
else // Tall texture.
{
if(*optWidth < *optHeight / ratioLimit)
*optWidth = *optHeight / ratioLimit;
}
}

return noStretch;
}

int GL_GetTexAnisoMul(int level)
{
int mul = 1;
Expand Down
75 changes: 0 additions & 75 deletions doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -1125,81 +1125,6 @@ DGLuint GL_PrepareRawTexture(rawtex_t &raw)
return raw.tex;
}

boolean GL_OptimalTextureSize(int width, int height, boolean noStretch, boolean isMipMapped,
int* optWidth, int* optHeight)
{
DENG_ASSERT(optWidth && optHeight);
if(GL_state.features.texNonPowTwo && !isMipMapped)
{
*optWidth = width;
*optHeight = height;
}
else if(noStretch)
{
*optWidth = M_CeilPow2(width);
*optHeight = M_CeilPow2(height);
}
else
{
// Determine the most favorable size for the texture.
if(texQuality == TEXQ_BEST) // The best quality.
{
// At the best texture quality *opt, all textures are
// sized *upwards*, so no details are lost. This takes
// more memory, but naturally looks better.
*optWidth = M_CeilPow2(width);
*optHeight = M_CeilPow2(height);
}
else if(texQuality == 0)
{
// At the lowest quality, all textures are sized down to the
// nearest power of 2.
*optWidth = M_FloorPow2(width);
*optHeight = M_FloorPow2(height);
}
else
{
// At the other quality *opts, a weighted rounding is used.
*optWidth = M_WeightPow2(width, 1 - texQuality / (float) TEXQ_BEST);
*optHeight = M_WeightPow2(height, 1 - texQuality / (float) TEXQ_BEST);
}
}

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

// Some GL drivers seem to have problems with VERY small textures.
if(*optWidth < MINTEXWIDTH)
*optWidth = MINTEXWIDTH;
if(*optHeight < MINTEXHEIGHT)
*optHeight = MINTEXHEIGHT;

if(ratioLimit)
{
if(*optWidth > *optHeight) // Wide texture.
{
if(*optHeight < *optWidth / ratioLimit)
*optHeight = *optWidth / ratioLimit;
}
else // Tall texture.
{
if(*optWidth < *optHeight / ratioLimit)
*optWidth = *optHeight / ratioLimit;
}
}

return noStretch;
}

void GL_SetRawTexturesMinFilter(int newMinFilter)
{
rawtex_t **rawTexs = R_CollectRawTexs();
Expand Down

0 comments on commit 7dcdc50

Please sign in to comment.