Browse Source

ref_soft: Fix alpha blending, optimize blitting

pull/2/head
mittorn 6 years ago
parent
commit
ce27aad67b
  1. 10
      r_draw.c
  2. 22
      r_glblit.c
  3. 4
      r_local.h
  4. 9
      r_triapi.c

10
r_draw.c

@ -130,6 +130,7 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1, @@ -130,6 +130,7 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1,
{
pixel_t src = source[f>>16];
int alpha = vid.alpha;
f += fstep;
if( pic->transparent )
{
@ -137,8 +138,11 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1, @@ -137,8 +138,11 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1,
src = src << 3;
}
if( alpha == 0 )
continue;
if( vid.color != COLOR_WHITE )
src = vid.modmap[src & 0xff00|(vid.color>>8)] << 8 | (src & vid.color & 0xff) | ((src & 0xff) >> 1);
src = vid.modmap[src & 0xff00|(vid.color>>8)] << 8 | (src & vid.color & 0xff) | ((src & 0xff) >> 3);
if( vid.rendermode == kRenderTransAdd)
{
@ -148,12 +152,12 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1, @@ -148,12 +152,12 @@ void R_DrawStretchPicImplementation (int x, int y, int w, int h, int s1, int t1,
else if( alpha < 7) // && (vid.rendermode == kRenderTransAlpha || vid.rendermode == kRenderTransTexture ) )
{
pixel_t screen = dest[u];
dest[u] = vid.alphamap[(vid.alpha << 16)|(src & 0xff00)|(screen>>8)] << 8 | (screen & 0xff) | ((src & 0xff) >> 1);
dest[u] = vid.alphamap[( alpha << 16)|(src & 0xff00)|(screen>>8)] << 8 | (screen & 0xff) >> 3 | ((src & 0xff) >> 3);
}
else
dest[u] = src;
f += fstep;
}
#endif
}

22
r_glblit.c

@ -34,7 +34,6 @@ static void APIENTRY GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLui @@ -34,7 +34,6 @@ static void APIENTRY GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLui
break;
}
}
int tex;
unsigned short *buffer;
#define LOAD(x) p##x = gEngfuncs.GL_GetProcAddress(#x)
@ -76,9 +75,9 @@ void R_BuildScreenMap() @@ -76,9 +75,9 @@ void R_BuildScreenMap()
for( j = 0; j < 256; j++ )
{
// restore minor GBRGBRGB
r = MOVE_BIT(i, 5, 1) | MOVE_BIT(i, 2, 0);
g = MOVE_BIT(i, 7, 2) | MOVE_BIT(i, 4, 1) | MOVE_BIT(i, 1, 0);
b = MOVE_BIT(i, 6, 2) | MOVE_BIT(i, 3, 1) | MOVE_BIT(i, 0, 0);
r = MOVE_BIT(j, 5, 1) | MOVE_BIT(j, 2, 0);
g = MOVE_BIT(j, 7, 2) | MOVE_BIT(j, 4, 1) | MOVE_BIT(j, 1, 0);
b = MOVE_BIT(j, 6, 2) | MOVE_BIT(j, 3, 1) | MOVE_BIT(j, 0, 0);
vid.screen[(i<<8)|j] = r << (6 + 5) | (g << 5) | b | major;
}
@ -116,13 +115,15 @@ void R_BuildBlendMaps() @@ -116,13 +115,15 @@ void R_BuildBlendMaps()
r = r1 * r2 / MASK(2);
g = g1 * g2 / MASK(2);
b = b1 * b2 / MASK(1);
vid.modmap[index2|index1] = r << (2 + 3) | g << 2 | b;
for( a = 0; a < 8; a++ )
{
r = r1 * a / 7 + r2 * (7 - a) / 7;
g = g1 * a / 7 + g2 * (7 - a) / 7;
b = b1 * a / 7 + b2 * (7 - a) / 7;
r = r1 * (7 - a) / 7 + r2 * a / 7;
g = g1 * (7 - a) / 7 + g2 * a / 7;
b = b1 * (7 - a) / 7 + b2 * a / 7;
//if( b == 1 ) b = 0;
vid.alphamap[a << 16|index2|index1] = r << (2 + 3) | g << 2 | b;
}
@ -162,8 +163,6 @@ void R_InitBlit() @@ -162,8 +163,6 @@ void R_InitBlit()
// enable all the low priority messages
pglDebugMessageControlARB( GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW_ARB, 0, NULL, true );
#endif
pglGenTextures( 1, &tex );
buffer = Mem_Malloc( r_temppool, 1920*1080*2 );
@ -191,7 +190,6 @@ void R_BlitScreen() @@ -191,7 +190,6 @@ void R_BlitScreen()
#endif
}
pglBindTexture(GL_TEXTURE_2D, tex);
pglViewport( 0, 0, gpGlobals->width, gpGlobals->height );
pglMatrixMode( GL_PROJECTION );
pglLoadIdentity();
@ -200,12 +198,8 @@ void R_BlitScreen() @@ -200,12 +198,8 @@ void R_BlitScreen()
pglLoadIdentity();
pglEnable( GL_TEXTURE_2D );
pglBindTexture(GL_TEXTURE_2D, tex);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//gEngfuncs.Con_Printf("%d\n",pglGetError());
pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vid.width, vid.height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, buffer );
//gEngfuncs.Con_Printf("%d\n",pglGetError());

4
r_local.h

@ -125,7 +125,7 @@ typedef struct vrect_s @@ -125,7 +125,7 @@ typedef struct vrect_s
} vrect_t;
#define COLOR_WHITE 0xFFFF
#define SEPARATE_BLIT
//#define SEPARATE_BLIT
typedef struct
{
pixel_t *buffer; // invisible buffer
@ -139,7 +139,7 @@ typedef struct @@ -139,7 +139,7 @@ typedef struct
#endif
byte addmap[256*256];
byte modmap[256*256];
pixel_t alphamap[8*256*256];
byte alphamap[8*256*256];
pixel_t color;
byte alpha;

9
r_triapi.c

@ -135,6 +135,12 @@ void _TriColor4f( float rr, float gg, float bb, float aa ) @@ -135,6 +135,12 @@ void _TriColor4f( float rr, float gg, float bb, float aa )
//pglColor4f( r, g, b, a );
unsigned short r,g,b;
vid.alpha = aa * 7;
if( vid.alpha > 7 )
vid.alpha = 7;
//gEngfuncs.Con_Printf("%d\n", vid.alpha);
if( rr == 1 && gg == 1 && bb == 1 )
{
vid.color = COLOR_WHITE;
@ -143,9 +149,6 @@ void _TriColor4f( float rr, float gg, float bb, float aa ) @@ -143,9 +149,6 @@ void _TriColor4f( float rr, float gg, float bb, float aa )
r = rr * 31, g = gg * 63, b = bb * 31;
vid.alpha = aa * 7;
if( vid.alpha > 7 )
vid.alpha = 7;
unsigned int major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2)));

Loading…
Cancel
Save