{
rtexture_t *texture;
int drawflag;
+ qboolean hasalpha;
unsigned short elements[3];
}vmpolygons_triangle_t;
float begin_vertex[VMPOLYGONS_MAXPOINTS][3];
float begin_color[VMPOLYGONS_MAXPOINTS][4];
float begin_texcoord[VMPOLYGONS_MAXPOINTS][2];
+ qboolean begin_texture_hasalpha;
} vmpolygons_t;
// FIXME: make VM_CL_R_Polygon functions use Debug_Polygon functions?
int numtriangles = 0;
rtexture_t *tex = polys->data_triangles[surfacelist[surfacelistindex]].texture;
int drawflag = polys->data_triangles[surfacelist[surfacelistindex]].drawflag;
- // this can't call _DrawQ_ProcessDrawFlag, but should be in sync with it
- // FIXME factor this out
- if(drawflag == DRAWFLAG_ADDITIVE)
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
- else if(drawflag == DRAWFLAG_MODULATE)
- GL_BlendFunc(GL_DST_COLOR, GL_ZERO);
- else if(drawflag == DRAWFLAG_2XMODULATE)
- GL_BlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
- else if(drawflag == DRAWFLAG_SCREEN)
- GL_BlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
- else
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ DrawQ_ProcessDrawFlag(drawflag, polys->data_triangles[surfacelist[surfacelistindex]].hasalpha);
R_SetupShader_Generic(tex, NULL, GL_MODULATE, 1);
numtriangles = 0;
for (;surfacelistindex < numsurfaces;surfacelistindex++)
void VMPolygons_Store(vmpolygons_t *polys)
{
+ qboolean hasalpha;
+ int i;
+
+ // detect if we have alpha
+ hasalpha = polys->begin_texture_hasalpha;
+ for(i = 0; !hasalpha && (i < polys->begin_vertices); ++i)
+ if(polys->begin_color[i][3] < 1)
+ hasalpha = true;
+
if (r_refdef.draw2dstage)
{
// draw the polygon as 2D immediately
mesh.data_vertex3f = polys->begin_vertex[0];
mesh.data_color4f = polys->begin_color[0];
mesh.data_texcoord2f = polys->begin_texcoord[0];
- DrawQ_Mesh(&mesh, polys->begin_drawflag);
+ DrawQ_Mesh(&mesh, polys->begin_drawflag, hasalpha);
}
else
{
polys->data_triangles[polys->num_triangles].elements[0] = polys->num_vertices;
polys->data_triangles[polys->num_triangles].elements[1] = polys->num_vertices + i+1;
polys->data_triangles[polys->num_triangles].elements[2] = polys->num_vertices + i+2;
+ polys->data_triangles[polys->num_triangles].hasalpha = hasalpha;
polys->num_triangles++;
}
polys->num_vertices += polys->begin_vertices;
}
polys->begin_texture = (sf && sf->base) ? sf->base : r_texture_white;
+ polys->begin_texture_hasalpha = (sf && sf->base) ? sf->hasalpha : false;
polys->begin_drawflag = (int)PRVM_G_FLOAT(OFS_PARM1) & DRAWFLAG_MASK;
polys->begin_vertices = 0;
polys->begin_active = true;
rtexture_t *tex;
// used for hash lookups
struct cachepic_s *chain;
+ // has alpha?
+ qboolean hasalpha;
// name of pic
char name[MAX_QPATH];
}
// draw a very fancy pic (per corner texcoord/color control), the order is tl, tr, bl, br
void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height, float s1, float t1, float r1, float g1, float b1, float a1, float s2, float t2, float r2, float g2, float b2, float a2, float s3, float t3, float r3, float g3, float b3, float a3, float s4, float t4, float r4, float g4, float b4, float a4, int flags);
// draw a triangle mesh
-void DrawQ_Mesh(drawqueuemesh_t *mesh, int flags);
+void DrawQ_Mesh(drawqueuemesh_t *mesh, int flags, qboolean hasalpha);
// set the clipping area
void DrawQ_SetClipArea(float x, float y, float width, float height);
// reset the clipping area
void DrawQ_LineLoop(drawqueuemesh_t *mesh, int flags);
// resets r_refdef.draw2dstage
void DrawQ_Finish(void);
+void DrawQ_ProcessDrawFlag(int flags, qboolean alpha); // sets GL_DepthMask and GL_BlendFunc
void R_DrawGamma(void);
unsigned char *lmpdata;
char lmpname[MAX_QPATH];
int texflags;
+ int j;
texflags = TEXF_ALPHA;
if (!(cachepicflags & CACHEPICFLAG_NOCLAMP))
return pic;
}
+ pic->hasalpha = true; // assume alpha unless we know it has none
pic->texflags = texflags;
pic->autoload = (cachepicflags & CACHEPICFLAG_NOTPERSISTENT);
pixels = loadimagepixelsbgra(path+4, false, true, r_texture_convertsRGB_2d.integer, NULL);
if (pixels)
{
+ pic->hasalpha = false;
+ if (pic->texflags & TEXF_ALPHA)
+ {
+ for (j = 3;j < image_width * image_height * 4;j += 4)
+ {
+ if (pixels[j] < 255)
+ {
+ pic->hasalpha = true;
+ break;
+ }
+ }
+ }
+
pic->width = image_width;
pic->height = image_height;
if (!pic->autoload)
- pic->tex = R_LoadTexture2D(drawtexturepool, path, image_width, image_height, pixels, TEXTYPE_BGRA, pic->texflags, -1, NULL);
+ pic->tex = R_LoadTexture2D(drawtexturepool, path, image_width, image_height, pixels, TEXTYPE_BGRA, pic->texflags & (pic->hasalpha ? ~0 : ~TEXF_ALPHA), -1, NULL);
}
else
{
R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap, NULL, NULL);
}
-void _DrawQ_Setup(void)
+static void _DrawQ_Setup(void)
{
r_viewport_t viewport;
if (r_refdef.draw2dstage)
GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
R_EntityMatrix(&identitymatrix);
- GL_DepthMask(true);
GL_DepthRange(0, 1);
GL_PolygonOffset(0, 0);
GL_DepthTest(false);
GL_Color(1,1,1,1);
GL_AlphaTest(false);
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
qboolean r_draw2d_force = false;
-static void _DrawQ_ProcessDrawFlag(int flags)
+void _DrawQ_SetupAndProcessDrawFlag(int flags, cachepic_t *pic, float alpha)
{
_DrawQ_Setup();
CHECKGLERROR
if(!r_draw2d.integer && !r_draw2d_force)
return;
+ DrawQ_ProcessDrawFlag(flags, (alpha < 1) || (pic && pic->hasalpha));
+}
+void DrawQ_ProcessDrawFlag(int flags, qboolean alpha)
+{
if(flags == DRAWFLAG_ADDITIVE)
- GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
+ {
+ GL_DepthMask(false);
+ GL_BlendFunc(alpha ? GL_SRC_ALPHA : GL_ONE, GL_ONE);
+ }
else if(flags == DRAWFLAG_MODULATE)
+ {
+ GL_DepthMask(false);
GL_BlendFunc(GL_DST_COLOR, GL_ZERO);
+ }
else if(flags == DRAWFLAG_2XMODULATE)
- GL_BlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
+ {
+ GL_DepthMask(false);
+ GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
+ }
else if(flags == DRAWFLAG_SCREEN)
- GL_BlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
- else
+ {
+ GL_DepthMask(false);
+ GL_BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
+ }
+ else if(alpha)
+ {
+ GL_DepthMask(false);
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ else
+ {
+ GL_DepthMask(true);
+ GL_BlendFunc(GL_ONE, GL_ZERO);
+ }
}
void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, float red, float green, float blue, float alpha, int flags)
{
float floats[20];
- _DrawQ_ProcessDrawFlag(flags);
+ _DrawQ_SetupAndProcessDrawFlag(flags, pic, alpha);
if(!r_draw2d.integer && !r_draw2d_force)
return;
float sinar = sin(ar);
float cosar = cos(ar);
- _DrawQ_ProcessDrawFlag(flags);
+ _DrawQ_SetupAndProcessDrawFlag(flags, pic, alpha);
if(!r_draw2d.integer && !r_draw2d_force)
return;
{
float floats[12];
- _DrawQ_ProcessDrawFlag(flags);
+ _DrawQ_SetupAndProcessDrawFlag(flags, NULL, alpha);
if(!r_draw2d.integer && !r_draw2d_force)
return;
if (maxlen < 1)
maxlen = 1<<30;
- _DrawQ_ProcessDrawFlag(flags);
+ _DrawQ_SetupAndProcessDrawFlag(flags, NULL, 0);
if(!r_draw2d.integer && !r_draw2d_force)
return startx + DrawQ_TextWidth_UntilWidth_TrackColors_Scale(text, &maxlen, w, h, sw, sh, NULL, ignorecolorcodes, fnt, 1000000000);
{
float floats[36];
- _DrawQ_ProcessDrawFlag(flags);
+ _DrawQ_SetupAndProcessDrawFlag(flags, pic, a1*a2*a3*a4);
if(!r_draw2d.integer && !r_draw2d_force)
return;
R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, polygonelement3s, 0, 0);
}
-void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags)
+void DrawQ_Mesh (drawqueuemesh_t *mesh, int flags, qboolean hasalpha)
{
- _DrawQ_ProcessDrawFlag(flags);
+ _DrawQ_Setup();
+ CHECKGLERROR
if(!r_draw2d.integer && !r_draw2d_force)
return;
+ DrawQ_ProcessDrawFlag(flags, hasalpha);
R_Mesh_VertexPointer(mesh->data_vertex3f, 0, 0);
R_Mesh_ColorPointer(mesh->data_color4f, 0, 0);
{
int num;
- _DrawQ_ProcessDrawFlag(flags);
+ _DrawQ_SetupAndProcessDrawFlag(flags, NULL, 1);
if(!r_draw2d.integer && !r_draw2d_force)
return;
//[515]: this is old, delete
void DrawQ_Line (float width, float x1, float y1, float x2, float y2, float r, float g, float b, float alpha, int flags)
{
- _DrawQ_ProcessDrawFlag(flags);
+ _DrawQ_SetupAndProcessDrawFlag(flags, NULL, alpha);
if(!r_draw2d.integer && !r_draw2d_force)
return;