void CG_GetTeamColor(vector4 *color) { if (cg.snap->ps.persistent[PERS_TEAM] == TEAM_RED) VectorSet4( color, 1.0f, 0.0f, 0.0f, 0.25f ); else if (cg.snap->ps.persistent[PERS_TEAM] == TEAM_BLUE) VectorSet4( color, 0.0f, 0.0f, 1.0f, 0.25f ); else VectorSet4( color, 0.0f, 0.17f, 0.0f, 0.25f ); }
void RB_ToneMap(FBO_t *hdrFbo, int autoExposure) { vec4i_t srcBox, dstBox; vec4_t color; static int lastFrameCount = 0; if (autoExposure) { if (lastFrameCount == 0 || tr.frameCount < lastFrameCount || tr.frameCount - lastFrameCount > 5) { // determine average log luminance FBO_t *srcFbo, *dstFbo, *tmp; int size = 256; lastFrameCount = tr.frameCount; VectorSet4(dstBox, 0, 0, size, size); srcFbo = hdrFbo; dstFbo = tr.textureScratchFbo[0]; FBO_Blit(srcFbo, NULL, NULL, dstFbo, dstBox, &tr.calclevels4xShader[0], NULL, 0); srcFbo = tr.textureScratchFbo[0]; dstFbo = tr.textureScratchFbo[1]; // downscale to 1x1 texture while (size > 1) { VectorSet4(srcBox, 0, 0, size, size); //size >>= 2; size >>= 1; VectorSet4(dstBox, 0, 0, size, size); if (size == 1) dstFbo = tr.targetLevelsFbo; //FBO_Blit(targetFbo, srcBox, NULL, tr.textureScratchFbo[nextScratch], dstBox, &tr.calclevels4xShader[1], NULL, 0); FBO_FastBlit(srcFbo, srcBox, dstFbo, dstBox, GL_COLOR_BUFFER_BIT, GL_LINEAR); tmp = srcFbo; srcFbo = dstFbo; dstFbo = tmp; } } // blend with old log luminance for gradual change VectorSet4(srcBox, 0, 0, 0, 0); color[0] = color[1] = color[2] = 1.0f; if (glRefConfig.textureFloat) color[3] = 0.03f; else color[3] = 0.1f; FBO_Blit(tr.targetLevelsFbo, srcBox, NULL, tr.calcLevelsFbo, NULL, NULL, color, GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA); }
/* =============== RB_ShowImages Draw all the images to the screen, on top of whatever was there. This is used to test for texture thrashing. Also called by RE_EndRegistration =============== */ void RB_ShowImages( void ) { int i; image_t *image; float x, y, w, h; int start, end; RB_SetGL2D(); qglClear( GL_COLOR_BUFFER_BIT ); qglFinish(); start = ri.Milliseconds(); for ( i=0 ; i<tr.numImages ; i++ ) { image = tr.images[i]; w = glConfig.vidWidth / 20; h = glConfig.vidHeight / 15; x = i % 20 * w; y = i / 20 * h; // show in proportional size in mode 2 if ( r_showImages->integer == 2 ) { w *= image->uploadWidth / 512.0f; h *= image->uploadHeight / 512.0f; } { vec4_t quadVerts[4]; GL_Bind(image); VectorSet4(quadVerts[0], x, y, 0, 1); VectorSet4(quadVerts[1], x + w, y, 0, 1); VectorSet4(quadVerts[2], x + w, y + h, 0, 1); VectorSet4(quadVerts[3], x, y + h, 0, 1); RB_InstantQuad(quadVerts); } } qglFinish(); end = ri.Milliseconds(); ri.Printf( PRINT_ALL, "%i msec to draw all images\n", end - start ); }
/* ================ CG_FadeColor ================ */ vector4 *CG_FadeColor( int startMsec, int totalMsec ) { static vector4 color; int t; int fadeTime = 500;//FADE_TIME; if ( startMsec == 0 ) { return NULL; } t = cg.time - startMsec; if ( t >= totalMsec ) { return NULL; } //Raz: This colour shouldn't be visible yet if ( t < 0 ) return NULL; // fade out VectorSet4( &color, 1.0f, 1.0f, 1.0f, 1.0f ); if ( totalMsec - t < fadeTime ) color.a = (totalMsec - t) * 1.0f / fadeTime; return &color; }
void FBO_Blit(FBO_t *src, ivec4_t inSrcBox, vec2_t srcTexScale, FBO_t *dst, ivec4_t dstBox, struct shaderProgram_s *shaderProgram, vec4_t color, int blend) { ivec4_t srcBox; if (!src) { ri.Printf(PRINT_WARNING, "Tried to blit from a NULL FBO!\n"); return; } // framebuffers are 0 bottom, Y up. if (inSrcBox) { srcBox[0] = inSrcBox[0]; srcBox[1] = src->height - inSrcBox[1] - inSrcBox[3]; srcBox[2] = inSrcBox[2]; srcBox[3] = inSrcBox[3]; } else { VectorSet4(srcBox, 0, src->height, src->width, -src->height); } FBO_BlitFromTexture(src->colorImage[0], srcBox, srcTexScale, dst, dstBox, shaderProgram, color, blend | GLS_DEPTHTEST_DISABLE); }
/* ================ DrawTris Draws triangle outlines for debugging ================ */ static void DrawTris (shaderCommands_t *input) { GL_Bind( tr.whiteImage ); GL_State( GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE ); qglDepthRange( 0, 0 ); { shaderProgram_t *sp = &tr.textureColorShader; vec4_t color; GLSL_VertexAttribsState(ATTR_POSITION); GLSL_BindProgram(sp); GLSL_SetUniformMatrix16(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); VectorSet4(color, 1, 1, 1, 1); GLSL_SetUniformVec4(sp, UNIFORM_COLOR, color); if (input->multiDrawPrimitives) { R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex); } else { R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex); } } qglDepthRange( 0, 1 ); }
void FBO_FastBlit(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, int buffers, int filter) { ivec4_t srcBoxFinal, dstBoxFinal; GLuint srcFb, dstFb; if (!glRefConfig.framebufferBlit) { FBO_Blit(src, srcBox, NULL, dst, dstBox, NULL, NULL, 0); return; } srcFb = src ? src->frameBuffer : 0; dstFb = dst ? dst->frameBuffer : 0; if (!srcBox) { int width = src ? src->width : glConfig.vidWidth; int height = src ? src->height : glConfig.vidHeight; VectorSet4(srcBoxFinal, 0, 0, width, height); } else { VectorSet4(srcBoxFinal, srcBox[0], srcBox[1], srcBox[0] + srcBox[2], srcBox[1] + srcBox[3]); } if (!dstBox) { int width = dst ? dst->width : glConfig.vidWidth; int height = dst ? dst->height : glConfig.vidHeight; VectorSet4(dstBoxFinal, 0, 0, width, height); } else { VectorSet4(dstBoxFinal, dstBox[0], dstBox[1], dstBox[0] + dstBox[2], dstBox[1] + dstBox[3]); } GL_BindFramebuffer(GL_READ_FRAMEBUFFER, srcFb); GL_BindFramebuffer(GL_DRAW_FRAMEBUFFER, dstFb); qglBlitFramebuffer(srcBoxFinal[0], srcBoxFinal[1], srcBoxFinal[2], srcBoxFinal[3], dstBoxFinal[0], dstBoxFinal[1], dstBoxFinal[2], dstBoxFinal[3], buffers, filter); GL_BindFramebuffer(GL_FRAMEBUFFER, 0); glState.currentFBO = NULL; }
void FBO_FastBlit(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, int buffers, int filter) { ivec4_t srcBoxFinal, dstBoxFinal; GLuint srcFb, dstFb; if (!glRefConfig.framebufferBlit) { FBO_Blit(src, srcBox, NULL, dst, dstBox, NULL, NULL, 0); return; } // get to a neutral state first //FBO_Bind(NULL); srcFb = src ? src->frameBuffer : 0; dstFb = dst ? dst->frameBuffer : 0; if (!srcBox) { if (src) { VectorSet4(srcBoxFinal, 0, 0, src->width, src->height); } else { VectorSet4(srcBoxFinal, 0, 0, glConfig.vidWidth, glConfig.vidHeight); } } else { VectorSet4(srcBoxFinal, srcBox[0], srcBox[1], srcBox[0] + srcBox[2], srcBox[1] + srcBox[3]); } if (!dstBox) { if (dst) { VectorSet4(dstBoxFinal, 0, 0, dst->width, dst->height); } else { VectorSet4(dstBoxFinal, 0, 0, glConfig.vidWidth, glConfig.vidHeight); } } else { VectorSet4(dstBoxFinal, dstBox[0], dstBox[1], dstBox[0] + dstBox[2], dstBox[1] + dstBox[3]); } qglBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, srcFb); qglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, dstFb); qglBlitFramebufferEXT(srcBoxFinal[0], srcBoxFinal[1], srcBoxFinal[2], srcBoxFinal[3], dstBoxFinal[0], dstBoxFinal[1], dstBoxFinal[2], dstBoxFinal[3], buffers, filter); qglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glState.currentFBO = NULL; }
// Draws a multi-colored string with a drop shadow, optionally forcing to a fixed color. // Coordinates are 640x480 virtual values void SCR_DrawStringExt( int x, int y, float size, const char *string, const vector4 *setColor, qboolean forceColor, qboolean noColorEscape ) { vector4 color; const char *s; int xx; // draw the drop shadow VectorSet4( &color, 0.0f, 0.0f, 0.0f, setColor->a ); re->SetColor( &color ); s = string; xx = x; while ( *s ) { if ( !noColorEscape && Q_IsColorString( s ) ) { s += 2; continue; } SCR_DrawChar( xx+2, y+2, size, *s ); xx += (int)size; s++; } // draw the colored text s = string; xx = x; re->SetColor( setColor ); while ( *s ) { if ( Q_IsColorString( s ) ) { if ( !forceColor ) { memcpy( &color, &g_color_table[ColorIndex(*(s+1))], sizeof( color ) ); color.a = setColor->a; re->SetColor( &color ); } if ( !noColorEscape ) { s += 2; continue; } } SCR_DrawChar( xx, y, size, *s ); xx += (int)size; s++; } re->SetColor( NULL ); }
void FBO_Blit(FBO_t *src, vec4i_t inSrcBox, vec2_t srcTexScale, FBO_t *dst, vec4i_t dstBox, struct shaderProgram_s *shaderProgram, vec4_t color, int blend) { vec4i_t srcBox; if (!src) return; // framebuffers are 0 bottom, Y up. if (inSrcBox) { srcBox[0] = inSrcBox[0]; srcBox[1] = src->height - inSrcBox[1] - inSrcBox[3]; srcBox[2] = inSrcBox[2]; srcBox[3] = inSrcBox[3]; } else { VectorSet4(srcBox, 0, src->height, src->width, -src->height); } FBO_BlitFromTexture(src->colorImage[0], srcBox, srcTexScale, dst, dstBox, shaderProgram, color, blend | GLS_DEPTHTEST_DISABLE); }
void FBO_Blit(FBO_t *src, ivec4_t inSrcBox, vec2_t srcTexScale, FBO_t *dst, ivec4_t dstBox, struct shaderProgram_s *shaderProgram, vec4_t color, int blend) { vec4_t srcTexCorners; if (!src) { ri.Printf(PRINT_WARNING, "Tried to blit from a NULL FBO!\n"); return; } if (inSrcBox) { srcTexCorners[0] = inSrcBox[0] / (float)src->width; srcTexCorners[1] = (inSrcBox[1] + inSrcBox[3]) / (float)src->height; srcTexCorners[2] = (inSrcBox[0] + inSrcBox[2]) / (float)src->width; srcTexCorners[3] = inSrcBox[1] / (float)src->height; } else { VectorSet4(srcTexCorners, 0.0f, 0.0f, 1.0f, 1.0f); } FBO_BlitFromTexture(src->colorImage[0], srcTexCorners, srcTexScale, dst, dstBox, shaderProgram, color, blend | GLS_DEPTHTEST_DISABLE); }
static void RB_IterateStagesGeneric( shaderCommands_t *input ) { int stage; matrix_t matrix; vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0}; float eyeT = 0; int deformGen; vec5_t deformParams; ComputeDeformValues(&deformGen, deformParams); ComputeFogValues(fogDistanceVector, fogDepthVector, &eyeT); for ( stage = 0; stage < MAX_SHADER_STAGES; stage++ ) { shaderStage_t *pStage = input->xstages[stage]; shaderProgram_t *sp; if ( !pStage ) { break; } if (backEnd.depthFill) { if (pStage->glslShaderGroup) { int index = 0; if (backEnd.currentEntity && backEnd.currentEntity != &tr.worldEntity) { index |= LIGHTDEF_ENTITY; } if (pStage->stateBits & GLS_ATEST_BITS) { index |= LIGHTDEF_USE_TCGEN_AND_TCMOD; } sp = &pStage->glslShaderGroup[index]; } else { int shaderAttribs = 0; if (tess.shader->numDeforms && !ShaderRequiresCPUDeforms(tess.shader)) { shaderAttribs |= GENERICDEF_USE_DEFORM_VERTEXES; } if (glState.vertexAttribsInterpolation > 0.0f && backEnd.currentEntity && backEnd.currentEntity != &tr.worldEntity) { shaderAttribs |= GENERICDEF_USE_VERTEX_ANIMATION; } if (pStage->stateBits & GLS_ATEST_BITS) { shaderAttribs |= GENERICDEF_USE_TCGEN_AND_TCMOD; } sp = &tr.genericShader[shaderAttribs]; } } else if (pStage->glslShaderGroup) { int index = pStage->glslShaderIndex; if (backEnd.currentEntity && backEnd.currentEntity != &tr.worldEntity) { index |= LIGHTDEF_ENTITY; } if (r_lightmap->integer && index & LIGHTDEF_USE_LIGHTMAP) { index = LIGHTDEF_USE_LIGHTMAP; } sp = &pStage->glslShaderGroup[index]; if (pStage->glslShaderGroup == tr.lightallShader) { backEnd.pc.c_lightallDraws++; } } else { sp = GLSL_GetGenericShaderProgram(stage); backEnd.pc.c_genericDraws++; } GLSL_BindProgram(sp); GLSL_SetUniformMatrix16(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin); GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation); GLSL_SetUniformInt(sp, UNIFORM_DEFORMGEN, deformGen); if (deformGen != DGEN_NONE) { GLSL_SetUniformFloat5(sp, UNIFORM_DEFORMPARAMS, deformParams); GLSL_SetUniformFloat(sp, UNIFORM_TIME, tess.shaderTime); } if ( input->fogNum ) { GLSL_SetUniformVec4(sp, UNIFORM_FOGDISTANCE, fogDistanceVector); GLSL_SetUniformVec4(sp, UNIFORM_FOGDEPTH, fogDepthVector); GLSL_SetUniformFloat(sp, UNIFORM_FOGEYET, eyeT); } GL_State( pStage->stateBits ); { vec4_t baseColor; vec4_t vertColor; qboolean tint = qtrue; int stage2; ComputeShaderColors(pStage, baseColor, vertColor); for ( stage2 = stage + 1; stage2 < MAX_SHADER_STAGES; stage2++ ) { shaderStage_t *pStage2 = input->xstages[stage2]; unsigned int srcBlendBits; //unsigned int dstBlendBits; if ( !pStage2 ) { break; } srcBlendBits = pStage2->stateBits & GLS_SRCBLEND_BITS; //dstBlendBits = pStage2->stateBits & GLS_DSTBLEND_BITS; if (srcBlendBits == GLS_SRCBLEND_DST_COLOR) { tint = qfalse; break; } } if (!((tr.sunShadows || r_forceSun->integer) && tess.shader->sort <= SS_OPAQUE && !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY) ) && tess.xstages[0]->glslShaderGroup == tr.lightallShader)) { tint = qfalse; } if (tint) { // use VectorScale to only scale first three values, not alpha VectorScale(baseColor, backEnd.refdef.colorScale, baseColor); VectorScale(vertColor, backEnd.refdef.colorScale, vertColor); } GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, baseColor); GLSL_SetUniformVec4(sp, UNIFORM_VERTCOLOR, vertColor); } if (pStage->rgbGen == CGEN_LIGHTING_DIFFUSE) { vec4_t vec; VectorScale(backEnd.currentEntity->ambientLight, 1.0f / 255.0f, vec); GLSL_SetUniformVec3(sp, UNIFORM_AMBIENTLIGHT, vec); VectorScale(backEnd.currentEntity->directedLight, 1.0f / 255.0f, vec); GLSL_SetUniformVec3(sp, UNIFORM_DIRECTEDLIGHT, vec); VectorCopy(backEnd.currentEntity->lightDir, vec); vec[3] = 0.0f; GLSL_SetUniformVec4(sp, UNIFORM_LIGHTORIGIN, vec); GLSL_SetUniformFloat(sp, UNIFORM_LIGHTRADIUS, 999999.0f); } if (pStage->alphaGen == AGEN_PORTAL) { GLSL_SetUniformFloat(sp, UNIFORM_PORTALRANGE, tess.shader->portalRange); } GLSL_SetUniformInt(sp, UNIFORM_COLORGEN, pStage->rgbGen); GLSL_SetUniformInt(sp, UNIFORM_ALPHAGEN, pStage->alphaGen); if ( input->fogNum ) { vec4_t fogColorMask; ComputeFogColorMask(pStage, fogColorMask); GLSL_SetUniformVec4(sp, UNIFORM_FOGCOLORMASK, fogColorMask); } ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix ); { vec4_t vector; VectorSet4(vector, matrix[0], matrix[1], matrix[4], matrix[5]); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, vector); VectorSet4(vector, matrix[8], matrix[9], matrix[12], matrix[13]); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, vector); } GLSL_SetUniformInt(sp, UNIFORM_TCGEN0, pStage->bundle[0].tcGen); if (pStage->bundle[0].tcGen == TCGEN_VECTOR) { vec3_t vec; VectorCopy(pStage->bundle[0].tcGenVectors[0], vec); GLSL_SetUniformVec3(sp, UNIFORM_TCGEN0VECTOR0, vec); VectorCopy(pStage->bundle[0].tcGenVectors[1], vec); GLSL_SetUniformVec3(sp, UNIFORM_TCGEN0VECTOR1, vec); } GLSL_SetUniformMatrix16(sp, UNIFORM_MODELMATRIX, backEnd.or.transformMatrix); GLSL_SetUniformVec2(sp, UNIFORM_MATERIALINFO, pStage->materialInfo); //GLSL_SetUniformFloat(sp, UNIFORM_MAPLIGHTSCALE, backEnd.refdef.mapLightScale); // // do multitexture // if ( backEnd.depthFill ) { if (!(pStage->stateBits & GLS_ATEST_BITS)) GL_BindToTMU( tr.whiteImage, 0 ); else if ( pStage->bundle[TB_COLORMAP].image[0] != 0 ) R_BindAnimatedImageToTMU( &pStage->bundle[TB_COLORMAP], TB_COLORMAP ); } else if ( pStage->glslShaderGroup ) { int i; if ((r_lightmap->integer == 1 || r_lightmap->integer == 2) && pStage->bundle[TB_LIGHTMAP].image[0]) { for (i = 0; i < NUM_TEXTURE_BUNDLES; i++) { if (i == TB_LIGHTMAP) { R_BindAnimatedImageToTMU( &pStage->bundle[i], i); } else if (pStage->bundle[i].image[0]) { GL_BindToTMU( tr.whiteImage, i); } } } else if (r_lightmap->integer == 3 && pStage->bundle[TB_DELUXEMAP].image[0]) { for (i = 0; i < NUM_TEXTURE_BUNDLES; i++) { if (i == TB_LIGHTMAP) { R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i); } else if (pStage->bundle[i].image[0]) { GL_BindToTMU( tr.whiteImage, i); } } } else { for (i = 0; i < NUM_TEXTURE_BUNDLES; i++) { if (pStage->bundle[i].image[0]) { R_BindAnimatedImageToTMU( &pStage->bundle[i], i); } } } } else if ( pStage->bundle[1].image[0] != 0 ) { R_BindAnimatedImageToTMU( &pStage->bundle[0], 0 ); // // lightmap/secondary pass // if ( r_lightmap->integer ) { GLSL_SetUniformInt(sp, UNIFORM_TEXTURE1ENV, GL_REPLACE); } else { GLSL_SetUniformInt(sp, UNIFORM_TEXTURE1ENV, tess.shader->multitextureEnv); } R_BindAnimatedImageToTMU( &pStage->bundle[1], 1 ); } else { // // set state // if ( pStage->bundle[0].vertexLightmap && ( (r_vertexLight->integer && !r_uiFullScreen->integer) || glConfig.hardwareType == GLHW_PERMEDIA2 ) && r_lightmap->integer ) { GL_BindToTMU( tr.whiteImage, 0 ); } else R_BindAnimatedImageToTMU( &pStage->bundle[0], 0 ); GLSL_SetUniformInt(sp, UNIFORM_TEXTURE1ENV, 0); } // // draw // if (input->multiDrawPrimitives) { R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex); } else { R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex); } // allow skipping out to show just lightmaps during development if ( r_lightmap->integer && ( pStage->bundle[0].isLightmap || pStage->bundle[1].isLightmap || pStage->bundle[0].vertexLightmap ) ) { break; } if (backEnd.depthFill) break; } }
void UIFakkLabel::Draw( void ) { if( m_stat == -1 && m_itemindex == -1 && m_inventoryrendermodelindex == -1 ) { if( m_stat_configstring != -1 ) { m_font->setColor( m_foreground_color ); m_font->PrintJustified( getClientFrame(), m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString( va( "%s", CL_ConfigString( cl.snap.ps.stats[ m_stat_configstring ] ) ) ), m_bVirtual ? m_vVirtualScale : NULL ); return; } if( !m_rendermodel && m_statbar_or == L_STATBAR_NONE && !m_sDrawModelName.length() ) { UILabel::Draw(); return; } } if( m_stat_configstring != -1 ) { m_font->setColor( m_foreground_color ); m_font->PrintJustified( getClientFrame(), m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString( va( "%s", CL_ConfigString( cl.snap.ps.stats[ m_stat_configstring ] ) ) ), m_bVirtual ? m_vVirtualScale : NULL ); return; } if( m_stat != -1 ) { float scale; qhandle_t handle; vec3_t origin; vec3_t mins; vec3_t maxs; vec3_t angles; vec3_t offset; vec3_t rotateoffset; vec3_t color; str sAnimName; float height; if( m_itemindex != -1 ) { if( m_itemindex < 0 ) return; m_font->setColor( m_foreground_color ); m_font->PrintJustified( getClientFrame(), m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, Sys_LV_CL_ConvertString( va( "%s", CL_ConfigString( CS_WEAPONS + cl.snap.ps.activeItems[ m_itemindex ] ) ) ), m_bVirtual ? m_vVirtualScale : NULL ); return; } if( m_inventoryrendermodelindex == -1 && !m_sDrawModelName.length() || !m_rendermodel ) { float frac = 0.0; if( m_statbar_or == L_STATBAR_NONE ) return; if( m_cvarname.length() ) { frac = Cvar_VariableValue( m_cvarname ) / ( m_statbar_max - m_statbar_min ); } if( frac > 1.0 ) frac = 1.0; if( frac < 0.0 ) frac = 0.0; DrawStatbar( frac ); return; } VectorSet4( color, 255, 255, 255, 255 ); if( m_rendermodel ) { if( !m_cvarname.length() ) return; handle = re.RegisterModel( Cvar_VariableString( m_cvarname ) ); if( !handle ) return; VectorCopy( m_angles, angles ); VectorCopy( m_rotateoffset, rotateoffset ); VectorCopy( m_offset, offset ); scale = m_scale; sAnimName = m_anim; } else if( m_sDrawModelName.length() ) { if( m_lastitemindex != cl.snap.ps.activeItems[ m_inventoryrendermodelindex ] ) { if( !m_lastitem ) m_lastitem = CL_GetInvItemByName( &client_inv, m_sDrawModelName ); } _shitlabel01: if( !m_lastitem ) return; VectorCopy( m_lastitem->hudprops.rotateoffset, rotateoffset ); VectorCopy( m_lastitem->hudprops.offset, offset ); handle = re.RegisterModel( m_lastitem->hudprops.model ); VectorCopy( m_lastitem->hudprops.angledeltas, angles ); if( m_lastitem->hudprops.move == INV_MOVE_BOB ) { float frac = uid.time / 600.0; angles[ 0 ] += sin( frac ) * m_lastitem->hudprops.angledeltas[ 0 ]; angles[ 1 ] += sin( frac ) * m_lastitem->hudprops.angledeltas[ 1 ]; angles[ 2 ] += sin( frac ) * m_lastitem->hudprops.angledeltas[ 2 ]; } else if( m_lastitem->hudprops.model == INV_MOVE_SPIN ) { float frac = uid.time / 600.0; angles[ 0 ] += frac * m_lastitem->hudprops.angledeltas[ 0 ]; angles[ 1 ] += frac * m_lastitem->hudprops.angledeltas[ 1 ]; angles[ 2 ] += frac * m_lastitem->hudprops.angledeltas[ 2 ]; } if( m_rendermodel ) { VectorSet( mins, -16, -16, 0 ); VectorSet( maxs, 16, 16, 96 ); } else { re.ModelBounds( handle, mins, maxs ); } origin[ 1 ] = ( mins[ 1 ] + maxs[ 1 ] ) * 0.5; origin[ 2 ] = ( mins[ 1 ] + maxs[ 1 ] ) * -0.5; height = maxs[ 2 ] - mins[ 2 ]; if( height < maxs[ 1 ] - mins[ 1 ] ) height = maxs[ 1 ] - mins[ 1 ]; if( height <= maxs[ 0 ] - mins[ 0 ] ) height = maxs[ 0 ] - mins[ 0 ]; origin[ 0 ] = height * scale * 0.5 / 0.268f; CL_Draw3DModel( m_screenframe.pos.x, m_screenframe.pos.y, m_screenframe.size.width, m_screenframe.size.height, handle, origin, rotateoffset, offset, angles, color, sAnimName ); return; } if( m_lastitemindex == cl.snap.ps.activeItems[ m_inventoryrendermodelindex ] ) goto _shitlabel01; if( m_lastitem == CL_GetInvItemByName( &client_inv, CL_ConfigString( CS_WEAPONS + cl.snap.ps.activeItems[ m_inventoryrendermodelindex ] ) ) ) { m_lastitemindex = cl.snap.ps.activeItems[ m_inventoryrendermodelindex ]; goto _shitlabel01; } m_lastitem = CL_GetInvItemByName( &client_inv, CL_ConfigString( CS_WEAPONS + cl.snap.ps.activeItems[ m_inventoryrendermodelindex ] ) ); goto _shitlabel01; } int delta = cl.snap.ps.stats[ m_stat ]; if( m_statbar_or ) { if( m_statbar_or == L_STATBAR_VERTICAL_STAGGER_EVEN || m_statbar_or == L_STATBAR_VERTICAL_STAGGER_ODD ) { int stat; if( m_maxstat < 0 ) { stat = m_statbar_max; } else { stat = cl.snap.ps.stats[ m_maxstat ]; } delta = stat - cl.snap.ps.stats[ m_stat ]; if( delta & 1 ) { if( m_statbar_or == L_STATBAR_VERTICAL_STAGGER_EVEN ) delta--; else delta++; } delta = stat - delta; if( m_maxstat >= 0 || m_statbar_min <= delta ) { if( delta < 0 ) delta = 0; } else { delta = m_statbar_min; } } float frac; if( m_maxstat ) { frac = delta / ( m_statbar_max - m_statbar_min ); } else { frac = delta / cl.snap.ps.stats[ m_maxstat ]; } if( frac > 1.0 ) frac = 1.0; if( frac < 0.0 ) frac = 0.0; DrawStatbar( frac ); return; } m_font->setColor( m_foreground_color ); m_font->PrintJustified( getClientFrame(), m_iFontAlignmentHorizontal, m_iFontAlignmentVertical, va( "%d", delta ), m_bVirtual ? m_vVirtualScale : NULL ); }
static void ForwardDlight( void ) { int l; //vec3_t origin; //float scale; float radius; int deformGen; vec5_t deformParams; vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0}; float eyeT = 0; shaderCommands_t *input = &tess; shaderStage_t *pStage = tess.xstages[0]; if ( !backEnd.refdef.num_dlights ) { return; } ComputeDeformValues(&deformGen, deformParams); ComputeFogValues(fogDistanceVector, fogDepthVector, &eyeT); for ( l = 0 ; l < backEnd.refdef.num_dlights ; l++ ) { dlight_t *dl; shaderProgram_t *sp; vec4_t vector; vec4_t texMatrix; vec4_t texOffTurb; if ( !( tess.dlightBits & ( 1 << l ) ) ) { continue; // this surface definately doesn't have any of this light } dl = &backEnd.refdef.dlights[l]; //VectorCopy( dl->transformed, origin ); radius = dl->radius; //scale = 1.0f / radius; //if (pStage->glslShaderGroup == tr.lightallShader) { int index = pStage->glslShaderIndex; index &= ~LIGHTDEF_LIGHTTYPE_MASK; index |= LIGHTDEF_USE_LIGHT_VECTOR; sp = &tr.lightallShader[index]; } backEnd.pc.c_lightallDraws++; GLSL_BindProgram(sp); GLSL_SetUniformMat4(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin); GLSL_SetUniformVec3(sp, UNIFORM_LOCALVIEWORIGIN, backEnd.or.viewOrigin); GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation); GLSL_SetUniformInt(sp, UNIFORM_DEFORMGEN, deformGen); if (deformGen != DGEN_NONE) { GLSL_SetUniformFloat5(sp, UNIFORM_DEFORMPARAMS, deformParams); GLSL_SetUniformFloat(sp, UNIFORM_TIME, tess.shaderTime); } if ( input->fogNum ) { vec4_t fogColorMask; GLSL_SetUniformVec4(sp, UNIFORM_FOGDISTANCE, fogDistanceVector); GLSL_SetUniformVec4(sp, UNIFORM_FOGDEPTH, fogDepthVector); GLSL_SetUniformFloat(sp, UNIFORM_FOGEYET, eyeT); ComputeFogColorMask(pStage, fogColorMask); GLSL_SetUniformVec4(sp, UNIFORM_FOGCOLORMASK, fogColorMask); } { vec4_t baseColor; vec4_t vertColor; ComputeShaderColors(pStage, baseColor, vertColor, GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE); GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, baseColor); GLSL_SetUniformVec4(sp, UNIFORM_VERTCOLOR, vertColor); } if (pStage->alphaGen == AGEN_PORTAL) { GLSL_SetUniformFloat(sp, UNIFORM_PORTALRANGE, tess.shader->portalRange); } GLSL_SetUniformInt(sp, UNIFORM_COLORGEN, pStage->rgbGen); GLSL_SetUniformInt(sp, UNIFORM_ALPHAGEN, pStage->alphaGen); GLSL_SetUniformVec3(sp, UNIFORM_DIRECTEDLIGHT, dl->color); VectorSet(vector, 0, 0, 0); GLSL_SetUniformVec3(sp, UNIFORM_AMBIENTLIGHT, vector); VectorCopy(dl->origin, vector); vector[3] = 1.0f; GLSL_SetUniformVec4(sp, UNIFORM_LIGHTORIGIN, vector); GLSL_SetUniformFloat(sp, UNIFORM_LIGHTRADIUS, radius); GLSL_SetUniformVec4(sp, UNIFORM_NORMALSCALE, pStage->normalScale); GLSL_SetUniformVec4(sp, UNIFORM_SPECULARSCALE, pStage->specularScale); // include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light // where they aren't rendered GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL ); GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, backEnd.or.transformMatrix); if (pStage->bundle[TB_DIFFUSEMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_DIFFUSEMAP], TB_DIFFUSEMAP); // bind textures that are sampled and used in the glsl shader, and // bind whiteImage to textures that are sampled but zeroed in the glsl shader // // alternatives: // - use the last bound texture // -> costs more to sample a higher res texture then throw out the result // - disable texture sampling in glsl shader with #ifdefs, as before // -> increases the number of shaders that must be compiled // if (pStage->bundle[TB_NORMALMAP].image[0]) { R_BindAnimatedImageToTMU( &pStage->bundle[TB_NORMALMAP], TB_NORMALMAP); } else if (r_normalMapping->integer) GL_BindToTMU( tr.whiteImage, TB_NORMALMAP ); if (pStage->bundle[TB_SPECULARMAP].image[0]) { R_BindAnimatedImageToTMU( &pStage->bundle[TB_SPECULARMAP], TB_SPECULARMAP); } else if (r_specularMapping->integer) GL_BindToTMU( tr.whiteImage, TB_SPECULARMAP ); { vec4_t enableTextures; VectorSet4(enableTextures, 0.0f, 0.0f, 0.0f, 0.0f); GLSL_SetUniformVec4(sp, UNIFORM_ENABLETEXTURES, enableTextures); } if (r_dlightMode->integer >= 2) { GL_SelectTexture(TB_SHADOWMAP); GL_Bind(tr.shadowCubemaps[l]); GL_SelectTexture(0); } ComputeTexMods( pStage, TB_DIFFUSEMAP, texMatrix, texOffTurb ); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, texMatrix); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, texOffTurb); GLSL_SetUniformInt(sp, UNIFORM_TCGEN0, pStage->bundle[0].tcGen); // // draw // if (input->multiDrawPrimitives) { R_DrawMultiElementsVao(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex); } else { R_DrawElementsVao(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex); } backEnd.pc.c_totalIndexes += tess.numIndexes; backEnd.pc.c_dlightIndexes += tess.numIndexes; backEnd.pc.c_dlightVertexes += tess.numVertexes; } }
static void RB_IterateStagesGeneric( shaderCommands_t *input ) { int stage; vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0}; float eyeT = 0; int deformGen; vec5_t deformParams; ComputeDeformValues(&deformGen, deformParams); ComputeFogValues(fogDistanceVector, fogDepthVector, &eyeT); for ( stage = 0; stage < MAX_SHADER_STAGES; stage++ ) { shaderStage_t *pStage = input->xstages[stage]; shaderProgram_t *sp; vec4_t texMatrix; vec4_t texOffTurb; if ( !pStage ) { break; } if (backEnd.depthFill) { if (pStage->glslShaderGroup == tr.lightallShader) { int index = 0; if (backEnd.currentEntity && backEnd.currentEntity != &tr.worldEntity) { index |= LIGHTDEF_ENTITY; } if (pStage->stateBits & GLS_ATEST_BITS) { index |= LIGHTDEF_USE_TCGEN_AND_TCMOD; } sp = &pStage->glslShaderGroup[index]; } else { int shaderAttribs = 0; if (tess.shader->numDeforms && !ShaderRequiresCPUDeforms(tess.shader)) { shaderAttribs |= GENERICDEF_USE_DEFORM_VERTEXES; } if (glState.vertexAnimation) { shaderAttribs |= GENERICDEF_USE_VERTEX_ANIMATION; } if (pStage->stateBits & GLS_ATEST_BITS) { shaderAttribs |= GENERICDEF_USE_TCGEN_AND_TCMOD; } sp = &tr.genericShader[shaderAttribs]; } } else if (pStage->glslShaderGroup == tr.lightallShader) { int index = pStage->glslShaderIndex; if (backEnd.currentEntity && backEnd.currentEntity != &tr.worldEntity) { index |= LIGHTDEF_ENTITY; } if (r_sunlightMode->integer && (backEnd.viewParms.flags & VPF_USESUNLIGHT) && (index & LIGHTDEF_LIGHTTYPE_MASK)) { index |= LIGHTDEF_USE_SHADOWMAP; } if (r_lightmap->integer && index & LIGHTDEF_USE_LIGHTMAP) { index = LIGHTDEF_USE_LIGHTMAP; } sp = &pStage->glslShaderGroup[index]; backEnd.pc.c_lightallDraws++; } else { sp = GLSL_GetGenericShaderProgram(stage); backEnd.pc.c_genericDraws++; } GLSL_BindProgram(sp); GLSL_SetUniformMat4(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin); GLSL_SetUniformVec3(sp, UNIFORM_LOCALVIEWORIGIN, backEnd.or.viewOrigin); GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation); GLSL_SetUniformInt(sp, UNIFORM_DEFORMGEN, deformGen); if (deformGen != DGEN_NONE) { GLSL_SetUniformFloat5(sp, UNIFORM_DEFORMPARAMS, deformParams); GLSL_SetUniformFloat(sp, UNIFORM_TIME, tess.shaderTime); } if ( input->fogNum ) { GLSL_SetUniformVec4(sp, UNIFORM_FOGDISTANCE, fogDistanceVector); GLSL_SetUniformVec4(sp, UNIFORM_FOGDEPTH, fogDepthVector); GLSL_SetUniformFloat(sp, UNIFORM_FOGEYET, eyeT); } GL_State( pStage->stateBits ); { vec4_t baseColor; vec4_t vertColor; ComputeShaderColors(pStage, baseColor, vertColor, pStage->stateBits); if ((backEnd.refdef.colorScale != 1.0f) && !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL)) { // use VectorScale to only scale first three values, not alpha VectorScale(baseColor, backEnd.refdef.colorScale, baseColor); VectorScale(vertColor, backEnd.refdef.colorScale, vertColor); } GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, baseColor); GLSL_SetUniformVec4(sp, UNIFORM_VERTCOLOR, vertColor); } if (pStage->rgbGen == CGEN_LIGHTING_DIFFUSE) { vec4_t vec; VectorScale(backEnd.currentEntity->ambientLight, 1.0f / 255.0f, vec); GLSL_SetUniformVec3(sp, UNIFORM_AMBIENTLIGHT, vec); VectorScale(backEnd.currentEntity->directedLight, 1.0f / 255.0f, vec); GLSL_SetUniformVec3(sp, UNIFORM_DIRECTEDLIGHT, vec); VectorCopy(backEnd.currentEntity->lightDir, vec); vec[3] = 0.0f; GLSL_SetUniformVec4(sp, UNIFORM_LIGHTORIGIN, vec); GLSL_SetUniformVec3(sp, UNIFORM_MODELLIGHTDIR, backEnd.currentEntity->modelLightDir); GLSL_SetUniformFloat(sp, UNIFORM_LIGHTRADIUS, 0.0f); } if (pStage->alphaGen == AGEN_PORTAL) { GLSL_SetUniformFloat(sp, UNIFORM_PORTALRANGE, tess.shader->portalRange); } GLSL_SetUniformInt(sp, UNIFORM_COLORGEN, pStage->rgbGen); GLSL_SetUniformInt(sp, UNIFORM_ALPHAGEN, pStage->alphaGen); if ( input->fogNum ) { vec4_t fogColorMask; ComputeFogColorMask(pStage, fogColorMask); GLSL_SetUniformVec4(sp, UNIFORM_FOGCOLORMASK, fogColorMask); } ComputeTexMods( pStage, TB_DIFFUSEMAP, texMatrix, texOffTurb ); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, texMatrix); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, texOffTurb); GLSL_SetUniformInt(sp, UNIFORM_TCGEN0, pStage->bundle[0].tcGen); if (pStage->bundle[0].tcGen == TCGEN_VECTOR) { vec3_t vec; VectorCopy(pStage->bundle[0].tcGenVectors[0], vec); GLSL_SetUniformVec3(sp, UNIFORM_TCGEN0VECTOR0, vec); VectorCopy(pStage->bundle[0].tcGenVectors[1], vec); GLSL_SetUniformVec3(sp, UNIFORM_TCGEN0VECTOR1, vec); } GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, backEnd.or.transformMatrix); GLSL_SetUniformVec4(sp, UNIFORM_NORMALSCALE, pStage->normalScale); GLSL_SetUniformVec4(sp, UNIFORM_SPECULARSCALE, pStage->specularScale); //GLSL_SetUniformFloat(sp, UNIFORM_MAPLIGHTSCALE, backEnd.refdef.mapLightScale); // // do multitexture // if ( backEnd.depthFill ) { if (!(pStage->stateBits & GLS_ATEST_BITS)) GL_BindToTMU( tr.whiteImage, 0 ); else if ( pStage->bundle[TB_COLORMAP].image[0] != 0 ) R_BindAnimatedImageToTMU( &pStage->bundle[TB_COLORMAP], TB_COLORMAP ); } else if ( pStage->glslShaderGroup == tr.lightallShader ) { int i; vec4_t enableTextures; if (r_sunlightMode->integer && (backEnd.viewParms.flags & VPF_USESUNLIGHT) && (pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK)) { GL_BindToTMU(tr.screenShadowImage, TB_SHADOWMAP); GLSL_SetUniformVec3(sp, UNIFORM_PRIMARYLIGHTAMBIENT, backEnd.refdef.sunAmbCol); GLSL_SetUniformVec3(sp, UNIFORM_PRIMARYLIGHTCOLOR, backEnd.refdef.sunCol); GLSL_SetUniformVec4(sp, UNIFORM_PRIMARYLIGHTORIGIN, backEnd.refdef.sunDir); } VectorSet4(enableTextures, 0, 0, 0, 0); if ((r_lightmap->integer == 1 || r_lightmap->integer == 2) && pStage->bundle[TB_LIGHTMAP].image[0]) { for (i = 0; i < NUM_TEXTURE_BUNDLES; i++) { if (i == TB_LIGHTMAP) R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], i); else GL_BindToTMU( tr.whiteImage, i ); } } else if (r_lightmap->integer == 3 && pStage->bundle[TB_DELUXEMAP].image[0]) { for (i = 0; i < NUM_TEXTURE_BUNDLES; i++) { if (i == TB_LIGHTMAP) R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], i); else GL_BindToTMU( tr.whiteImage, i ); } } else { qboolean light = (pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK) != 0; qboolean fastLight = !(r_normalMapping->integer || r_specularMapping->integer); if (pStage->bundle[TB_DIFFUSEMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_DIFFUSEMAP], TB_DIFFUSEMAP); if (pStage->bundle[TB_LIGHTMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_LIGHTMAP], TB_LIGHTMAP); // bind textures that are sampled and used in the glsl shader, and // bind whiteImage to textures that are sampled but zeroed in the glsl shader // // alternatives: // - use the last bound texture // -> costs more to sample a higher res texture then throw out the result // - disable texture sampling in glsl shader with #ifdefs, as before // -> increases the number of shaders that must be compiled // if (light && !fastLight) { if (pStage->bundle[TB_NORMALMAP].image[0]) { R_BindAnimatedImageToTMU( &pStage->bundle[TB_NORMALMAP], TB_NORMALMAP); enableTextures[0] = 1.0f; } else if (r_normalMapping->integer) GL_BindToTMU( tr.whiteImage, TB_NORMALMAP ); if (pStage->bundle[TB_DELUXEMAP].image[0]) { R_BindAnimatedImageToTMU( &pStage->bundle[TB_DELUXEMAP], TB_DELUXEMAP); enableTextures[1] = 1.0f; } else if (r_deluxeMapping->integer) GL_BindToTMU( tr.whiteImage, TB_DELUXEMAP ); if (pStage->bundle[TB_SPECULARMAP].image[0]) { R_BindAnimatedImageToTMU( &pStage->bundle[TB_SPECULARMAP], TB_SPECULARMAP); enableTextures[2] = 1.0f; } else if (r_specularMapping->integer) GL_BindToTMU( tr.whiteImage, TB_SPECULARMAP ); } enableTextures[3] = (r_cubeMapping->integer && !(tr.viewParms.flags & VPF_NOCUBEMAPS) && input->cubemapIndex) ? 1.0f : 0.0f; } GLSL_SetUniformVec4(sp, UNIFORM_ENABLETEXTURES, enableTextures); } else if ( pStage->bundle[1].image[0] != 0 ) { R_BindAnimatedImageToTMU( &pStage->bundle[0], 0 ); R_BindAnimatedImageToTMU( &pStage->bundle[1], 1 ); } else { // // set state // R_BindAnimatedImageToTMU( &pStage->bundle[0], 0 ); } // // testing cube map // if (!(tr.viewParms.flags & VPF_NOCUBEMAPS) && input->cubemapIndex && r_cubeMapping->integer) { vec4_t vec; GL_BindToTMU( tr.cubemaps[input->cubemapIndex - 1], TB_CUBEMAP); vec[0] = tr.cubemapOrigins[input->cubemapIndex - 1][0] - backEnd.viewParms.or.origin[0]; vec[1] = tr.cubemapOrigins[input->cubemapIndex - 1][1] - backEnd.viewParms.or.origin[1]; vec[2] = tr.cubemapOrigins[input->cubemapIndex - 1][2] - backEnd.viewParms.or.origin[2]; vec[3] = 1.0f; VectorScale4(vec, 1.0f / 1000.0f, vec); GLSL_SetUniformVec4(sp, UNIFORM_CUBEMAPINFO, vec); } // // draw // if (input->multiDrawPrimitives) { R_DrawMultiElementsVao(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex); } else { R_DrawElementsVao(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex); } // allow skipping out to show just lightmaps during development if ( r_lightmap->integer && ( pStage->bundle[0].isLightmap || pStage->bundle[1].isLightmap ) ) { break; } if (backEnd.depthFill) break; } }
/* ============= RE_StretchRaw FIXME: not exactly backend Stretches a raw 32 bit power of 2 bitmap image over the given screen rectangle. Used for cinematics. ============= */ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty) { int i, j; int start, end; vec4_t quadVerts[4]; vec2_t texCoords[4]; if ( !tr.registered ) { return; } R_IssuePendingRenderCommands(); if ( tess.numIndexes ) { RB_EndSurface(); } // we definately want to sync every frame for the cinematics qglFinish(); start = 0; if ( r_speeds->integer ) { start = ri.Milliseconds(); } // make sure rows and cols are powers of 2 for ( i = 0 ; ( 1 << i ) < cols ; i++ ) { } for ( j = 0 ; ( 1 << j ) < rows ; j++ ) { } if ( ( 1 << i ) != cols || ( 1 << j ) != rows) { ri.Error (ERR_DROP, "Draw_StretchRaw: size not a power of 2: %i by %i", cols, rows); } RE_UploadCinematic (w, h, cols, rows, data, client, dirty); if ( r_speeds->integer ) { end = ri.Milliseconds(); ri.Printf( PRINT_ALL, "qglTexSubImage2D %i, %i: %i msec\n", cols, rows, end - start ); } // FIXME: HUGE hack if (glRefConfig.framebufferObject) { if (!tr.renderFbo || backEnd.framePostProcessed) { FBO_Bind(NULL); } else { FBO_Bind(tr.renderFbo); } } RB_SetGL2D(); VectorSet4(quadVerts[0], x, y, 0.0f, 1.0f); VectorSet4(quadVerts[1], x + w, y, 0.0f, 1.0f); VectorSet4(quadVerts[2], x + w, y + h, 0.0f, 1.0f); VectorSet4(quadVerts[3], x, y + h, 0.0f, 1.0f); VectorSet2(texCoords[0], 0.5f / cols, 0.5f / rows); VectorSet2(texCoords[1], (cols - 0.5f) / cols, 0.5f / rows); VectorSet2(texCoords[2], (cols - 0.5f) / cols, (rows - 0.5f) / rows); VectorSet2(texCoords[3], 0.5f / cols, (rows - 0.5f) / rows); GLSL_BindProgram(&tr.textureColorShader); GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); GLSL_SetUniformVec4(&tr.textureColorShader, UNIFORM_COLOR, colorWhite); RB_InstantQuad2(quadVerts, texCoords); }
void CG_DrawSmallString( int x, int y, const char *s, float alpha ) { vector4 color; VectorSet4( &color, 1.0f, 1.0f, 1.0f, alpha ); CG_DrawStringExt( x, y, s, &color, qfalse, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 ); }
static void ForwardSunlight( void ) { // int l; //vec3_t origin; //float scale; int stage; int stageGlState[2]; qboolean alphaOverride = qfalse; int deformGen; vec5_t deformParams; vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0}; float eyeT = 0; shaderCommands_t *input = &tess; ComputeDeformValues(&deformGen, deformParams); ComputeFogValues(fogDistanceVector, fogDepthVector, &eyeT); // deal with vertex alpha blended surfaces if (input->xstages[0] && input->xstages[1] && (input->xstages[1]->alphaGen == AGEN_VERTEX || input->xstages[1]->alphaGen == AGEN_ONE_MINUS_VERTEX)) { stageGlState[0] = input->xstages[0]->stateBits & (GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS); if (stageGlState[0] == 0 || stageGlState[0] == (GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO)) { stageGlState[1] = input->xstages[1]->stateBits & (GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS); if (stageGlState[1] == (GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA)) { alphaOverride = qtrue; stageGlState[0] = GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL; stageGlState[1] = GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL; } else if (stageGlState[1] == (GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA | GLS_DSTBLEND_SRC_ALPHA)) { alphaOverride = qtrue; stageGlState[0] = GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL; stageGlState[1] = GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL; } } } if (!alphaOverride) { stageGlState[0] = stageGlState[1] = GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL; } for ( stage = 0; stage < 2 /*MAX_SHADER_STAGES */; stage++ ) { shaderStage_t *pStage = input->xstages[stage]; shaderProgram_t *sp; vec4_t vector; matrix_t matrix; if ( !pStage ) { break; } //VectorCopy( dl->transformed, origin ); //if (pStage->glslShaderGroup == tr.lightallShader) { int index = pStage->glslShaderIndex; index &= ~(LIGHTDEF_LIGHTTYPE_MASK | LIGHTDEF_USE_DELUXEMAP); index |= LIGHTDEF_USE_LIGHT_VECTOR | LIGHTDEF_USE_SHADOWMAP; if (backEnd.currentEntity && backEnd.currentEntity != &tr.worldEntity) { index |= LIGHTDEF_ENTITY; } sp = &tr.lightallShader[index]; } backEnd.pc.c_lightallDraws++; GLSL_BindProgram(sp); GLSL_SetUniformMatrix16(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin); GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation); GLSL_SetUniformInt(sp, UNIFORM_DEFORMGEN, deformGen); if (deformGen != DGEN_NONE) { GLSL_SetUniformFloat5(sp, UNIFORM_DEFORMPARAMS, deformParams); GLSL_SetUniformFloat(sp, UNIFORM_TIME, tess.shaderTime); } if ( input->fogNum ) { vec4_t fogColorMask; GLSL_SetUniformVec4(sp, UNIFORM_FOGDISTANCE, fogDistanceVector); GLSL_SetUniformVec4(sp, UNIFORM_FOGDEPTH, fogDepthVector); GLSL_SetUniformFloat(sp, UNIFORM_FOGEYET, eyeT); ComputeFogColorMask(pStage, fogColorMask); GLSL_SetUniformVec4(sp, UNIFORM_FOGCOLORMASK, fogColorMask); } { vec4_t baseColor; vec4_t vertColor; ComputeShaderColors(pStage, baseColor, vertColor); if (alphaOverride) { if (input->xstages[1]->alphaGen == AGEN_VERTEX) { baseColor[3] = 0.0f; vertColor[3] = 1.0f; } else if (input->xstages[1]->alphaGen == AGEN_ONE_MINUS_VERTEX) { baseColor[3] = 1.0f; vertColor[3] = -1.0f; } } GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, baseColor); GLSL_SetUniformVec4(sp, UNIFORM_VERTCOLOR, vertColor); } if (pStage->alphaGen == AGEN_PORTAL) { GLSL_SetUniformFloat(sp, UNIFORM_PORTALRANGE, tess.shader->portalRange); } GLSL_SetUniformInt(sp, UNIFORM_COLORGEN, pStage->rgbGen); GLSL_SetUniformInt(sp, UNIFORM_ALPHAGEN, pStage->alphaGen); GLSL_SetUniformVec3(sp, UNIFORM_DIRECTEDLIGHT, backEnd.refdef.sunCol); GLSL_SetUniformVec3(sp, UNIFORM_AMBIENTLIGHT, backEnd.refdef.sunAmbCol); GLSL_SetUniformVec4(sp, UNIFORM_LIGHTORIGIN, backEnd.refdef.sunDir); GLSL_SetUniformFloat(sp, UNIFORM_LIGHTRADIUS, 9999999999.9f); GLSL_SetUniformVec2(sp, UNIFORM_MATERIALINFO, pStage->materialInfo); GL_State( stageGlState[stage] ); GLSL_SetUniformMatrix16(sp, UNIFORM_MODELMATRIX, backEnd.or.transformMatrix); if (pStage->bundle[TB_DIFFUSEMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_DIFFUSEMAP], TB_DIFFUSEMAP); if (pStage->bundle[TB_NORMALMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_NORMALMAP], TB_NORMALMAP); if (pStage->bundle[TB_SPECULARMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_SPECULARMAP], TB_SPECULARMAP); /* { GL_BindToTMU(tr.sunShadowDepthImage[0], TB_SHADOWMAP); GL_BindToTMU(tr.sunShadowDepthImage[1], TB_SHADOWMAP2); GL_BindToTMU(tr.sunShadowDepthImage[2], TB_SHADOWMAP3); GLSL_SetUniformMatrix16(sp, UNIFORM_SHADOWMVP, backEnd.refdef.sunShadowMvp[0]); GLSL_SetUniformMatrix16(sp, UNIFORM_SHADOWMVP2, backEnd.refdef.sunShadowMvp[1]); GLSL_SetUniformMatrix16(sp, UNIFORM_SHADOWMVP3, backEnd.refdef.sunShadowMvp[2]); } */ GL_BindToTMU(tr.screenShadowImage, TB_SHADOWMAP); ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix ); VectorSet4(vector, matrix[0], matrix[1], matrix[4], matrix[5]); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, vector); VectorSet4(vector, matrix[8], matrix[9], matrix[12], matrix[13]); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, vector); GLSL_SetUniformInt(sp, UNIFORM_TCGEN0, pStage->bundle[0].tcGen); // // draw // if (input->multiDrawPrimitives) { R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex); } else { R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex); } backEnd.pc.c_totalIndexes += tess.numIndexes; backEnd.pc.c_dlightIndexes += tess.numIndexes; } }
/* ============= RB_PostProcess ============= */ const void *RB_PostProcess(const void *data) { const postProcessCommand_t *cmd = data; FBO_t *srcFbo; ivec4_t srcBox, dstBox; qboolean autoExposure; // finish any 2D drawing if needed if(tess.numIndexes) RB_EndSurface(); if (!glRefConfig.framebufferObject || !r_postProcess->integer) { // do nothing return (const void *)(cmd + 1); } if (cmd) { backEnd.refdef = cmd->refdef; backEnd.viewParms = cmd->viewParms; } srcFbo = tr.renderFbo; if (tr.msaaResolveFbo) { // Resolve the MSAA before anything else // Can't resolve just part of the MSAA FBO, so multiple views will suffer a performance hit here FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); srcFbo = tr.msaaResolveFbo; } dstBox[0] = backEnd.viewParms.viewportX; dstBox[1] = backEnd.viewParms.viewportY; dstBox[2] = backEnd.viewParms.viewportWidth; dstBox[3] = backEnd.viewParms.viewportHeight; if (r_ssao->integer) { srcBox[0] = backEnd.viewParms.viewportX * tr.screenSsaoImage->width / (float)glConfig.vidWidth; srcBox[1] = backEnd.viewParms.viewportY * tr.screenSsaoImage->height / (float)glConfig.vidHeight; srcBox[2] = backEnd.viewParms.viewportWidth * tr.screenSsaoImage->width / (float)glConfig.vidWidth; srcBox[3] = backEnd.viewParms.viewportHeight * tr.screenSsaoImage->height / (float)glConfig.vidHeight; FBO_Blit(tr.screenSsaoFbo, srcBox, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); } srcBox[0] = backEnd.viewParms.viewportX; srcBox[1] = backEnd.viewParms.viewportY; srcBox[2] = backEnd.viewParms.viewportWidth; srcBox[3] = backEnd.viewParms.viewportHeight; if (srcFbo) { if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer)) { autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer; RB_ToneMap(srcFbo, srcBox, NULL, dstBox, autoExposure); } else if (r_cameraExposure->value == 0.0f) { FBO_FastBlit(srcFbo, srcBox, NULL, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST); } else { vec4_t color; color[0] = color[1] = color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value); color[3] = 1.0f; FBO_Blit(srcFbo, srcBox, NULL, NULL, dstBox, NULL, color, 0); } } if (r_drawSunRays->integer) RB_SunRays(NULL, srcBox, NULL, dstBox); if (1) RB_BokehBlur(NULL, srcBox, NULL, dstBox, backEnd.refdef.blurFactor); else RB_GaussianBlur(backEnd.refdef.blurFactor); #if 0 if (0) { vec4_t quadVerts[4]; vec2_t texCoords[4]; ivec4_t iQtrBox; vec4_t box; vec4_t viewInfo; static float scale = 5.0f; scale -= 0.005f; if (scale < 0.01f) scale = 5.0f; FBO_FastBlit(NULL, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); iQtrBox[0] = backEnd.viewParms.viewportX * tr.quarterImage[0]->width / (float)glConfig.vidWidth; iQtrBox[1] = backEnd.viewParms.viewportY * tr.quarterImage[0]->height / (float)glConfig.vidHeight; iQtrBox[2] = backEnd.viewParms.viewportWidth * tr.quarterImage[0]->width / (float)glConfig.vidWidth; iQtrBox[3] = backEnd.viewParms.viewportHeight * tr.quarterImage[0]->height / (float)glConfig.vidHeight; qglViewport(iQtrBox[0], iQtrBox[1], iQtrBox[2], iQtrBox[3]); qglScissor(iQtrBox[0], iQtrBox[1], iQtrBox[2], iQtrBox[3]); VectorSet4(box, 0.0f, 0.0f, 1.0f, 1.0f); texCoords[0][0] = box[0]; texCoords[0][1] = box[3]; texCoords[1][0] = box[2]; texCoords[1][1] = box[3]; texCoords[2][0] = box[2]; texCoords[2][1] = box[1]; texCoords[3][0] = box[0]; texCoords[3][1] = box[1]; VectorSet4(box, -1.0f, -1.0f, 1.0f, 1.0f); VectorSet4(quadVerts[0], box[0], box[3], 0, 1); VectorSet4(quadVerts[1], box[2], box[3], 0, 1); VectorSet4(quadVerts[2], box[2], box[1], 0, 1); VectorSet4(quadVerts[3], box[0], box[1], 0, 1); GL_State(GLS_DEPTHTEST_DISABLE); VectorSet4(viewInfo, backEnd.viewParms.zFar / r_znear->value, backEnd.viewParms.zFar, 0.0, 0.0); viewInfo[2] = scale / (float)(tr.quarterImage[0]->width); viewInfo[3] = scale / (float)(tr.quarterImage[0]->height); FBO_Bind(tr.quarterFbo[1]); GLSL_BindProgram(&tr.depthBlurShader[2]); GL_BindToTMU(tr.quarterImage[0], TB_COLORMAP); GLSL_SetUniformVec4(&tr.depthBlurShader[2], UNIFORM_VIEWINFO, viewInfo); RB_InstantQuad2(quadVerts, texCoords); FBO_Bind(tr.quarterFbo[0]); GLSL_BindProgram(&tr.depthBlurShader[3]); GL_BindToTMU(tr.quarterImage[1], TB_COLORMAP); GLSL_SetUniformVec4(&tr.depthBlurShader[3], UNIFORM_VIEWINFO, viewInfo); RB_InstantQuad2(quadVerts, texCoords); SetViewportAndScissor(); FBO_FastBlit(tr.quarterFbo[1], NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR); FBO_Bind(NULL); } #endif if (0 && r_sunlightMode->integer) { ivec4_t dstBox; VectorSet4(dstBox, 0, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 128, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 256, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 384, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); } #if 0 if (r_cubeMapping->integer && tr.numCubemaps) { ivec4_t dstBox; int cubemapIndex = R_CubemapForPoint( backEnd.viewParms.or.origin ); if (cubemapIndex) { VectorSet4(dstBox, 0, glConfig.vidHeight - 256, 256, 256); //FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1].image, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); } } #endif backEnd.framePostProcessed = qtrue; return (const void *)(cmd + 1); }
void FBO_BlitFromTexture(struct image_s *src, vec4_t inSrcTexCorners, vec2_t inSrcTexScale, FBO_t *dst, ivec4_t inDstBox, struct shaderProgram_s *shaderProgram, vec4_t inColor, int blend) { ivec4_t dstBox; vec4_t color; vec4_t quadVerts[4]; vec2_t texCoords[4]; vec2_t invTexRes; FBO_t *oldFbo = glState.currentFBO; mat4_t projection; int width, height; if (!src) { ri.Printf(PRINT_WARNING, "Tried to blit from a NULL texture!\n"); return; } width = dst ? dst->width : glConfig.vidWidth; height = dst ? dst->height : glConfig.vidHeight; if (inSrcTexCorners) { VectorSet2(texCoords[0], inSrcTexCorners[0], inSrcTexCorners[1]); VectorSet2(texCoords[1], inSrcTexCorners[2], inSrcTexCorners[1]); VectorSet2(texCoords[2], inSrcTexCorners[2], inSrcTexCorners[3]); VectorSet2(texCoords[3], inSrcTexCorners[0], inSrcTexCorners[3]); } else { VectorSet2(texCoords[0], 0.0f, 1.0f); VectorSet2(texCoords[1], 1.0f, 1.0f); VectorSet2(texCoords[2], 1.0f, 0.0f); VectorSet2(texCoords[3], 0.0f, 0.0f); } // framebuffers are 0 bottom, Y up. if (inDstBox) { dstBox[0] = inDstBox[0]; dstBox[1] = height - inDstBox[1] - inDstBox[3]; dstBox[2] = inDstBox[0] + inDstBox[2]; dstBox[3] = height - inDstBox[1]; } else { VectorSet4(dstBox, 0, height, width, 0); } if (inSrcTexScale) { VectorCopy2(inSrcTexScale, invTexRes); } else { VectorSet2(invTexRes, 1.0f, 1.0f); } if (inColor) { VectorCopy4(inColor, color); } else { VectorCopy4(colorWhite, color); } if (!shaderProgram) { shaderProgram = &tr.textureColorShader; } FBO_Bind(dst); qglViewport( 0, 0, width, height ); qglScissor( 0, 0, width, height ); Mat4Ortho(0, width, height, 0, 0, 1, projection); GL_Cull( CT_TWO_SIDED ); GL_BindToTMU(src, TB_COLORMAP); VectorSet4(quadVerts[0], dstBox[0], dstBox[1], 0.0f, 1.0f); VectorSet4(quadVerts[1], dstBox[2], dstBox[1], 0.0f, 1.0f); VectorSet4(quadVerts[2], dstBox[2], dstBox[3], 0.0f, 1.0f); VectorSet4(quadVerts[3], dstBox[0], dstBox[3], 0.0f, 1.0f); invTexRes[0] /= src->width; invTexRes[1] /= src->height; GL_State( blend ); GLSL_BindProgram(shaderProgram); GLSL_SetUniformMat4(shaderProgram, UNIFORM_MODELVIEWPROJECTIONMATRIX, projection); GLSL_SetUniformVec4(shaderProgram, UNIFORM_COLOR, color); GLSL_SetUniformVec2(shaderProgram, UNIFORM_INVTEXRES, invTexRes); GLSL_SetUniformVec2(shaderProgram, UNIFORM_AUTOEXPOSUREMINMAX, tr.refdef.autoExposureMinMax); GLSL_SetUniformVec3(shaderProgram, UNIFORM_TONEMINAVGMAXLINEAR, tr.refdef.toneMinAvgMaxLinear); RB_InstantQuad2(quadVerts, texCoords); FBO_Bind(oldFbo); }
void FBO_BlitFromTexture(struct image_s *src, ivec4_t inSrcBox, vec2_t inSrcTexScale, FBO_t *dst, ivec4_t inDstBox, struct shaderProgram_s *shaderProgram, vec4_t inColor, int blend) { ivec4_t dstBox, srcBox; vec2_t srcTexScale; vec4_t color; vec4_t quadVerts[4]; vec2_t texCoords[4]; vec2_t invTexRes; FBO_t *oldFbo = glState.currentFBO; mat4_t projection; int width, height; if (!src) return; if (inSrcBox) { VectorSet4(srcBox, inSrcBox[0], inSrcBox[1], inSrcBox[0] + inSrcBox[2], inSrcBox[1] + inSrcBox[3]); } else { VectorSet4(srcBox, 0, 0, src->width, src->height); } // framebuffers are 0 bottom, Y up. if (inDstBox) { if (dst) { dstBox[0] = inDstBox[0]; dstBox[1] = dst->height - inDstBox[1] - inDstBox[3]; dstBox[2] = inDstBox[0] + inDstBox[2]; dstBox[3] = dst->height - inDstBox[1]; } else { dstBox[0] = inDstBox[0]; dstBox[1] = glConfig.vidHeight - inDstBox[1] - inDstBox[3]; dstBox[2] = inDstBox[0] + inDstBox[2]; dstBox[3] = glConfig.vidHeight - inDstBox[1]; } } else if (dst) { VectorSet4(dstBox, 0, dst->height, dst->width, 0); } else { VectorSet4(dstBox, 0, glConfig.vidHeight, glConfig.vidWidth, 0); } if (inSrcTexScale) { VectorCopy2(inSrcTexScale, srcTexScale); } else { srcTexScale[0] = srcTexScale[1] = 1.0f; } if (inColor) { VectorCopy4(inColor, color); } else { VectorCopy4(colorWhite, color); } if (!shaderProgram) { shaderProgram = &tr.textureColorShader; } FBO_Bind(dst); if (glState.currentFBO) { width = glState.currentFBO->width; height = glState.currentFBO->height; } else { width = glConfig.vidWidth; height = glConfig.vidHeight; } qglViewport( 0, 0, width, height ); qglScissor( 0, 0, width, height ); Mat4Ortho(0, width, height, 0, 0, 1, projection); qglDisable( GL_CULL_FACE ); GL_BindToTMU(src, TB_COLORMAP); VectorSet4(quadVerts[0], dstBox[0], dstBox[1], 0, 1); VectorSet4(quadVerts[1], dstBox[2], dstBox[1], 0, 1); VectorSet4(quadVerts[2], dstBox[2], dstBox[3], 0, 1); VectorSet4(quadVerts[3], dstBox[0], dstBox[3], 0, 1); texCoords[0][0] = srcBox[0] / (float)src->width; texCoords[0][1] = 1.0f - srcBox[1] / (float)src->height; texCoords[1][0] = srcBox[2] / (float)src->width; texCoords[1][1] = 1.0f - srcBox[1] / (float)src->height; texCoords[2][0] = srcBox[2] / (float)src->width; texCoords[2][1] = 1.0f - srcBox[3] / (float)src->height; texCoords[3][0] = srcBox[0] / (float)src->width; texCoords[3][1] = 1.0f - srcBox[3] / (float)src->height; invTexRes[0] = 1.0f / src->width * srcTexScale[0]; invTexRes[1] = 1.0f / src->height * srcTexScale[1]; GL_State( blend ); GLSL_BindProgram(shaderProgram); GLSL_SetUniformMat4(shaderProgram, UNIFORM_MODELVIEWPROJECTIONMATRIX, projection); GLSL_SetUniformVec4(shaderProgram, UNIFORM_COLOR, color); GLSL_SetUniformVec2(shaderProgram, UNIFORM_INVTEXRES, invTexRes); GLSL_SetUniformVec2(shaderProgram, UNIFORM_AUTOEXPOSUREMINMAX, tr.refdef.autoExposureMinMax); GLSL_SetUniformVec3(shaderProgram, UNIFORM_TONEMINAVGMAXLINEAR, tr.refdef.toneMinAvgMaxLinear); RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes); FBO_Bind(oldFbo); }
void CG_DrawBigString( int x, int y, const char *s, float alpha ) { vector4 color; VectorSet4( &color, 1.0f, 1.0f, 1.0f, alpha ); CG_DrawStringExt(x, y, s, &color, qfalse, qtrue, BIGCHAR_WIDTH * cgs.widthRatioCoef, BIGCHAR_HEIGHT, 0); }
static void ForwardDlight( void ) { int l; //vec3_t origin; //float scale; float radius; int deformGen; vec5_t deformParams; vec4_t fogDistanceVector, fogDepthVector = {0, 0, 0, 0}; float eyeT = 0; shaderCommands_t *input = &tess; shaderStage_t *pStage = tess.xstages[0]; if ( !backEnd.refdef.num_dlights ) { return; } ComputeDeformValues(&deformGen, deformParams); ComputeFogValues(fogDistanceVector, fogDepthVector, &eyeT); for ( l = 0 ; l < backEnd.refdef.num_dlights ; l++ ) { dlight_t *dl; shaderProgram_t *sp; vec4_t vector; matrix_t matrix; if ( !( tess.dlightBits & ( 1 << l ) ) ) { continue; // this surface definately doesn't have any of this light } dl = &backEnd.refdef.dlights[l]; //VectorCopy( dl->transformed, origin ); radius = dl->radius; //scale = 1.0f / radius; //if (pStage->glslShaderGroup == tr.lightallShader) { int index = pStage->glslShaderIndex; index &= ~(LIGHTDEF_LIGHTTYPE_MASK | LIGHTDEF_USE_DELUXEMAP); index |= LIGHTDEF_USE_LIGHT_VECTOR; sp = &tr.lightallShader[index]; } backEnd.pc.c_lightallDraws++; GLSL_BindProgram(sp); GLSL_SetUniformMatrix16(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin); GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation); GLSL_SetUniformInt(sp, UNIFORM_DEFORMGEN, deformGen); if (deformGen != DGEN_NONE) { GLSL_SetUniformFloat5(sp, UNIFORM_DEFORMPARAMS, deformParams); GLSL_SetUniformFloat(sp, UNIFORM_TIME, tess.shaderTime); } if ( input->fogNum ) { vec4_t fogColorMask; GLSL_SetUniformVec4(sp, UNIFORM_FOGDISTANCE, fogDistanceVector); GLSL_SetUniformVec4(sp, UNIFORM_FOGDEPTH, fogDepthVector); GLSL_SetUniformFloat(sp, UNIFORM_FOGEYET, eyeT); ComputeFogColorMask(pStage, fogColorMask); GLSL_SetUniformVec4(sp, UNIFORM_FOGCOLORMASK, fogColorMask); } { vec4_t baseColor; vec4_t vertColor; ComputeShaderColors(pStage, baseColor, vertColor); GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, baseColor); GLSL_SetUniformVec4(sp, UNIFORM_VERTCOLOR, vertColor); } if (pStage->alphaGen == AGEN_PORTAL) { GLSL_SetUniformFloat(sp, UNIFORM_PORTALRANGE, tess.shader->portalRange); } GLSL_SetUniformInt(sp, UNIFORM_COLORGEN, pStage->rgbGen); GLSL_SetUniformInt(sp, UNIFORM_ALPHAGEN, pStage->alphaGen); GLSL_SetUniformVec3(sp, UNIFORM_DIRECTEDLIGHT, dl->color); VectorSet(vector, 0, 0, 0); GLSL_SetUniformVec3(sp, UNIFORM_AMBIENTLIGHT, vector); VectorCopy(dl->origin, vector); vector[3] = 1.0f; GLSL_SetUniformVec4(sp, UNIFORM_LIGHTORIGIN, vector); GLSL_SetUniformFloat(sp, UNIFORM_LIGHTRADIUS, radius); GLSL_SetUniformVec2(sp, UNIFORM_MATERIALINFO, pStage->materialInfo); // include GLS_DEPTHFUNC_EQUAL so alpha tested surfaces don't add light // where they aren't rendered GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL ); GLSL_SetUniformMatrix16(sp, UNIFORM_MODELMATRIX, backEnd.or.transformMatrix); if (pStage->bundle[TB_DIFFUSEMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_DIFFUSEMAP], TB_DIFFUSEMAP); if (pStage->bundle[TB_NORMALMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_NORMALMAP], TB_NORMALMAP); if (pStage->bundle[TB_SPECULARMAP].image[0]) R_BindAnimatedImageToTMU( &pStage->bundle[TB_SPECULARMAP], TB_SPECULARMAP); if (r_dlightMode->integer >= 2) { GL_SelectTexture(TB_SHADOWMAP); GL_BindCubemap(tr.shadowCubemaps[l]); GL_SelectTexture(0); } ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix ); VectorSet4(vector, matrix[0], matrix[1], matrix[4], matrix[5]); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, vector); VectorSet4(vector, matrix[8], matrix[9], matrix[12], matrix[13]); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, vector); GLSL_SetUniformInt(sp, UNIFORM_TCGEN0, pStage->bundle[0].tcGen); // // draw // if (input->multiDrawPrimitives) { R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex); } else { R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex); } backEnd.pc.c_totalIndexes += tess.numIndexes; backEnd.pc.c_dlightIndexes += tess.numIndexes; } }
void ParseBrushFace (entity_t *ent, mbrush_t **brushpointer, brushtype_t brushtype) { int i, j, hltexdef, bpface, brushplane; // int facecontents, faceflags, facevalue, q2brushface, q3brushface; vec_t planepts[3][3], t1[3], t2[3], d, rotate, scale[2], vecs[2][4], ang, sinv, cosv, bp[2][3]; mface_t *f, *f2; plane_t plane; texinfo_t tx; mbrush_t *b; if (brushtype == BRUSHTYPE_PATCHDEF2 || brushtype == BRUSHTYPE_PATCHDEF3) return; // read the three point plane definition if (strcmp (token, "(") ) Error ("parsing brush on line %d\n", scriptline); GetToken (false); planepts[0][0] = atof(token); GetToken (false); planepts[0][1] = atof(token); GetToken (false); planepts[0][2] = atof(token); GetToken (false); if (!strcmp(token, ")")) { brushplane = false; GetToken (false); if (strcmp(token, "(")) Error("parsing brush on line %d\n", scriptline); GetToken (false); planepts[1][0] = atof(token); GetToken (false); planepts[1][1] = atof(token); GetToken (false); planepts[1][2] = atof(token); GetToken (false); if (strcmp(token, ")")) Error("parsing brush on line %d\n", scriptline); GetToken (false); if (strcmp(token, "(")) Error("parsing brush on line %d\n", scriptline); GetToken (false); planepts[2][0] = atof(token); GetToken (false); planepts[2][1] = atof(token); GetToken (false); planepts[2][2] = atof(token); GetToken (false); if (strcmp(token, ")")) Error("parsing brush on line %d\n", scriptline); // convert points to a plane VectorSubtract(planepts[0], planepts[1], t1); VectorSubtract(planepts[2], planepts[1], t2); CrossProduct(t1, t2, plane.normal); VectorNormalize(plane.normal); plane.dist = DotProduct(planepts[1], plane.normal); } else { // oh, it's actually a 4 value plane brushplane = true; plane.normal[0] = planepts[0][0]; plane.normal[1] = planepts[0][1]; plane.normal[2] = planepts[0][2]; plane.dist = -atof(token); GetToken (false); if (strcmp(token, ")")) Error("parsing brush on line %d\n", scriptline); } // read the texturedef memset (&tx, 0, sizeof(tx)); GetToken (false); bpface = false; hltexdef = false; if (!strcmp(token, "(")) { // brush primitives, utterly insane bpface = true; // ( GetToken(false); // ( GetToken(false); bp[0][0] = atof(token); GetToken(false); bp[0][1] = atof(token); GetToken(false); bp[0][2] = atof(token); GetToken(false); // ) GetToken(false); // ( GetToken(false); bp[1][0] = atof(token); GetToken(false); bp[1][1] = atof(token); GetToken(false); bp[1][2] = atof(token); GetToken(false); // ) GetToken (false); GetToken (false); tx.miptex = FindMiptex (token); rotate = 0; scale[0] = 1; scale[1] = 1; } else { // if the texture name contains a / then this is a q2/q3 brushface // strip off the path, wads don't use a path on texture names tx.miptex = FindMiptex (token); GetToken (false); if (!strcmp(token, "[")) { hltexdef = true; // S vector GetToken(false); vecs[0][0] = (vec_t)atof(token); GetToken(false); vecs[0][1] = (vec_t)atof(token); GetToken(false); vecs[0][2] = (vec_t)atof(token); GetToken(false); vecs[0][3] = (vec_t)atof(token); // ] GetToken(false); // [ GetToken(false); // T vector GetToken(false); vecs[1][0] = (vec_t)atof(token); GetToken(false); vecs[1][1] = (vec_t)atof(token); GetToken(false); vecs[1][2] = (vec_t)atof(token); GetToken(false); vecs[1][3] = (vec_t)atof(token); // ] GetToken(false); // rotation (unused - implicit in tex coords) GetToken(false); rotate = 0; } else { vecs[0][3] = (vec_t)atof(token); // LordHavoc: float coords GetToken (false); vecs[1][3] = (vec_t)atof(token); // LordHavoc: float coords GetToken (false); rotate = atof(token); // LordHavoc: float coords } GetToken (false); scale[0] = (vec_t)atof(token); // LordHavoc: was already float coords GetToken (false); scale[1] = (vec_t)atof(token); // LordHavoc: was already float coords bp[0][0] = 1; bp[0][1] = 0; bp[0][2] = 0; bp[1][0] = 0; bp[1][1] = 1; bp[1][2] = 0; } // q3 .map properties, currently unused but parsed // facecontents = 0; // faceflags = 0; // facevalue = 0; // q2brushface = false; // q3brushface = false; if (GetToken (false)) { // q2brushface = true; // facecontents = atoi(token); if (GetToken (false)) { // faceflags = atoi(token); if (GetToken (false)) { // q2brushface = false; // q3brushface = true; // facevalue = atoi(token); } } } // skip trailing info (the 3 q3 .map parameters for example) while (GetToken (false)); if (DotProduct(plane.normal, plane.normal) < 0.1) { printf ("WARNING: line %i: brush plane with no normal\n", scriptline); return; } scale[0] = 1.0 / scale[0]; scale[1] = 1.0 / scale[1]; if (bpface) { // calculate proper texture vectors from GTKRadiant/Doom3 brushprimitives matrix float a, ac, as, bc, bs; a = -atan2(plane.normal[2], sqrt(plane.normal[0]*plane.normal[0]+plane.normal[1]*plane.normal[1])); ac = cos(a); as = sin(a); a = atan2(plane.normal[1], plane.normal[0]); bc = cos(a); bs = sin(a); vecs[0][0] = -bs; vecs[0][1] = bc; vecs[0][2] = 0; vecs[1][0] = -as*bc; vecs[1][1] = -as*bs; vecs[1][2] = -ac; tx.vecs[0][0] = bp[0][0] * vecs[0][0] + bp[0][1] * vecs[1][0]; tx.vecs[0][1] = bp[0][0] * vecs[0][1] + bp[0][1] * vecs[1][1]; tx.vecs[0][2] = bp[0][0] * vecs[0][2] + bp[0][1] * vecs[1][2]; tx.vecs[0][3] = bp[0][0] * vecs[0][3] + bp[0][1] * vecs[1][3] + bp[0][2]; tx.vecs[1][0] = bp[1][0] * vecs[0][0] + bp[1][1] * vecs[1][0]; tx.vecs[1][1] = bp[1][0] * vecs[0][1] + bp[1][1] * vecs[1][1]; tx.vecs[1][2] = bp[1][0] * vecs[0][2] + bp[1][1] * vecs[1][2]; tx.vecs[1][3] = bp[1][0] * vecs[0][3] + bp[1][1] * vecs[1][3] + bp[1][2]; } else if (hltexdef) { // HL texture vectors are almost ready to go for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) tx.vecs[i][j] = vecs[i][j] * scale[i]; tx.vecs[i][3] = vecs[i][3] /*+ DotProduct(origin, tx.vecs[i])*/; // Sajt: ripped the commented out bit from the HL compiler code, not really sure what it is exactly doing // 'origin': origin set on bmodel by origin brush or origin key } } else { // fake proper texture vectors from QuakeEd style // texture rotation around the plane normal if (rotate == 0) {sinv = 0;cosv = 1;} else if (rotate == 90) {sinv = 1;cosv = 0;} else if (rotate == 180) {sinv = 0;cosv = -1;} else if (rotate == 270) {sinv = -1;cosv = 0;} else {ang = rotate * (Q_PI / 180);sinv = sin(ang);cosv = cos(ang);} if (fabs(plane.normal[2]) < fabs(plane.normal[0])) { if (fabs(plane.normal[0]) < fabs(plane.normal[1])) { // Y primary VectorSet4(tx.vecs[0], cosv*scale[0], 0, sinv*scale[0], vecs[0][3]); VectorSet4(tx.vecs[1], sinv*scale[1], 0, -cosv*scale[1], vecs[1][3]); } else { // X primary VectorSet4(tx.vecs[0], 0, cosv*scale[0], sinv*scale[0], vecs[0][3]); VectorSet4(tx.vecs[1], 0, sinv*scale[1], -cosv*scale[1], vecs[1][3]); } } else if (fabs(plane.normal[2]) < fabs(plane.normal[1])) { // Y primary VectorSet4(tx.vecs[0], cosv*scale[0], 0, sinv*scale[0], vecs[0][3]); VectorSet4(tx.vecs[1], sinv*scale[1], 0, -cosv*scale[1], vecs[1][3]); } else { // Z primary VectorSet4(tx.vecs[0], cosv*scale[0], sinv*scale[0], 0, vecs[0][3]); VectorSet4(tx.vecs[1], sinv*scale[1], -cosv*scale[1], 0, vecs[1][3]); } //printf("plane + rotate scale = texture vectors:\n(%f %f %f %f) + [%f %f %f] =\n[%f %f %f %f] [%f %f %f %f]\n", plane.normal[0], plane.normal[1], plane.normal[2], plane.dist, rotate, scale[0], scale[1], tx.vecs[0][0], tx.vecs[0][1], tx.vecs[0][2], tx.vecs[0][3], tx.vecs[1][0], tx.vecs[1][1], tx.vecs[1][2], tx.vecs[1][3]); } for (i = 0;i < 2;i++) { for (j = 0;j < 4;j++) { if (tx.vecs[i][j] > -BOGUS_RANGE && tx.vecs[i][j] < BOGUS_RANGE) continue; printf( "WARNING: line %i: corrupt texture mapping vectors, using defaults\n", scriptline); cosv = 1; sinv = 0; scale[0] = 1; scale[1] = 1; vecs[0][3] = 0; vecs[1][3] = 0; if (fabs(plane.normal[2]) < fabs(plane.normal[0])) { if (fabs(plane.normal[0]) < fabs(plane.normal[1])) { // Y primary VectorSet4(tx.vecs[0], cosv*scale[0], 0, sinv*scale[0], vecs[0][3]); VectorSet4(tx.vecs[1], sinv*scale[1], 0, -cosv*scale[1], vecs[1][3]); } else { // X primary VectorSet4(tx.vecs[0], 0, cosv*scale[0], sinv*scale[0], vecs[0][3]); VectorSet4(tx.vecs[1], 0, sinv*scale[1], -cosv*scale[1], vecs[1][3]); } } else if (fabs(plane.normal[2]) < fabs(plane.normal[1])) { // Y primary VectorSet4(tx.vecs[0], cosv*scale[0], 0, sinv*scale[0], vecs[0][3]); VectorSet4(tx.vecs[1], sinv*scale[1], 0, -cosv*scale[1], vecs[1][3]); } else { // Z primary VectorSet4(tx.vecs[0], cosv*scale[0], sinv*scale[0], 0, vecs[0][3]); VectorSet4(tx.vecs[1], sinv*scale[1], -cosv*scale[1], 0, vecs[1][3]); } break; } } /* // LordHavoc: fix for CheckFace: point off plane errors in some maps (most notably QOOLE ones), // and hopefully preventing most 'portal clipped away' warnings VectorNormalize (plane.normal); for (j = 0;j < 3;j++) plane.normal[j] = (Q_rint((vec_t) plane.normal[j] * (vec_t) 8.0)) * (vec_t) (1.0 / 8.0); VectorNormalize (plane.normal); plane.dist = DotProduct (t3, plane.normal); d = (Q_rint(plane.dist * 8.0)) * (1.0 / 8.0); //if (fabs(d - plane.dist) >= (0.4 / 8.0)) // printf("WARNING: line %i: correcting minor math errors in brushface\n", scriptline); plane.dist = d; */ /* VectorNormalize (plane.normal); plane.dist = DotProduct (t3, plane.normal); VectorCopy(plane.normal, v); //for (j = 0;j < 3;j++) // v[j] = (Q_rint((vec_t) v[j] * (vec_t) 32.0)) * (vec_t) (1.0 / 32.0); VectorNormalize (v); d = (Q_rint(DotProduct (t3, v) * 8.0)) * (1.0 / 8.0); // if deviation is too high, warn (frequently happens on QOOLE maps) if (fabs(DotProduct(v, plane.normal) - 1.0) > (0.5 / 32.0) || fabs(d - plane.dist) >= (0.25 / 8.0)) printf("WARNING: line %i: minor misalignment of brushface\n" "normal %f %f %f (l: %f d: %f)\n" "rounded to %f %f %f (l: %f d: %f r: %f)\n", scriptline, (vec_t) plane.normal[0], (vec_t) plane.normal[1], (vec_t) plane.normal[2], (vec_t) sqrt(DotProduct(plane.normal, plane.normal)), (vec_t) DotProduct (t3, plane.normal), (vec_t) v[0], (vec_t) v[1], (vec_t) v[2], (vec_t) sqrt(DotProduct(v, v)), (vec_t) DotProduct(t3, v), (vec_t) d); //VectorCopy(v, plane.normal); //plane.dist = d; */ b = *brushpointer; if (b) { if (brushplane) { for (f2 = b->faces ; f2 ;f2=f2->next) if (VectorCompare(plane.normal, f2->plane.normal) && fabs(plane.dist - f2->plane.dist) < ON_EPSILON) break; if (f2) { printf ("WARNING: line %i: brush with duplicate plane\n", scriptline); return; } } else { // if the three points are all on a previous plane, it is a // duplicate plane for (f2 = b->faces ; f2 ; f2=f2->next) { for (i = 0;i < 3;i++) { d = DotProduct(planepts[i],f2->plane.normal) - f2->plane.dist; if (d < -ON_EPSILON || d > ON_EPSILON) break; } if (i==3) break; } if (f2) { printf ("WARNING: line %i: brush with duplicate plane\n", scriptline); return; } } } else { b = &mapbrushes[nummapbrushes]; nummapbrushes++; b->next = ent->brushes; ent->brushes = b; b->scriptline = scriptline; *brushpointer = b; } f = qmalloc(sizeof(mface_t)); f->next = b->faces; b->faces = f; f->scriptline = scriptline; f->plane = plane; f->texinfo = FindTexinfo (&tx); nummapbrushfaces++; }
/* ============= RB_PostProcess ============= */ const void *RB_PostProcess(const void *data) { const postProcessCommand_t *cmd = data; FBO_t *srcFbo; qboolean autoExposure; // finish any 2D drawing if needed if(tess.numIndexes) RB_EndSurface(); if (!glRefConfig.framebufferObject || !r_postProcess->integer) { // do nothing return (const void *)(cmd + 1); } srcFbo = tr.renderFbo; if (tr.msaaResolveFbo) { // Resolve the MSAA before anything else FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); srcFbo = tr.msaaResolveFbo; } if (r_ssao->integer) { FBO_BlitFromTexture(tr.screenSsaoImage, NULL, NULL, srcFbo, NULL, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); } if (srcFbo) { if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer)) { autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer; RB_ToneMap(srcFbo, autoExposure); } else if (r_cameraExposure->value == 0.0f) { FBO_FastBlit(srcFbo, NULL, tr.screenScratchFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST); } else { vec4_t color; color[0] = color[1] = color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value); color[3] = 1.0f; FBO_Blit(srcFbo, NULL, NULL, tr.screenScratchFbo, NULL, NULL, color, 0); } } if (r_drawSunRays->integer) RB_SunRays(); if (1) RB_BokehBlur(backEnd.refdef.blurFactor); else RB_GaussianBlur(backEnd.refdef.blurFactor); if (0) { vec4i_t dstBox; VectorSet4(dstBox, 0, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 128, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 256, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0); } if (0) { vec4i_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0); } if (0) { vec4i_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0); } backEnd.framePostProcessed = qtrue; return (const void *)(cmd + 1); }
/* ============= RB_PostProcess ============= */ const void *RB_PostProcess(const void *data) { const postProcessCommand_t *cmd = data; FBO_t *srcFbo; ivec4_t srcBox, dstBox; qboolean autoExposure; // finish any 2D drawing if needed if(tess.numIndexes) RB_EndSurface(); if (!glRefConfig.framebufferObject || !r_postProcess->integer) { // do nothing return (const void *)(cmd + 1); } if (cmd) { backEnd.refdef = cmd->refdef; backEnd.viewParms = cmd->viewParms; } srcFbo = tr.renderFbo; if (tr.msaaResolveFbo) { // Resolve the MSAA before anything else // Can't resolve just part of the MSAA FBO, so multiple views will suffer a performance hit here FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); srcFbo = tr.msaaResolveFbo; } dstBox[0] = backEnd.viewParms.viewportX; dstBox[1] = backEnd.viewParms.viewportY; dstBox[2] = backEnd.viewParms.viewportWidth; dstBox[3] = backEnd.viewParms.viewportHeight; if (r_ssao->integer) { srcBox[0] = backEnd.viewParms.viewportX * tr.screenSsaoImage->width / (float)glConfig.vidWidth; srcBox[1] = backEnd.viewParms.viewportY * tr.screenSsaoImage->height / (float)glConfig.vidHeight; srcBox[2] = backEnd.viewParms.viewportWidth * tr.screenSsaoImage->width / (float)glConfig.vidWidth; srcBox[3] = backEnd.viewParms.viewportHeight * tr.screenSsaoImage->height / (float)glConfig.vidHeight; //FBO_BlitFromTexture(tr.screenSsaoImage, srcBox, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); srcBox[1] = tr.screenSsaoImage->height - srcBox[1]; srcBox[3] = -srcBox[3]; FBO_Blit(tr.screenSsaoFbo, srcBox, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO); } srcBox[0] = backEnd.viewParms.viewportX; srcBox[1] = backEnd.viewParms.viewportY; srcBox[2] = backEnd.viewParms.viewportWidth; srcBox[3] = backEnd.viewParms.viewportHeight; if (srcFbo) { if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer) && qglActiveTextureARB) { autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer; RB_ToneMap(srcFbo, srcBox, NULL, dstBox, autoExposure); } else if (r_cameraExposure->value == 0.0f) { FBO_FastBlit(srcFbo, srcBox, NULL, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST); } else { vec4_t color; color[0] = color[1] = color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value); color[3] = 1.0f; FBO_Blit(srcFbo, srcBox, NULL, NULL, dstBox, NULL, color, 0); } } if (r_drawSunRays->integer) RB_SunRays(NULL, srcBox, NULL, dstBox); if (1) RB_BokehBlur(NULL, srcBox, NULL, dstBox, backEnd.refdef.blurFactor); else RB_GaussianBlur(backEnd.refdef.blurFactor); if (0 && r_sunlightMode->integer) { ivec4_t dstBox; VectorSet4(dstBox, 0, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 128, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 256, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 384, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) { ivec4_t dstBox; VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256); FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0); } #if 0 if (r_cubeMapping->integer && tr.numCubemaps) { ivec4_t dstBox; int cubemapIndex = R_CubemapForPoint( backEnd.viewParms.or.origin ); if (cubemapIndex) { VectorSet4(dstBox, 0, glConfig.vidHeight - 256, 256, 256); //FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1], NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0); } } #endif backEnd.framePostProcessed = qtrue; return (const void *)(cmd + 1); }
/* ============= RB_DrawSurfs ============= */ const void *RB_DrawSurfs( const void *data ) { const drawSurfsCommand_t *cmd; // finish any 2D drawing if needed if ( tess.numIndexes ) { RB_EndSurface(); } cmd = (const drawSurfsCommand_t *)data; backEnd.refdef = cmd->refdef; backEnd.viewParms = cmd->viewParms; // clear the z buffer, set the modelview, etc RB_BeginDrawingView (); if (glRefConfig.framebufferObject && (backEnd.viewParms.flags & VPF_DEPTHCLAMP) && glRefConfig.depthClamp) { qglEnable(GL_DEPTH_CLAMP); } if (glRefConfig.framebufferObject && !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL) && (r_depthPrepass->integer || (backEnd.viewParms.flags & VPF_DEPTHSHADOW))) { FBO_t *oldFbo = glState.currentFBO; backEnd.depthFill = qtrue; qglColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); RB_RenderDrawSurfList( cmd->drawSurfs, cmd->numDrawSurfs ); qglColorMask(!backEnd.colorMask[0], !backEnd.colorMask[1], !backEnd.colorMask[2], !backEnd.colorMask[3]); backEnd.depthFill = qfalse; if (tr.msaaResolveFbo) { // If we're using multisampling, resolve the depth first FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_DEPTH_BUFFER_BIT, GL_NEAREST); } else if (tr.renderFbo == NULL) { // If we're rendering directly to the screen, copy the depth to a texture GL_BindToTMU(tr.renderDepthImage, 0); qglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 0, 0, glConfig.vidWidth, glConfig.vidHeight, 0); } if (r_ssao->integer) { // need the depth in a texture we can do GL_LINEAR sampling on, so copy it to an HDR image FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, tr.hdrDepthFbo, NULL, NULL, NULL, 0); } if (r_sunlightMode->integer && backEnd.viewParms.flags & VPF_USESUNLIGHT) { vec4_t quadVerts[4]; vec2_t texCoords[4]; vec4_t box; FBO_Bind(tr.screenShadowFbo); box[0] = backEnd.viewParms.viewportX * tr.screenShadowFbo->width / (float)glConfig.vidWidth; box[1] = backEnd.viewParms.viewportY * tr.screenShadowFbo->height / (float)glConfig.vidHeight; box[2] = backEnd.viewParms.viewportWidth * tr.screenShadowFbo->width / (float)glConfig.vidWidth; box[3] = backEnd.viewParms.viewportHeight * tr.screenShadowFbo->height / (float)glConfig.vidHeight; qglViewport(box[0], box[1], box[2], box[3]); qglScissor(box[0], box[1], box[2], box[3]); box[0] = backEnd.viewParms.viewportX / (float)glConfig.vidWidth; box[1] = backEnd.viewParms.viewportY / (float)glConfig.vidHeight; box[2] = box[0] + backEnd.viewParms.viewportWidth / (float)glConfig.vidWidth; box[3] = box[1] + backEnd.viewParms.viewportHeight / (float)glConfig.vidHeight; texCoords[0][0] = box[0]; texCoords[0][1] = box[3]; texCoords[1][0] = box[2]; texCoords[1][1] = box[3]; texCoords[2][0] = box[2]; texCoords[2][1] = box[1]; texCoords[3][0] = box[0]; texCoords[3][1] = box[1]; box[0] = -1.0f; box[1] = -1.0f; box[2] = 1.0f; box[3] = 1.0f; VectorSet4(quadVerts[0], box[0], box[3], 0, 1); VectorSet4(quadVerts[1], box[2], box[3], 0, 1); VectorSet4(quadVerts[2], box[2], box[1], 0, 1); VectorSet4(quadVerts[3], box[0], box[1], 0, 1); GL_State( GLS_DEPTHTEST_DISABLE ); GLSL_BindProgram(&tr.shadowmaskShader); GL_BindToTMU(tr.renderDepthImage, TB_COLORMAP); if (r_shadowCascadeZFar->integer != 0) { GL_BindToTMU(tr.sunShadowDepthImage[0], TB_SHADOWMAP); GL_BindToTMU(tr.sunShadowDepthImage[1], TB_SHADOWMAP2); GL_BindToTMU(tr.sunShadowDepthImage[2], TB_SHADOWMAP3); GL_BindToTMU(tr.sunShadowDepthImage[3], TB_SHADOWMAP4); GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP, backEnd.refdef.sunShadowMvp[0]); GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP2, backEnd.refdef.sunShadowMvp[1]); GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP3, backEnd.refdef.sunShadowMvp[2]); GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP4, backEnd.refdef.sunShadowMvp[3]); } else { GL_BindToTMU(tr.sunShadowDepthImage[3], TB_SHADOWMAP); GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP, backEnd.refdef.sunShadowMvp[3]); } GLSL_SetUniformVec3(&tr.shadowmaskShader, UNIFORM_VIEWORIGIN, backEnd.refdef.vieworg); { vec4_t viewInfo; vec3_t viewVector; float zmax = backEnd.viewParms.zFar; float ymax = zmax * tan(backEnd.viewParms.fovY * M_PI / 360.0f); float xmax = zmax * tan(backEnd.viewParms.fovX * M_PI / 360.0f); float zmin = r_znear->value; VectorScale(backEnd.refdef.viewaxis[0], zmax, viewVector); GLSL_SetUniformVec3(&tr.shadowmaskShader, UNIFORM_VIEWFORWARD, viewVector); VectorScale(backEnd.refdef.viewaxis[1], xmax, viewVector); GLSL_SetUniformVec3(&tr.shadowmaskShader, UNIFORM_VIEWLEFT, viewVector); VectorScale(backEnd.refdef.viewaxis[2], ymax, viewVector); GLSL_SetUniformVec3(&tr.shadowmaskShader, UNIFORM_VIEWUP, viewVector); VectorSet4(viewInfo, zmax / zmin, zmax, 0.0, 0.0); GLSL_SetUniformVec4(&tr.shadowmaskShader, UNIFORM_VIEWINFO, viewInfo); } RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes); } if (r_ssao->integer) { vec4_t quadVerts[4]; vec2_t texCoords[4]; FBO_Bind(tr.quarterFbo[0]); qglViewport(0, 0, tr.quarterFbo[0]->width, tr.quarterFbo[0]->height); qglScissor(0, 0, tr.quarterFbo[0]->width, tr.quarterFbo[0]->height); VectorSet4(quadVerts[0], -1, 1, 0, 1); VectorSet4(quadVerts[1], 1, 1, 0, 1); VectorSet4(quadVerts[2], 1, -1, 0, 1); VectorSet4(quadVerts[3], -1, -1, 0, 1); texCoords[0][0] = 0; texCoords[0][1] = 1; texCoords[1][0] = 1; texCoords[1][1] = 1; texCoords[2][0] = 1; texCoords[2][1] = 0; texCoords[3][0] = 0; texCoords[3][1] = 0; GL_State( GLS_DEPTHTEST_DISABLE ); GLSL_BindProgram(&tr.ssaoShader); GL_BindToTMU(tr.hdrDepthImage, TB_COLORMAP); { vec4_t viewInfo; float zmax = backEnd.viewParms.zFar; float zmin = r_znear->value; VectorSet4(viewInfo, zmax / zmin, zmax, 0.0, 0.0); GLSL_SetUniformVec4(&tr.ssaoShader, UNIFORM_VIEWINFO, viewInfo); } RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes); FBO_Bind(tr.quarterFbo[1]); qglViewport(0, 0, tr.quarterFbo[1]->width, tr.quarterFbo[1]->height); qglScissor(0, 0, tr.quarterFbo[1]->width, tr.quarterFbo[1]->height); GLSL_BindProgram(&tr.depthBlurShader[0]); GL_BindToTMU(tr.quarterImage[0], TB_COLORMAP); GL_BindToTMU(tr.hdrDepthImage, TB_LIGHTMAP); { vec4_t viewInfo; float zmax = backEnd.viewParms.zFar; float zmin = r_znear->value; VectorSet4(viewInfo, zmax / zmin, zmax, 0.0, 0.0); GLSL_SetUniformVec4(&tr.depthBlurShader[0], UNIFORM_VIEWINFO, viewInfo); } RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes); FBO_Bind(tr.screenSsaoFbo); qglViewport(0, 0, tr.screenSsaoFbo->width, tr.screenSsaoFbo->height); qglScissor(0, 0, tr.screenSsaoFbo->width, tr.screenSsaoFbo->height); GLSL_BindProgram(&tr.depthBlurShader[1]); GL_BindToTMU(tr.quarterImage[1], TB_COLORMAP); GL_BindToTMU(tr.hdrDepthImage, TB_LIGHTMAP); { vec4_t viewInfo; float zmax = backEnd.viewParms.zFar; float zmin = r_znear->value; VectorSet4(viewInfo, zmax / zmin, zmax, 0.0, 0.0); GLSL_SetUniformVec4(&tr.depthBlurShader[1], UNIFORM_VIEWINFO, viewInfo); } RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes); } // reset viewport and scissor FBO_Bind(oldFbo); SetViewportAndScissor(); } if (glRefConfig.framebufferObject && (backEnd.viewParms.flags & VPF_DEPTHCLAMP) && glRefConfig.depthClamp) { qglDisable(GL_DEPTH_CLAMP); } if (!(backEnd.viewParms.flags & VPF_DEPTHSHADOW)) { RB_RenderDrawSurfList( cmd->drawSurfs, cmd->numDrawSurfs ); if (r_drawSun->integer) { RB_DrawSun(0.1, tr.sunShader); } if (r_drawSunRays->integer) { FBO_t *oldFbo = glState.currentFBO; FBO_Bind(tr.sunRaysFbo); qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); qglClear( GL_COLOR_BUFFER_BIT ); if (glRefConfig.occlusionQuery) { tr.sunFlareQueryActive[tr.sunFlareQueryIndex] = qtrue; qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, tr.sunFlareQuery[tr.sunFlareQueryIndex]); } RB_DrawSun(0.3, tr.sunFlareShader); if (glRefConfig.occlusionQuery) { qglEndQueryARB(GL_SAMPLES_PASSED_ARB); } FBO_Bind(oldFbo); } // darken down any stencil shadows RB_ShadowFinish(); // add light flares on lights that aren't obscured RB_RenderFlares(); } if (glRefConfig.framebufferObject && tr.renderCubeFbo && backEnd.viewParms.targetFbo == tr.renderCubeFbo) { FBO_Bind(NULL); GL_SelectTexture(TB_CUBEMAP); GL_BindToTMU(tr.cubemaps[backEnd.viewParms.targetFboCubemapIndex], TB_CUBEMAP); qglGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP); GL_SelectTexture(0); } return (const void *)(cmd + 1); }
void SCR_DrawBigString( int x, int y, const char *s, float alpha, qboolean noColorEscape ) { vector4 color; VectorSet4( &color, 1.0f, 1.0f, 1.0f, alpha ); SCR_DrawStringExt( x, y, BIGCHAR_WIDTH, s, &color, qfalse, noColorEscape ); }
void RB_ShowImages( void ) { int i; image_t *image; float x, y, w, h; vec4_t quadVerts[ 4 ]; int start, end; GLimp_LogComment( "--- RB_ShowImages ---\n" ); if ( !backEnd.projection2D ) { RB_SetGL2D(); } qglClear( GL_COLOR_BUFFER_BIT ); qglFinish(); GL_BindProgram( &tr.genericSingleShader ); GL_Cull( CT_TWO_SIDED ); // set uniforms GLSL_SetUniform_TCGen_Environment( &tr.genericSingleShader, qfalse ); GLSL_SetUniform_ColorGen( &tr.genericSingleShader, CGEN_VERTEX ); GLSL_SetUniform_AlphaGen( &tr.genericSingleShader, AGEN_VERTEX ); if ( glConfig.vboVertexSkinningAvailable ) { GLSL_SetUniform_VertexSkinning( &tr.genericSingleShader, qfalse ); } GLSL_SetUniform_DeformGen( &tr.genericSingleShader, DGEN_NONE ); GLSL_SetUniform_AlphaTest( &tr.genericSingleShader, 0 ); GLSL_SetUniform_ColorTextureMatrix( &tr.genericSingleShader, matrixIdentity ); GL_SelectTexture( 0 ); start = ri.Milliseconds(); for ( i = 0; i < tr.images.currentElements; i++ ) { image = Com_GrowListElement( &tr.images, i ); /* if(image->bits & (IF_RGBA16F | IF_RGBA32F | IF_LA16F | IF_LA32F)) { // don't render float textures using FFP continue; } */ w = glConfig.vidWidth / 20; h = glConfig.vidHeight / 15; x = i % 20 * w; y = i / 20 * h; // show in proportional size in mode 2 if ( r_showImages->integer == 2 ) { w *= image->uploadWidth / 512.0f; h *= image->uploadHeight / 512.0f; } // bind u_ColorMap GL_Bind( image ); VectorSet4( quadVerts[ 0 ], x, y, 0, 1 ); VectorSet4( quadVerts[ 1 ], x + w, y, 0, 1 ); VectorSet4( quadVerts[ 2 ], x + w, y + h, 0, 1 ); VectorSet4( quadVerts[ 3 ], x, y + h, 0, 1 ); Tess_InstantQuad( quadVerts ); /* qglBegin(GL_QUADS); qglVertexAttrib4fARB(ATTR_INDEX_TEXCOORD0, 0, 0, 0, 1); qglVertexAttrib4fARB(ATTR_INDEX_POSITION, x, y, 0, 1); qglVertexAttrib4fARB(ATTR_INDEX_TEXCOORD0, 1, 0, 0, 1); qglVertexAttrib4fARB(ATTR_INDEX_POSITION, x + w, y, 0, 1); qglVertexAttrib4fARB(ATTR_INDEX_TEXCOORD0, 1, 1, 0, 1); qglVertexAttrib4fARB(ATTR_INDEX_POSITION, x + w, y + h, 0, 1); qglVertexAttrib4fARB(ATTR_INDEX_TEXCOORD0, 0, 1, 0, 1); qglVertexAttrib4fARB(ATTR_INDEX_POSITION, x, y + h, 0, 1); qglEnd(); */ } qglFinish(); end = ri.Milliseconds(); ri.Printf( PRINT_ALL, "%i msec to draw all images\n", end - start ); GL_CheckErrors(); }
static void DrawSkySideInner( struct image_s *image, const int mins[2], const int maxs[2] ) { int s, t; int firstVertex = tess.numVertexes; //int firstIndex = tess.numIndexes; int minIndex = tess.minIndex; int maxIndex = tess.maxIndex; vec4_t color; //tess.numVertexes = 0; //tess.numIndexes = 0; tess.firstIndex = tess.numIndexes; GL_Bind( image ); GL_Cull( CT_TWO_SIDED ); for ( t = mins[1]+HALF_SKY_SUBDIVISIONS; t <= maxs[1]+HALF_SKY_SUBDIVISIONS; t++ ) { for ( s = mins[0]+HALF_SKY_SUBDIVISIONS; s <= maxs[0]+HALF_SKY_SUBDIVISIONS; s++ ) { tess.xyz[tess.numVertexes][0] = s_skyPoints[t][s][0]; tess.xyz[tess.numVertexes][1] = s_skyPoints[t][s][1]; tess.xyz[tess.numVertexes][2] = s_skyPoints[t][s][2]; tess.xyz[tess.numVertexes][3] = 1.0; tess.texCoords[tess.numVertexes][0][0] = s_skyTexCoords[t][s][0]; tess.texCoords[tess.numVertexes][0][1] = s_skyTexCoords[t][s][1]; tess.numVertexes++; if(tess.numVertexes >= SHADER_MAX_VERTEXES) { ri.Error(ERR_DROP, "SHADER_MAX_VERTEXES hit in DrawSkySideVBO()\n"); } } } for ( t = 0; t < maxs[1] - mins[1]; t++ ) { for ( s = 0; s < maxs[0] - mins[0]; s++ ) { if (tess.numIndexes + 6 >= SHADER_MAX_INDEXES) { ri.Error(ERR_DROP, "SHADER_MAX_INDEXES hit in DrawSkySideVBO()\n"); } tess.indexes[tess.numIndexes++] = s + t * (maxs[0] - mins[0] + 1) + firstVertex; tess.indexes[tess.numIndexes++] = s + (t + 1) * (maxs[0] - mins[0] + 1) + firstVertex; tess.indexes[tess.numIndexes++] = (s + 1) + t * (maxs[0] - mins[0] + 1) + firstVertex; tess.indexes[tess.numIndexes++] = (s + 1) + t * (maxs[0] - mins[0] + 1) + firstVertex; tess.indexes[tess.numIndexes++] = s + (t + 1) * (maxs[0] - mins[0] + 1) + firstVertex; tess.indexes[tess.numIndexes++] = (s + 1) + (t + 1) * (maxs[0] - mins[0] + 1) + firstVertex; } } tess.minIndex = firstVertex; tess.maxIndex = tess.numVertexes; // FIXME: A lot of this can probably be removed for speed, and refactored into a more convenient function RB_UpdateTessVao(ATTR_POSITION | ATTR_TEXCOORD); /* { shaderProgram_t *sp = &tr.textureColorShader; GLSL_BindProgram(sp); GLSL_SetUniformMat4(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); color[0] = color[1] = color[2] = tr.identityLight; color[3] = 1.0f; GLSL_SetUniformVec4(sp, UNIFORM_COLOR, color); } */ { shaderProgram_t *sp = &tr.lightallShader[0]; vec4_t vector; GLSL_BindProgram(sp); GLSL_SetUniformMat4(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection); color[0] = color[1] = color[2] = backEnd.refdef.colorScale; color[3] = 1.0f; GLSL_SetUniformVec4(sp, UNIFORM_BASECOLOR, color); color[0] = color[1] = color[2] = color[3] = 0.0f; GLSL_SetUniformVec4(sp, UNIFORM_VERTCOLOR, color); VectorSet4(vector, 1.0, 0.0, 0.0, 1.0); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXMATRIX, vector); VectorSet4(vector, 0.0, 0.0, 0.0, 0.0); GLSL_SetUniformVec4(sp, UNIFORM_DIFFUSETEXOFFTURB, vector); } R_DrawElementsVao(tess.numIndexes - tess.firstIndex, tess.firstIndex, tess.minIndex, tess.maxIndex); //qglDrawElements(GL_TRIANGLES, tess.numIndexes - tess.firstIndex, GL_INDEX_TYPE, BUFFER_OFFSET(tess.firstIndex * sizeof(glIndex_t))); //R_BindNullVBO(); //R_BindNullIBO(); tess.numIndexes = tess.firstIndex; tess.numVertexes = firstVertex; tess.firstIndex = 0; tess.minIndex = minIndex; tess.maxIndex = maxIndex; }