Skip to content

Commit

Permalink
Fixed scale problem with Patch drawing.
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed May 14, 2010
1 parent a38a0aa commit 2e1b6e8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 34 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/api/doomsday.h
Expand Up @@ -351,7 +351,7 @@ extern "C" {
void R_SetupMap(int mode, int flags);
void R_PrecacheMap(void);
void R_PrecacheMobjNum(int mobjtypeNum);
void R_PrecachePatch(const char* name, patchinfo_t* info);
patchid_t R_PrecachePatch(const char* name, patchinfo_t* info);
void R_PrecacheSkinsForState(int stateIndex);
void R_RenderPlayerView(int num);
void R_SetViewWindow(int x, int y, int w, int h);
Expand Down
5 changes: 3 additions & 2 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -161,7 +161,7 @@ typedef struct {
// A patchtex is a lumppatch that has been prepared for render.
typedef struct patchtex_s {
lumpnum_t lump;
gltextureid_t id; // Name of the associated GL texture.
gltextureid_t texId; // Name of the associated GL texture.
boolean isCustom;
short flags;
short width, height;
Expand Down Expand Up @@ -312,7 +312,6 @@ boolean R_UpdateSurface(struct surface_s* suf, boolean forceUpdate);

void R_PrecacheMap(void);
void R_PrecacheMobjNum(int mobjtypeNum);
void R_PrecachePatch(const char* name, patchinfo_t* info);

doomtexturedef_t* R_GetDoomTextureDef(int num);

Expand Down Expand Up @@ -345,7 +344,9 @@ masktex_t* R_CreateMaskTexture(const ded_reflection_t* def);
masktex_t* R_GetMaskTexture(const char* external);
void R_DestroyMaskTextures(void); // Called at shutdown.

patchid_t R_PrecachePatch(const char* name, patchinfo_t* info);
patchtex_t* R_GetPatchTex(lumpnum_t lump); // Creates new entries.

patchtex_t* R_FindPatchTex(patchid_t id);
boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -2080,7 +2080,7 @@ DGLuint GL_PreparePatch(patchtex_t* patchTex)
params.flags |= MLF_TEX_MONOCHROME;
if(patchTex->flags & PF_UPSCALE_AND_SHARPEN)
params.flags |= MLF_TEX_UPSCALE_AND_SHARPEN;
if((texInst = GL_PrepareGLTexture(patchTex->id, &params, NULL)))
if((texInst = GL_PrepareGLTexture(patchTex->texId, &params, NULL)))
return texInst->id;
}
return 0;
Expand Down
43 changes: 18 additions & 25 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -984,15 +984,13 @@ patchtex_t* R_GetPatchTex(lumpnum_t lump)
* Strictly speaking we should specify the border dimension here and
* reference it when upscaling.
*/
p->width += 2;
p->height += 2;
p->extraOffset[0] = p->extraOffset[1] = -1;
}

// Register a gltexture for this.
{
const gltexture_t* glTex = GL_CreateGLTexture(W_LumpName(lump), lump, GLT_DOOMPATCH);
p->id = glTex->id;
p->texId = glTex->id;
}

// Add it to the pointer array.
Expand All @@ -1005,36 +1003,29 @@ patchtex_t* R_GetPatchTex(lumpnum_t lump)

boolean R_GetPatchInfo(patchid_t id, patchinfo_t* info)
{
lumpnum_t lump = (lumpnum_t) id;

if(!info)
return false;

Con_Error("R_GetPatchInfo: Info argument cannot be NULL.");
{
const patchtex_t* p;
memset(info, 0, sizeof(*info));

if(lump >= 0 && lump < numLumps)
if((p = getPatchTex(id)) != NULL)
{
const lumppatch_t* patch = (const lumppatch_t*) W_CacheLumpNum(lump, PU_STATIC);
info->id = id;
info->width = SHORT(patch->width);
info->height = SHORT(patch->height);
info->topOffset = -SHORT(patch->topOffset);
info->offset = -SHORT(patch->leftOffset);
info->isCustom = !W_IsFromIWAD(lump);
/// \fixme
info->extraOffset[0] = info->extraOffset[1] = 0;
W_ChangeCacheTag(lump, PU_CACHE);
info->width = p->width;
info->height = p->height;
info->offset = p->offX;
info->topOffset = p->offY;
info->isCustom = p->isCustom;
info->extraOffset[0] = p->extraOffset[0];
info->extraOffset[1] = p->extraOffset[1];
return true;
}

// Safety precaution.
info->id = -1;

VERBOSE(Con_Message("R_GetPatchInfo: Warning, unknown Patch %i.\n", id));
info->id = -1; // Safety Precaution.
return false;
}
}

void R_PrecachePatch(const char* name, patchinfo_t* info)
patchid_t R_PrecachePatch(const char* name, patchinfo_t* info)
{
lumpnum_t lump;

Expand All @@ -1045,7 +1036,7 @@ void R_PrecachePatch(const char* name, patchinfo_t* info)
}

if(isDedicated)
return;
return -1;

if((lump = W_CheckNumForName(name)) != -1)
{
Expand All @@ -1055,7 +1046,9 @@ void R_PrecachePatch(const char* name, patchinfo_t* info)
{
R_GetPatchInfo((patchid_t)lump, info);
}
return (patchid_t)lump;
}
return -1;
}

/**
Expand Down
13 changes: 8 additions & 5 deletions doomsday/plugins/common/src/hu_stuff.c
Expand Up @@ -3192,6 +3192,9 @@ void Hu_DrawPatch(patchid_t id, int posX, int posY, boolean usePatchOffset)
float x = posX, y = posY, w, h;
patchinfo_t info;

if(id == -1)
return;

DGL_SetPatch(id, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);
if(!R_GetPatchInfo(id, &info))
return;
Expand All @@ -3205,15 +3208,15 @@ void Hu_DrawPatch(patchid_t id, int posX, int posY, boolean usePatchOffset)
y += (float) info.topOffset;
}

if(info.extraOffset[VX])
if(info.extraOffset[0])
{
// This offset is used only for the extra borders in the
// "upscaled and sharpened" patches, so we can tweak the values
// to our liking a bit more.
x += info.extraOffset[VX];
y += info.extraOffset[VY];
w += fabs(info.extraOffset[VX])*2;
h += fabs(info.extraOffset[VY])*2;
x += info.extraOffset[0];
y += info.extraOffset[1];
w += fabs(info.extraOffset[0])*2;
h += fabs(info.extraOffset[1])*2;
}

DGL_Begin(DGL_QUADS);
Expand Down

0 comments on commit 2e1b6e8

Please sign in to comment.