Skip to content

Commit

Permalink
Texture upload refactoring continues:
Browse files Browse the repository at this point in the history
* Store the used/assumed color palette index for the loaded image data in de::Image making it possible to determine the difference between a luminance texture and a non-masked paletted texture without forcing the user to track this information. This removes a nasty logical disconnect between the namespace from which an image is loaded and whether or not it is paletted in de::Textures::prepareVariant.
* Do not allocate double the required storage space for luminance textures with TXCF_CONVERT_8BIT_TO_ALPHA when taking a texture content copy. We do not do any in-place conversions once the upload task has been deferred (the only caller) so this is just unused space. Although we should do in-place conversions during content upload, that is not the current logic.
* Added conversion from color-paletted to alpha-map. Not exactly optimum but considering we'll probably never use it, it doesn't really matter. I merely needed to eliminate a logic branch/use case.
* Moved the "noStretch" and "toAlpha" properties into de::TextureVariantSpecification.
* Fixed lightmap clamping.
* Cleanup.

The only remaining unwanted uses of the variant usage contexts in de::Textures::prepareVariant are for the min/mag filter selections. Once this is addressed (and creation of the image analyses moved out), the context compare in GL_CompareTextureVariantSpecifications can be removed, further improving GL texture object sharing.
  • Loading branch information
danij-deng committed Apr 3, 2011
1 parent 80b7f13 commit f08458c
Show file tree
Hide file tree
Showing 28 changed files with 200 additions and 185 deletions.
6 changes: 3 additions & 3 deletions doomsday/engine/portable/include/gl_main.h
Expand Up @@ -148,7 +148,7 @@ int GL_ChooseSmartFilter(int width, int height, int flags);
* 4 = RGBA
*/
uint8_t* GL_ConvertBuffer(const uint8_t* src, int width, int height,
int informat, colorpaletteid_t pal, int outformat);
int informat, int paletteIdx, int outformat);

/**
* @param method Unique identifier of the smart filtering method to apply.
Expand All @@ -175,7 +175,7 @@ boolean GL_QuantizeImageToPalette(uint8_t* out, int outformat, int paletteIdx,
* looking up the nearest match in the palette. Increases the brightness
* to maximum.
*/
void GL_DeSaturatePalettedImage(byte* buffer, int paletteIdx, int width, int height);
void GL_DeSaturatePalettedImage(uint8_t* buffer, int paletteIdx, int width, int height);

/**
* Calculates the properties of a dynamic light that the given sprite frame
Expand All @@ -184,7 +184,7 @@ void GL_DeSaturatePalettedImage(byte* buffer, int paletteIdx, int width, int hei
* Handles pixel sizes; 1 (==2), 3 and 4.
*/
void GL_CalcLuminance(const uint8_t* buffer, int width, int height, int comps,
colorpaletteid_t palid, float* brightX, float* brightY, float color[3],
int paletteIdx, float* brightX, float* brightY, float color[3],
float* lumSize);

/**
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/include/gl_tex.h
Expand Up @@ -124,12 +124,12 @@ void FindAverageColor(const uint8_t* pixels, int width, int height,
* @param pixels Index-color image to evaluate.
* @param width Logical width of the image in pixels.
* @param height Logical height of the image in pixels.
* @param palid Unique identifier of the color palette to use.
* @param paletteIdx Index of the color palette to use else @c 0
* @param hasAlpha @c true == @a pixels includes alpha data.
* @param color Determined average color written here.
*/
void FindAverageColorIdx(const uint8_t* pixels, int width, int height,
colorpaletteid_t palid, boolean hasAlpha, float color[3]);
int paletteIdx, boolean hasAlpha, float color[3]);

/**
* @param pixels RGB(a) image to evaluate.
Expand All @@ -144,12 +144,12 @@ void FindAverageLineColor(const uint8_t* pixels, int width, int height,
* @param pixels Index-color image to evaluate.
* @param width Logical width of the image in pixels.
* @param height Logical height of the image in pixels.
* @param palid Unique identifier of the color palette to use.
* @param paletteIdx Index of the color palette to use else @c 0
* @param hasAlpha @c true == @a pixels includes alpha data.
* @param color Determined average color written here.
*/
void FindAverageLineColorIdx(const uint8_t* pixels, int width, int height,
int line, colorpaletteid_t palid, boolean hasAlpha, float color[3]);
int line, int paletteIdx, boolean hasAlpha, float color[3]);

