openmohaa/code/renderer/tr_draw.c

406 lines
8.8 KiB
C
Raw Normal View History

2023-05-08 14:33:37 +02:00
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of Quake III Arena source code.
Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// tr_draw.c -- drawing
#include "tr_local.h"
vec4_t r_colorWhite = { 1.0, 1.0, 1.0, 1.0 };
/*
================
Draw_SetColor
================
*/
void Draw_SetColor(const vec4_t rgba) {
2023-05-08 14:33:37 +02:00
#if 1
if (!rgba) {
2023-05-08 14:33:37 +02:00
rgba = r_colorWhite;
}
backEnd.color2D[0] = (byte)(rgba[0] * tr.identityLightByte);
backEnd.color2D[1] = (byte)(rgba[1] * tr.identityLightByte);
backEnd.color2D[2] = (byte)(rgba[2] * tr.identityLightByte);
backEnd.color2D[3] = (byte)(rgba[3] * 255.0);
qglColor4ubv(backEnd.color2D);
2023-05-08 14:33:37 +02:00
#else
RE_SetColor(rgba);
2023-05-08 14:33:37 +02:00
#endif
}
/*
================
Draw_StretchPic
================
*/
void Draw_StretchPic(float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader) {
2023-05-08 14:33:37 +02:00
#if 1
shader_t* shader;
2023-05-08 14:33:37 +02:00
R_SyncRenderThread();
if (hShader) {
shader = R_GetShaderByHandle(hShader);
}
else {
2023-05-08 14:33:37 +02:00
shader = tr.defaultShader;
}
if (w <= 0) {
w = shader->unfoggedStages[0]->bundle[0].image[0]->width;
h = shader->unfoggedStages[0]->bundle[0].image[0]->height;
2023-05-08 14:33:37 +02:00
}
// draw the pic
RB_Color4f(backEnd.color2D[0], backEnd.color2D[1], backEnd.color2D[2], backEnd.color2D[3]);
RB_BeginSurface(shader);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f(s1, t1);
RB_Vertex2f(x, y);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f(s2, t1);
RB_Vertex2f(x + w, y);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f(s1, t2);
RB_Vertex2f(x, y + h);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f(s2, t2);
RB_Vertex2f(x + w, y + h);
2023-05-08 14:33:37 +02:00
RB_StreamEnd();
#else
RE_StretchPic(x, y, w, h, s1, t1, s2, t2, hShader);
2023-05-08 14:33:37 +02:00
#endif
}
/*
================
Draw_TilePic
================
*/
void Draw_TilePic(float x, float y, float w, float h, qhandle_t hShader) {
shader_t* shader;
2023-05-08 14:33:37 +02:00
float picw, pich;
R_SyncRenderThread();
if (hShader) {
shader = R_GetShaderByHandle(hShader);
2023-05-08 14:33:37 +02:00
}
else {
shader = tr.defaultShader;
}
if (w <= 0) {
w = shader->unfoggedStages[0]->bundle[0].image[0]->width;
h = shader->unfoggedStages[0]->bundle[0].image[0]->height;
2023-05-08 14:33:37 +02:00
}
picw = shader->unfoggedStages[0]->bundle[0].image[0]->uploadWidth;
pich = shader->unfoggedStages[0]->bundle[0].image[0]->uploadHeight;
2023-05-08 14:33:37 +02:00
// draw the pic
RB_Color4f(backEnd.color2D[0], backEnd.color2D[1], backEnd.color2D[2], backEnd.color2D[3]);
2023-05-08 14:33:37 +02:00
RB_StreamBegin(shader);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f(x / picw, y / pich);
RB_Vertex2f(x, y);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f((x + w) / picw, y / pich);
RB_Vertex2f(x + w, y);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f(x / picw, (y + h) / pich);
RB_Vertex2f(x, y + h);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f((x + w) / picw, (y + h) / pich);
RB_Vertex2f(x + w, y + h);
2023-05-08 14:33:37 +02:00
RB_StreamEnd();
}
/*
================
Draw_TilePicOffset
================
*/
void Draw_TilePicOffset(float x, float y, float w, float h, qhandle_t hShader, int offsetX, int offsetY) {
shader_t* shader;
2023-05-08 14:33:37 +02:00
float picw, pich;
R_SyncRenderThread();
if (hShader) {
shader = R_GetShaderByHandle(hShader);
}
else {
2023-05-08 14:33:37 +02:00
shader = tr.defaultShader;
}
if (w <= 0) {
w = shader->unfoggedStages[0]->bundle[0].image[0]->width;
h = shader->unfoggedStages[0]->bundle[0].image[0]->height;
2023-05-08 14:33:37 +02:00
}
picw = shader->unfoggedStages[0]->bundle[0].image[0]->uploadWidth;
pich = shader->unfoggedStages[0]->bundle[0].image[0]->uploadHeight;
2023-05-08 14:33:37 +02:00
// draw the pic
RB_Color4f(backEnd.color2D[0], backEnd.color2D[1], backEnd.color2D[2], backEnd.color2D[3]);
2023-05-08 14:33:37 +02:00
RB_StreamBegin(shader);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f(x / picw, y / pich);
RB_Vertex2f(x + offsetX, y + offsetY);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f((x + w) / picw, y / pich);
RB_Vertex2f(x + offsetX + w, y + offsetY);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f(x / picw, (y + h) / pich);
RB_Vertex2f(x + offsetX, y + offsetY + h);
2023-05-08 14:33:37 +02:00
RB_Texcoord2f((x + w) / picw, (y + h) / pich);
RB_Vertex2f(x + offsetX + w, y + offsetY + h);
2023-05-08 14:33:37 +02:00
RB_StreamEnd();
}
/*
================
Draw_TrianglePic
================
*/
void Draw_TrianglePic(const vec2_t vPoints[3], const vec2_t vTexCoords[3], qhandle_t hShader) {
2023-05-08 14:33:37 +02:00
int i;
shader_t* shader;
2023-05-08 14:33:37 +02:00
R_SyncRenderThread();
if (hShader) {
shader = R_GetShaderByHandle(hShader);
}
else {
2023-05-08 14:33:37 +02:00
shader = tr.defaultShader;
}
// draw the pic
RB_Color4f(backEnd.color2D[0], backEnd.color2D[1], backEnd.color2D[2], backEnd.color2D[3]);
2023-05-08 14:33:37 +02:00
RB_BeginSurface(shader);
2023-05-08 14:33:37 +02:00
for (i = 0; i < 3; i++) {
RB_Texcoord2f(vTexCoords[i][0], vTexCoords[i][1]);
RB_Vertex2f(vPoints[i][0], vPoints[i][1]);
2023-05-08 14:33:37 +02:00
}
RB_StreamEnd();
}
/*
================
RE_DrawBackground_TexSubImage
================
*/
void RE_DrawBackground_TexSubImage(int cols, int rows, int bgr, byte* data) {
2023-05-08 14:33:37 +02:00
GLenum format;
int w, h;
w = glConfig.vidWidth;
h = glConfig.vidHeight;
R_SyncRenderThread();
qglFinish();
if (bgr) {
2023-05-08 14:33:37 +02:00
format = GL_BGR_EXT;
}
else {
2023-05-08 14:33:37 +02:00
format = GL_RGB;
}
2023-05-20 19:33:16 +02:00
GL_Bind(tr.scratchImage);
2023-05-08 14:33:37 +02:00
2023-05-20 19:33:16 +02:00
if (cols == tr.scratchImage->width && rows == tr.scratchImage->height && format == tr.scratchImage->internalFormat)
2023-05-08 14:33:37 +02:00
{
qglTexSubImage2D(3553, 0, 0, 0, cols, rows, format, 5121, data);
2023-05-08 14:33:37 +02:00
}
else
{
2023-05-20 19:33:16 +02:00
tr.scratchImage->uploadWidth = cols;
tr.scratchImage->uploadHeight = rows;
tr.scratchImage->internalFormat = format;
qglTexImage2D(GL_TEXTURE_2D, 0, 3, cols, rows, 0, format, 5121, data);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 9729.0);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 9729.0);
2023-05-08 14:33:37 +02:00
}
qglDisable(GL_CULL_FACE);
qglDisable(GL_DEPTH_TEST);
qglEnable(GL_TEXTURE_2D);
2023-05-08 14:33:37 +02:00
qglBegin(GL_QUADS);
2023-05-08 14:33:37 +02:00
qglTexCoord2f(0.5 / (GLfloat)cols, ((GLfloat)rows - 0.5) / rows);
qglVertex2f(0, 0);
2023-05-08 14:33:37 +02:00
qglTexCoord2f(((GLfloat)cols - 0.5) / cols, ((GLfloat)rows - 0.5) / rows);
qglVertex2f(w, 0);
2023-05-08 14:33:37 +02:00
qglTexCoord2f(((GLfloat)cols - 0.5) / cols, 0.5 / (GLfloat)rows);
qglVertex2f(w, h);
2023-05-08 14:33:37 +02:00
qglTexCoord2f(0.5 / (GLfloat)rows, 0.5 / (GLfloat)rows);
qglVertex2f(0, h);
2023-05-08 14:33:37 +02:00
qglEnd();
}
/*
================
RE_DrawBackground_DrawPixels
================
*/
void RE_DrawBackground_DrawPixels(int cols, int rows, int bgr, byte* data) {
2023-05-08 14:33:37 +02:00
// FIXME: stub
}
/*
================
AddBox
================
*/
void AddBox(float x, float y, float w, float h) {
2023-05-08 14:33:37 +02:00
R_SyncRenderThread();
qglColor4ubv(backEnd.color2D);
qglDisable(GL_TEXTURE_2D);
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE);
2023-05-08 14:33:37 +02:00
qglBegin(GL_QUADS);
2023-05-08 14:33:37 +02:00
qglVertex2f(x, y);
qglVertex2f(x + w, y);
qglVertex2f(x + w, y + h);
qglVertex2f(x, y + h);
2023-05-08 14:33:37 +02:00
qglEnd();
qglEnable(GL_TEXTURE_2D);
2023-05-08 14:33:37 +02:00
}
/*
================
DrawBox
================
*/
void DrawBox(float x, float y, float w, float h) {
2023-05-08 14:33:37 +02:00
R_SyncRenderThread();
qglColor4ubv(backEnd.color2D);
qglDisable(GL_TEXTURE_2D);
GL_State(GLS_DEPTHTEST_DISABLE | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_SRCBLEND_SRC_ALPHA);
2023-05-08 14:33:37 +02:00
qglBegin(GL_QUADS);
2023-05-08 14:33:37 +02:00
qglVertex2f(x, y);
qglVertex2f(x + w, y);
qglVertex2f(x + w, y + h);
qglVertex2f(x, y + h);
2023-05-08 14:33:37 +02:00
qglEnd();
qglEnable(GL_TEXTURE_2D);
2023-05-08 14:33:37 +02:00
}
/*
================
DrawLineLoop
================
*/
void DrawLineLoop(const vec2_t* points, int count, int stipple_factor, int stipple_mask) {
2023-05-08 14:33:37 +02:00
int i;
R_SyncRenderThread();
qglDisable(GL_TEXTURE_2D);
2023-05-08 14:33:37 +02:00
if (stipple_factor) {
qglEnable(GL_LINE_STIPPLE);
2023-05-26 23:32:27 +02:00
glLineStipple(stipple_factor, stipple_mask);
2023-05-08 14:33:37 +02:00
}
qglBegin(GL_LINE_LOOP);
2023-05-08 14:33:37 +02:00
for (i = 0; i < count; i++) {
2023-05-26 23:32:27 +02:00
qglVertex2f(points[i][0], points[i][1]);
2023-05-08 14:33:37 +02:00
}
qglEnd();
qglEnable(GL_TEXTURE_2D);
2023-05-08 14:33:37 +02:00
if (stipple_factor) {
qglDisable(GL_LINE_STIPPLE);
2023-05-08 14:33:37 +02:00
}
}
/*
================
Set2DWindow
================
*/
void Set2DWindow(int x, int y, int w, int h, float left, float right, float bottom, float top, float n, float f) {
2023-05-15 17:27:05 +02:00
R_SyncRenderThread();
qglViewport(x, y, w, h);
qglScissor(x, y, w, h);
qglMatrixMode(GL_PROJECTION);
qglLoadIdentity();
qglOrtho(left, right, bottom, top, n, f);
qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity();
GL_State(GLS_DEPTHTEST_DISABLE | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_SRCBLEND_SRC_ALPHA);
2023-05-15 17:27:05 +02:00
qglEnable(GL_BLEND);
qglDisable(GL_CULL_FACE);
qglDisable(GL_CLIP_PLANE0);
if (r_reset_tc_array->integer) {
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
if (!backEnd.in2D)
{
backEnd.refdef.time = ri.Milliseconds();
2023-05-15 21:33:25 +02:00
backEnd.in2D = qtrue;
2023-05-15 17:27:05 +02:00
backEnd.refdef.floatTime = backEnd.refdef.time / 1000.0;
}
2023-05-08 14:33:37 +02:00
}
/*
================
RE_Scissor
================
*/
void RE_Scissor(int x, int y, int width, int height) {
qglEnable(GL_SCISSOR_TEST);
qglScissor(x, y, width, height);
2023-05-08 14:33:37 +02:00
}