summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2013-03-06 00:54:56 -0800
committerTim Angus <tim@ngus.net>2013-03-19 16:41:15 +0000
commit691a93f6decc07b9ec726b49ca01a7f87340060f (patch)
tree90706be4a1b26d10cc2bb912faa4c091afe81c31
parent1e92fa878eb7efc180ce62b74de5ff3e59f3ea37 (diff)
Simplify RE_StretchRaw() with RE_UploadCinematic() and RB_InstantQuad2().
-rw-r--r--src/renderergl2/tr_backend.c110
-rw-r--r--src/renderergl2/tr_extramath.h1
2 files changed, 18 insertions, 93 deletions
diff --git a/src/renderergl2/tr_backend.c b/src/renderergl2/tr_backend.c
index db517103..bc11001c 100644
--- a/src/renderergl2/tr_backend.c
+++ b/src/renderergl2/tr_backend.c
@@ -844,8 +844,9 @@ 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;
- shaderProgram_t *sp = &tr.textureColorShader;
vec4_t color;
+ vec4_t quadVerts[4];
+ vec2_t texCoords[4];
if ( !tr.registered ) {
return;
@@ -869,24 +870,7 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
ri.Error (ERR_DROP, "Draw_StretchRaw: size not a power of 2: %i by %i", cols, rows);
}
- GL_Bind( tr.scratchImage[client] );
-
- // if the scratchImage isn't in the format we want, specify it as a new texture
- if ( cols != tr.scratchImage[client]->width || rows != tr.scratchImage[client]->height ) {
- tr.scratchImage[client]->width = tr.scratchImage[client]->uploadWidth = cols;
- tr.scratchImage[client]->height = tr.scratchImage[client]->uploadHeight = rows;
- qglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, cols, rows, 0, GL_RGBA, GL_UNSIGNED_BYTE, data );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
- } else {
- if (dirty) {
- // otherwise, just subimage upload it so that drivers can tell we are going to be changing
- // it and don't try and do a texture compression
- qglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, cols, rows, GL_RGBA, GL_UNSIGNED_BYTE, data );
- }
- }
+ RE_UploadCinematic (w, h, cols, rows, data, client, dirty);
if ( r_speeds->integer ) {
end = ri.Milliseconds();
@@ -908,84 +892,24 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
RB_SetGL2D();
- tess.numIndexes = 0;
- tess.numVertexes = 0;
- tess.firstIndex = 0;
- tess.minIndex = 0;
- tess.maxIndex = 0;
-
- tess.xyz[tess.numVertexes][0] = x;
- tess.xyz[tess.numVertexes][1] = y;
- tess.xyz[tess.numVertexes][2] = 0;
- tess.xyz[tess.numVertexes][3] = 1;
- tess.texCoords[tess.numVertexes][0][0] = 0.5f / cols;
- tess.texCoords[tess.numVertexes][0][1] = 0.5f / rows;
- tess.texCoords[tess.numVertexes][1][0] = 0;
- tess.texCoords[tess.numVertexes][1][1] = 1;
- tess.numVertexes++;
-
- tess.xyz[tess.numVertexes][0] = x + w;
- tess.xyz[tess.numVertexes][1] = y;
- tess.xyz[tess.numVertexes][2] = 0;
- tess.xyz[tess.numVertexes][3] = 1;
- tess.texCoords[tess.numVertexes][0][0] = (cols - 0.5f) / cols;
- tess.texCoords[tess.numVertexes][0][1] = 0.5f / rows;
- tess.texCoords[tess.numVertexes][1][0] = 0;
- tess.texCoords[tess.numVertexes][1][1] = 1;
- tess.numVertexes++;
-
- tess.xyz[tess.numVertexes][0] = x + w;
- tess.xyz[tess.numVertexes][1] = y + h;
- tess.xyz[tess.numVertexes][2] = 0;
- tess.xyz[tess.numVertexes][3] = 1;
- tess.texCoords[tess.numVertexes][0][0] = (cols - 0.5f) / cols;
- tess.texCoords[tess.numVertexes][0][1] = (rows - 0.5f) / rows;
- tess.texCoords[tess.numVertexes][1][0] = 0;
- tess.texCoords[tess.numVertexes][1][1] = 1;
- tess.numVertexes++;
-
- tess.xyz[tess.numVertexes][0] = x;
- tess.xyz[tess.numVertexes][1] = y + h;
- tess.xyz[tess.numVertexes][2] = 0;
- tess.xyz[tess.numVertexes][3] = 1;
- tess.texCoords[tess.numVertexes][0][0] = 0.5f / cols;
- tess.texCoords[tess.numVertexes][0][1] = (rows - 0.5f) / rows;
- tess.texCoords[tess.numVertexes][1][0] = 0;
- tess.texCoords[tess.numVertexes][1][1] = 1;
- tess.numVertexes++;
-
- tess.indexes[tess.numIndexes++] = 0;
- tess.indexes[tess.numIndexes++] = 1;
- tess.indexes[tess.numIndexes++] = 2;
- tess.indexes[tess.numIndexes++] = 0;
- tess.indexes[tess.numIndexes++] = 2;
- tess.indexes[tess.numIndexes++] = 3;
- tess.minIndex = 0;
- tess.maxIndex = 3;
-
- // FIXME: A lot of this can probably be removed for speed, and refactored into a more convenient function
- RB_UpdateVBOs(ATTR_POSITION | ATTR_TEXCOORD);
-
- sp = &tr.textureColorShader;
+ 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);
- GLSL_VertexAttribsState(ATTR_POSITION | ATTR_TEXCOORD);
-
- GLSL_BindProgram(sp);
+ 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_SetUniformMatrix16(sp, TEXTURECOLOR_UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
- VectorSet4(color, 1, 1, 1, 1);
- GLSL_SetUniformVec4(sp, TEXTURECOLOR_UNIFORM_COLOR, color);
+ VectorSet4(color, 1.0f, 1.0f, 1.0f, 1.0f);
- R_DrawElementsVBO(tess.numIndexes, tess.firstIndex, tess.minIndex, tess.maxIndex);
+ GLSL_BindProgram(&tr.textureColorShader);
- //R_BindNullVBO();
- //R_BindNullIBO();
-
- tess.numIndexes = 0;
- tess.numVertexes = 0;
- tess.firstIndex = 0;
- tess.minIndex = 0;
- tess.maxIndex = 0;
+ GLSL_SetUniformMatrix16(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
+ GLSL_SetUniformVec4(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_COLOR, color);
+
+ RB_InstantQuad2(quadVerts, texCoords);
}
void RE_UploadCinematic (int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty) {
diff --git a/src/renderergl2/tr_extramath.h b/src/renderergl2/tr_extramath.h
index bd2982ed..509521fa 100644
--- a/src/renderergl2/tr_extramath.h
+++ b/src/renderergl2/tr_extramath.h
@@ -42,6 +42,7 @@ void Matrix16View(vec3_t axes[3], vec3_t origin, matrix_t out);
void Matrix16SimpleInverse( const matrix_t in, matrix_t out);
#define VectorCopy2(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1])
+#define VectorSet2(v,x,y) ((v)[0]=(x),(v)[1]=(y));
#define VectorCopy4(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
#define VectorSet4(v,x,y,z,w) ((v)[0]=(x),(v)[1]=(y),(v)[2]=(z),(v)[3]=(w))