Skip to content

Commit

Permalink
Added new routines to handle the determination of whether detail text…
Browse files Browse the repository at this point in the history
…ures or reflections are to be used with a particular material (is it from an PWAD? Does the definition allow this? etc...).
  • Loading branch information
danij committed Nov 17, 2008
1 parent e3beed5 commit 53f71e3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 58 deletions.
83 changes: 29 additions & 54 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -36,11 +36,21 @@
#include "def_data.h"
#include "r_extres.h"

// Flags for decorations.
// Flags for material decorations.
#define DCRF_NO_IWAD 0x1 // Don't use if from IWAD.
#define DCRF_PWAD 0x2 // Can use if from PWAD.
#define DCRF_EXTERNAL 0x4 // Can use if from external resource.

// Flags for material reflections.
#define REFF_NO_IWAD 0x1 // Don't use if from IWAD.
#define REFF_PWAD 0x2 // Can use if from PWAD.
#define REFF_EXTERNAL 0x4 // Can use if from external resource.

// Flags for material detailtexs.
#define DTLF_NO_IWAD 0x1 // Don't use if from IWAD.
#define DTLF_PWAD 0x2 // Can use if from PWAD.
#define DTLF_EXTERNAL 0x4 // Can use if from external resource.

typedef struct materialtexinst_s {
DGLuint tex; // Name of the associated DGL texture.
byte masked;
Expand Down Expand Up @@ -68,16 +78,15 @@ typedef struct {
detailtexinst_t* instances;
} detailtex_t;

// Flags for gltexture_t:
#define GLTXF_MASKED 0x00000001

typedef struct gltexture_s {
DGLuint id;
int flags; // GLTXF_* flags.
int magMode;
float width, height;
boolean masked;
struct {
DGLuint id;
int width, height;
float scale;
} detail;
float scale; // Currently only used with detail textures.
} gltexture_t;

typedef struct glcommand_vertex_s {
Expand All @@ -86,25 +95,10 @@ typedef struct glcommand_vertex_s {
} glcommand_vertex_t;

#define RL_MAX_DIVS 64

// Rendpoly flags.
#define RPF_MASKED 0x0001 // Use the special list for masked textures.
#define RPF_SKY_MASK 0x0004 // A sky mask polygon.
#define RPF_LIGHT 0x0008 // A dynamic light.
#define RPF_DYNLIT 0x0010 // Normal list: poly is dynamically lit.
#define RPF_GLOW 0x0020 // Multiply original vtx colors.
#define RPF_DETAIL 0x0040 // Render with detail (incl. vtx distances)
#define RPF_SHADOW 0x0100
#define RPF_HORIZONTAL 0x0200
#define RPF_SHINY 0x0400 // Shiny surface.
#define RPF_DONE 0x8000 // This poly has already been drawn.

typedef enum {
RP_NONE,
RP_QUAD, // Wall segment.
RP_DIVQUAD, // Divided wall segment.
RP_FLAT // Floor or ceiling.
} rendpolytype_t;
typedef struct walldiv_s {
unsigned int num;
float pos[RL_MAX_DIVS];
} walldiv_t;

typedef struct rvertex_s {
float pos[3];
Expand All @@ -118,33 +112,6 @@ typedef struct rtexcoord_s {
float st[2];
} rtexcoord_t;

typedef struct walldiv_s {
unsigned int num;
float pos[RL_MAX_DIVS];
} walldiv_t;

typedef struct rendpoly_wall_s {
float length;
walldiv_t divs[2]; // For wall segments (two vertices).
} rendpoly_wall_t;

// rendpoly_params_t is only for convenience; the data written in the rendering
// list data buffer is taken from this struct.
typedef struct rendpoly_params_s {
boolean isWall;
rendpolytype_t type;
short flags; // RPF_*.
float texOrigin[2][3]; // Used in texture coordinate calculation.
float texOffset[2]; // Texture coordinates for left/top
// (in real texcoords).
gltexture_t tex;
gltexture_t interTex;
float interPos; // Blending strength (0..1).
uint lightListIdx; // List of lights that affect this poly.
blendmode_t blendMode; // Primitive-specific blending mode.
rendpoly_wall_t* wall; // Wall specific data if any.
} rendpoly_params_t;

// This is the dummy mobj_t used for blockring roots.
// It has some excess information since it has to be compatible with
// regular mobjs (otherwise the rings don't really work).
Expand Down Expand Up @@ -178,6 +145,9 @@ typedef struct {
short offY; // accounted for the patch's internal origin
} texpatch_t;

#define TXDF_NODRAW 0x1 // Not to be drawn.
#define TXDF_IWAD 0x2 // Defines an IWAD texture. Note the definition may NOT be from the IWAD.

// Describes a rectangular texture, which is composed of one
// or more texpatch_t structures that arrange graphic patches.
typedef struct {
Expand Down Expand Up @@ -352,7 +322,8 @@ void R_DestroySkins(void); // Called at shutdown.
void R_InitAnimGroup(ded_group_t* def);

void R_CreateDetailTexture(ded_detailtexture_t* def);
detailtex_t* R_GetDetailTexture(lumpnum_t lump, const char* external);
detailtex_t* R_GetDetailTexture(lumpnum_t lump, const char* external,
float scale, float strength, float maxDist);
void R_DeleteDetailTextures(void);
void R_DestroyDetailTextures(void); // Called at shutdown.

Expand All @@ -366,6 +337,10 @@ rawtex_t** R_CollectRawTexs(int* count);

boolean R_IsAllowedDecoration(ded_decor_t* def, struct material_s* mat,
boolean hasExternal);
boolean R_IsAllowedReflection(ded_reflection_t* def, struct material_s* mat,
boolean hasExternal);
boolean R_IsAllowedDetailTex(ded_detailtexture_t* def, struct material_s* mat,
boolean hasExternal);
boolean R_IsValidLightDecoration(const ded_decorlight_t* lightDef);

#endif
46 changes: 42 additions & 4 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -1568,6 +1568,42 @@ boolean R_IsAllowedDecoration(ded_decor_t* def, material_t* mat,
return (def->flags & DCRF_PWAD) != 0;
}

/**
* @return @c true, if the given reflection works under the
* specified circumstances.
*/
boolean R_IsAllowedReflection(ded_reflection_t* def, material_t* mat,
boolean hasExternal)
{
if(hasExternal)
{
return (def->flags & REFF_EXTERNAL) != 0;
}

if(mat->tex->isFromIWAD)
return !(def->flags & REFF_NO_IWAD);

return (def->flags & REFF_PWAD) != 0;
}

/**
* @return @c true, if the given decoration works under the
* specified circumstances.
*/
boolean R_IsAllowedDetailTex(ded_detailtexture_t* def, material_t* mat,
boolean hasExternal)
{
if(hasExternal)
{
return (def->flags & DTLF_EXTERNAL) != 0;
}

if(mat->tex->isFromIWAD)
return !(def->flags & DTLF_NO_IWAD);

return (def->flags & DTLF_PWAD) != 0;
}

/**
* Prepares the specified patch.
*/
Expand Down Expand Up @@ -1763,15 +1799,16 @@ void R_CreateDetailTexture(ded_detailtexture_t* def)
(def->isExternal? def->detailLump.path : NULL);

// Have we already created one for this?
if((dTex = R_GetDetailTexture(lump, external)))
if((dTex = R_GetDetailTexture(lump, external, def->scale, def->strength,
def->maxDist)))
return;

// Its a new detail texture.
dTex = M_Malloc(sizeof(*dTex));

// The width and height could be used for something meaningful.
dTex->width = dTex->height = 128;
dTex->scale = def->scale;
dTex->scale = (def->scale <= 0? 1 : def->scale);
dTex->strength = def->strength;
dTex->maxDist = def->maxDist;
dTex->lump = lump;
Expand All @@ -1784,15 +1821,16 @@ void R_CreateDetailTexture(ded_detailtexture_t* def)
detailTextures[numDetailTextures-1] = dTex;
}

detailtex_t* R_GetDetailTexture(lumpnum_t lump, const char* external)
detailtex_t* R_GetDetailTexture(lumpnum_t lump, const char* external,
float scale, float strength, float maxDist)
{
int i;

for(i = 0; i < numDetailTextures; ++i)
{
detailtex_t* dTex = detailTextures[i];

if(dTex->lump == lump &&
if(dTex->lump == lump && dTex->scale == scale &&
dTex->strength == strength && dTex->maxDist == maxDist &&
((dTex->external == NULL && external == NULL) ||
(dTex->external && external && !stricmp(dTex->external, external))))
Expand Down

0 comments on commit 53f71e3

Please sign in to comment.