/**
* Calculates a clip region for the image that excludes alpha pixels.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/gl_texmanager.h
Expand Up @@ -286,7 +286,7 @@ int GL_CompareTextureVariantSpecifications(const texturevariantspecification_t*
texturevariantspecification_t* GL_TextureVariantSpecificationForContext(
texturevariantusagecontext_t tc, int flags, byte border, int tClass,
int tMap, int wrapS, int wrapT, int anisoFilter, boolean mipmapped,
boolean gammaCorrection);
boolean gammaCorrection, boolean noStretch, boolean toAlpha);

/**
* Prepare a TextureVariantSpecification according to usage context.
Expand Down
15 changes: 12 additions & 3 deletions doomsday/engine/portable/include/image.h
Expand Up @@ -38,15 +38,24 @@
* @defgroup imageFlags Image Flags
*/
/*@{*/
#define IMGF_IS_MASKED 0x1
#define IMGF_IS_MASKED (0x1)
/*@}*/

typedef struct image_s {
/// @see imageFlags
int flags;

/// Index of the color palette used/assumed or @c 0 if none (1-based).
int palette;

/// Dimensions of the image in logical pixels.
int width;
int height;

/// Bytes per pixel in the data buffer.
int pixelSize;
int originalBits; /// Bits per pixel in the image file.
int flags; /// @see imageFlags

/// Pixel color/palette (+alpha) data buffer.
uint8_t* pixels;
} image_t;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/p_materialmanager.h
Expand Up @@ -128,7 +128,7 @@ materialnum_t Materials_ToMaterialNum(struct material_s* mat);
struct materialvariantspecification_s* Materials_VariantSpecificationForContext(
materialvariantusagecontext_t mc, int flags, byte border, int tClass,
int tMap, int wrapS, int wrapT, int anisoFilter, boolean mipmapped,
boolean gammaCorrection);
boolean gammaCorrection, boolean noStretch, boolean toAlpha);

struct materialvariant_s* Materials_ChooseVariant(struct material_s* mat,
const struct materialvariantspecification_s* spec);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/r_data.h
Expand Up @@ -321,7 +321,7 @@ int R_ColorPaletteCount(void);
* Given a color palette index return the associated ColorPalette.
* @return ColorPalette if found else @c NULL
*/
struct colorpalette_s* R_ToColorPalette(int palIdx);
struct colorpalette_s* R_ToColorPalette(int paletteIdx);

