Skip to content

Commit

Permalink
Merge pull request #185 from atsb/texture_combiners_back
Browse files Browse the repository at this point in the history
Texture combiners back
  • Loading branch information
atsb authored Mar 28, 2023
2 parents 5e5174a + 05cc283 commit aa6fcb9
Show file tree
Hide file tree
Showing 18 changed files with 885 additions and 434 deletions.
Binary file modified doom64ex-plus.wad
Binary file not shown.
57 changes: 44 additions & 13 deletions src/engine/am_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static angle_t am_viewangle;

CVAR_EXTERNAL(am_fulldraw);
CVAR_EXTERNAL(am_ssect);
CVAR_EXTERNAL(r_texturecombiner);

//
// AM_BeginDraw
Expand All @@ -55,6 +56,16 @@ CVAR_EXTERNAL(am_ssect);
void AM_BeginDraw(angle_t view, fixed_t x, fixed_t y) {
am_viewangle = view;

if(r_texturecombiner.value > 0 && am_overlay.value) {
GL_SetState(GLSTATE_BLEND, 1);

//
// increase the rgb scale so the automap can look good while transparent (overlay mode)
//
GL_SetTextureMode(GL_COMBINE);
dglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 4);
}

dglDepthRange(0.0f, 0.0f);
dglMatrixMode(GL_PROJECTION);
dglLoadIdentity();
Expand All @@ -77,10 +88,16 @@ void AM_BeginDraw(angle_t view, fixed_t x, fixed_t y) {
//

void AM_EndDraw(void) {
dglPopMatrix();
dglDepthRange(0.0f, 1.0f);
dglPopMatrix();
dglDepthRange(0.0f, 1.0f);

GL_SetDefaultCombiner();
if(r_texturecombiner.value > 0 && am_overlay.value) {
GL_SetState(GLSTATE_BLEND, 0);
GL_SetTextureMode(GL_COMBINE);
GL_SetColorScale();
}

GL_SetDefaultCombiner();
}

//
Expand Down Expand Up @@ -233,14 +250,24 @@ void AM_DrawLeafs(float scale) {
//
// process draw list
//
DL_BeginDrawList(!am_ssect.value && 1);

if (!nolights) {
GL_SetTextureMode(GL_MODULATE);
}
else {
GL_SetTextureMode(GL_REPLACE);
}
DL_BeginDrawList(!am_ssect.value && r_fillmode.value, 0);

if(r_texturecombiner.value > 0) {
if(!nolights) {
dglTexCombModulate(GL_TEXTURE0_ARB, GL_PRIMARY_COLOR);
}
else {
dglTexCombReplace();
}
}
else {
if(!nolights) {
GL_SetTextureMode(GL_MODULATE);
}
else {
GL_SetTextureMode(GL_REPLACE);
}
}

DL_ProcessDrawList(DLT_AMAP, DL_ProcessAutomap);
}
Expand Down Expand Up @@ -314,15 +341,19 @@ void AM_DrawTriangle(mobj_t* mobj, float scale, boolean solid, byte r, byte g, b
return;
}

dglPolygonMode(GL_FRONT_AND_BACK, (solid == 1) ? GL_LINE : GL_FILL);
if(r_fillmode.value) {
dglPolygonMode(GL_FRONT_AND_BACK, (solid == 1) ? GL_LINE : GL_FILL);
}

dglSetVertex(tri);
RB_AddTriangle(0, 1, 2);
dglDisable(GL_TEXTURE_2D);
dglDrawGeometry(3, tri);
dglEnable(GL_TEXTURE_2D);

dglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if(r_fillmode.value) {
dglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}

if (devparm) {
vertCount += 3;
Expand Down
121 changes: 121 additions & 0 deletions src/engine/dgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,124 @@ void dglGetColorf(rcolor color, float* argb) {
argb[1] = (float)((color >> 8) & 0xff) / 255.0f;
argb[0] = (float)(color & 0xff) / 255.0f;
}

//
// dglTexCombReplace
//

void dglTexCombReplace(void) {
#ifdef LOG_GLFUNC_CALLS
I_Printf("dglTexCombReplace\n");
#endif
GL_SetTextureMode(GL_COMBINE_ARB);
GL_SetCombineState(GL_REPLACE);
GL_SetCombineSourceRGB(0, GL_TEXTURE);
GL_SetCombineOperandRGB(0, GL_SRC_COLOR);
}

//
// dglTexCombColor
//

void dglTexCombColor(int t, rcolor c, int func) {
float f[4];
#ifdef LOG_GLFUNC_CALLS
I_Printf("dglTexCombColor(t=0x%x, c=0x%x)\n", t, c);
#endif
dglGetColorf(c, f);
GL_SetTextureMode(GL_COMBINE_ARB);
GL_SetEnvColor(f);
GL_SetCombineState(func);
GL_SetCombineSourceRGB(0, t);
GL_SetCombineOperandRGB(0, GL_SRC_COLOR);
GL_SetCombineSourceRGB(1, GL_CONSTANT);
GL_SetCombineOperandRGB(1, GL_SRC_COLOR);
}

//
// dglTexCombColorf
//

void dglTexCombColorf(int t, float* f, int func) {
#ifdef LOG_GLFUNC_CALLS
I_Printf("dglTexCombColorf(t=0x%x, f=%p)\n", t, f);
#endif
GL_SetTextureMode(GL_COMBINE_ARB);
GL_SetEnvColor(f);
GL_SetCombineState(func);
GL_SetCombineSourceRGB(0, t);
GL_SetCombineOperandRGB(0, GL_SRC_COLOR);
GL_SetCombineSourceRGB(1, GL_CONSTANT);
GL_SetCombineOperandRGB(1, GL_SRC_COLOR);
}

//
// dglTexCombModulate
//

void dglTexCombModulate(int t, int s) {
#ifdef LOG_GLFUNC_CALLS
I_Printf("dglTexCombFinalize(t=0x%x)\n", t);
#endif
GL_SetTextureMode(GL_COMBINE_ARB);
GL_SetCombineState(GL_MODULATE);
GL_SetCombineSourceRGB(0, t);
GL_SetCombineOperandRGB(0, GL_SRC_COLOR);
GL_SetCombineSourceRGB(1, s);
GL_SetCombineOperandRGB(1, GL_SRC_COLOR);
}

//
// dglTexCombAdd
//

void dglTexCombAdd(int t, int s) {
#ifdef LOG_GLFUNC_CALLS
I_Printf("dglTexCombFinalize(t=0x%x)\n", t);
#endif
GL_SetTextureMode(GL_COMBINE_ARB);
GL_SetCombineState(GL_ADD);
GL_SetCombineSourceRGB(0, t);
GL_SetCombineOperandRGB(0, GL_SRC_COLOR);
GL_SetCombineSourceRGB(1, s);
GL_SetCombineOperandRGB(1, GL_SRC_COLOR);
}

//
// dglTexCombInterpolate
//

void dglTexCombInterpolate(int t, float a) {
float f[4];
#ifdef LOG_GLFUNC_CALLS
I_Printf("dglTexCombInterpolate(t=0x%x, a=%f)\n", t, a);
#endif
f[0] = f[1] = f[2] = 0.0f;
f[3] = a;

GL_SetTextureMode(GL_COMBINE_ARB);
GL_SetCombineState(GL_INTERPOLATE);
GL_SetEnvColor(f);
GL_SetCombineSourceRGB(0, GL_TEXTURE);
GL_SetCombineOperandRGB(0, GL_SRC_COLOR);
GL_SetCombineSourceRGB(1, t);
GL_SetCombineOperandRGB(1, GL_SRC_COLOR);
GL_SetCombineSourceRGB(2, GL_CONSTANT);
GL_SetCombineOperandRGB(2, GL_SRC_ALPHA);
}

//
// dglTexCombReplaceAlpha
//

void dglTexCombReplaceAlpha(int t) {
#ifdef LOG_GLFUNC_CALLS
I_Printf("dglTexCombReplaceAlpha(t=0x%x)\n", t);
#endif
GL_SetTextureMode(GL_COMBINE_ARB);
GL_SetCombineStateAlpha(GL_MODULATE);
GL_SetCombineSourceAlpha(0, t);
GL_SetCombineOperandAlpha(0, GL_SRC_ALPHA);
GL_SetCombineSourceAlpha(1, GL_PRIMARY_COLOR);
GL_SetCombineOperandAlpha(1, GL_SRC_ALPHA);
}
14 changes: 14 additions & 0 deletions src/engine/gl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,21 @@ int Draw_Text(int x, int y, rcolor color, float scale,
char msg[MAX_MESSAGE_SIZE];
va_list va;
const int ix = x;
boolean fill = false;

va_start(va, string);
vsprintf(msg, string, va);
va_end(va);

GL_SetState(GLSTATE_BLEND, 1);

if(!r_fillmode.value) {
dglEnable(GL_TEXTURE_2D);
dglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
r_fillmode.value = 1.0f;
fill = true;
}

GL_BindGfxTexture("SFONT", true);

dglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, DGL_CLAMP);
Expand Down Expand Up @@ -214,6 +222,12 @@ int Draw_Text(int x, int y, rcolor color, float scale,

GL_ResetViewport();

if(fill) {
dglDisable(GL_TEXTURE_2D);
dglPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
r_fillmode.value = 0.0f;
}

GL_SetState(GLSTATE_BLEND, 0);
GL_SetOrthoScale(1.0f);

Expand Down
Loading

0 comments on commit aa6fcb9

Please sign in to comment.