/**
* Add a new (named) color palette.
Expand Down
Expand Up @@ -82,7 +82,7 @@ typedef struct {
int flags; /// @see textureVariantSpecificationFlags
byte border; /// In pixels, added to all four edges of the texture.
int wrapS, wrapT;
boolean mipmapped, gammaCorrection;
boolean mipmapped, gammaCorrection, noStretch, toAlpha;
int anisoFilter;
colorpalettetranslationspecification_t* translated;
} variantspecification_t;
Expand Down
20 changes: 8 additions & 12 deletions doomsday/engine/portable/src/gl_main.c
Expand Up @@ -1041,7 +1041,7 @@ void GL_SetMaterial(material_t* mat)
Con_Error("GL_SetMaterial: No usage context specified.");
Materials_Prepare(&ms, mat, true,
Materials_VariantSpecificationForContext(MC_UNKNOWN, 0, 0, 0, 0,
GL_REPEAT, GL_REPEAT, 0, false, false));
GL_REPEAT, GL_REPEAT, 0, false, false, false, false));
GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode);
}

Expand All @@ -1050,7 +1050,7 @@ void GL_SetPSprite(material_t* mat, int tClass, int tMap)
material_snapshot_t ms;
Materials_Prepare(&ms, mat, true,
Materials_VariantSpecificationForContext(MC_PSPRITE, 0, 1, tClass,
tMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, false, true));
tMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, false, true, true, false));
GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode);
}

Expand Down Expand Up @@ -1131,7 +1131,7 @@ uint8_t* GL_SmartFilter(int method, const uint8_t* src, int width, int height,
}

uint8_t* GL_ConvertBuffer(const uint8_t* in, int width, int height, int informat,
colorpaletteid_t palid, int outformat)
int paletteIdx, int outformat)
{
assert(in);
{
Expand All @@ -1155,16 +1155,14 @@ uint8_t* GL_ConvertBuffer(const uint8_t* in, int width, int height, int informat
// Conversion from pal8(a) to RGB(A).
if(informat <= 2 && outformat >= 3)
{
GL_PalettizeImage(out, outformat, R_FindColorPaletteIndexForId(palid), false,
in, informat, width, height);
GL_PalettizeImage(out, outformat, paletteIdx, false, in, informat, width, height);
return out;
}

// Conversion from RGB(A) to pal8(a), using pal18To8.
if(informat >= 3 && outformat <= 2)
{
GL_QuantizeImageToPalette(out, outformat, R_FindColorPaletteIndexForId(palid),
in, informat, width, height);
GL_QuantizeImageToPalette(out, outformat, paletteIdx, in, informat, width, height);
return out;
}

Expand All @@ -1189,8 +1187,7 @@ uint8_t* GL_ConvertBuffer(const uint8_t* in, int width, int height, int informat
}

void GL_CalcLuminance(const uint8_t* buffer, int width, int height, int pixelSize,
colorpaletteid_t palid, float* brightX, float* brightY, float color[3],
float* lumSize)
int paletteIdx, float* brightX, float* brightY, float color[3], float* lumSize)
{
assert(buffer && brightX && brightY && color && lumSize);
{
Expand All @@ -1205,10 +1202,9 @@ void GL_CalcLuminance(const uint8_t* buffer, int width, int height, int pixelSiz

if(pixelSize == 1)
{
pal = R_ToColorPalette(R_FindColorPaletteIndexForId(palid));
pal = R_ToColorPalette(paletteIdx);
if(NULL == pal)
Con_Error("GL_CalcLuminance: Failed to locate ColorPalette for id %u.",
(uint) palid);
Con_Error("GL_CalcLuminance: Failed to locate ColorPalette for index %i.", paletteIdx);
}

for(i = 0; i < 3; ++i)
Expand Down
16 changes: 7 additions & 9 deletions doomsday/engine/portable/src/gl_tex.c
Expand Up @@ -753,7 +753,7 @@ void GL_DownMipmap8(uint8_t* in, uint8_t* fadedOut, int width, int height, float
}

void FindAverageLineColorIdx(const uint8_t* data, int w, int h, int line,
colorpaletteid_t palid, boolean hasAlpha, float col[3])
int paletteIdx, boolean hasAlpha, float col[3])
{
assert(data && col);
{
Expand All @@ -778,10 +778,9 @@ void FindAverageLineColorIdx(const uint8_t* data, int w, int h, int line,
return;
}

pal = R_ToColorPalette(R_FindColorPaletteIndexForId(palid));
pal = R_ToColorPalette(paletteIdx);
if(NULL == pal)
Con_Error("FindAverageLineColorIdx: Failed to locate ColorPalette for id %u.",
(uint) palid);
Con_Error("FindAverageLineColorIdx: Failed to locate ColorPalette for index %i.", paletteIdx);

numpels = w * h;
start = data + w * line;
Expand Down Expand Up @@ -888,8 +887,8 @@ void FindAverageColor(const uint8_t* pixels, int width, int height,
}
}

void FindAverageColorIdx(const uint8_t* data, int w, int h,
colorpaletteid_t palid, boolean hasAlpha, float col[3])
void FindAverageColorIdx(const uint8_t* data, int w, int h, int paletteIdx,
boolean hasAlpha, float col[3])
{
assert(data && col);
{
Expand All @@ -904,10 +903,9 @@ void FindAverageColorIdx(const uint8_t* data, int w, int h,
return;
}

pal = R_ToColorPalette(R_FindColorPaletteIndexForId(palid));
pal = R_ToColorPalette(paletteIdx);
if(NULL == pal)
Con_Error("FindAverageColorIdx: Failed to locate ColorPalette for id %u.",
(uint) palid);
Con_Error("FindAverageColorIdx: Failed to locate ColorPalette for index %i.", paletteIdx);

numpels = w * h;
alphaStart = data + numpels;
Expand Down

0 comments on commit f08458c

Please sign in to comment.