1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 //
21 // rf_2d.c
22 //
23
24 #include "rf_local.h"
25
26 /*
27 ===============================================================================
28
29 2D HANDLING
30
31 ===============================================================================
32 */
33
34 static mesh_t rb_2DMesh;
35 static meshBuffer_t rb_2DMBuffer;
36
37 static vec3_t rb_2DVertices[4];
38 static vec3_t rb_2DNormals[4] = { {0,1,0}, {0,1,0}, {0,1,0}, {0,1,0} };
39 static vec2_t rb_2DTexCoords[4];
40 static bvec4_t rb_2DColors[4];
41
42 /*
43 =============
44 R_DrawPic
45 =============
46 */
R_DrawPic(shader_t * shader,float shaderTime,float x,float y,int w,int h,float s1,float t1,float s2,float t2,vec4_t color)47 void R_DrawPic (shader_t *shader, float shaderTime, float x, float y, int w, int h, float s1, float t1, float s2, float t2, vec4_t color)
48 {
49 meshFeatures_t features;
50 int bColor;
51
52 if (!shader)
53 return;
54
55 // FIXME: Normalize and FloatToByte?
56 rb_2DColors[0][0] = (color[0] * 255);
57 rb_2DColors[0][1] = (color[1] * 255);
58 rb_2DColors[0][2] = (color[2] * 255);
59 rb_2DColors[0][3] = (color[3] * 255);
60 bColor = *(int *)rb_2DColors[0];
61
62 rb_2DVertices[0][0] = x;
63 rb_2DVertices[0][1] = y;
64 rb_2DTexCoords[0][0] = s1;
65 rb_2DTexCoords[0][1] = t1;
66
67 rb_2DVertices[1][0] = x+w;
68 rb_2DVertices[1][1] = y;
69 rb_2DTexCoords[1][0] = s2;
70 rb_2DTexCoords[1][1] = t1;
71 *(int *)rb_2DColors[1] = bColor;
72
73 rb_2DVertices[2][0] = x+w;
74 rb_2DVertices[2][1] = y+h;
75 rb_2DTexCoords[2][0] = s2;
76 rb_2DTexCoords[2][1] = t2;
77 *(int *)rb_2DColors[2] = bColor;
78
79 rb_2DVertices[3][0] = x;
80 rb_2DVertices[3][1] = y+h;
81 rb_2DTexCoords[3][0] = s1;
82 rb_2DTexCoords[3][1] = t2;
83 *(int *)rb_2DColors[3] = bColor;
84
85 rb_2DMBuffer.shader = shader;
86 rb_2DMBuffer.shaderTime = shaderTime;
87
88 features = MF_TRIFAN|shader->features;
89 if (gl_shownormals->intVal)
90 features |= MF_NORMALS;
91 // if (!(shader->flags & SHADER_ENTITY_MERGABLE) || r_debugBatching->intVal == 2)
92 features |= MF_NONBATCHED;
93
94 RB_PushMesh (&rb_2DMesh, features);
95 RB_RenderMeshBuffer (&rb_2DMBuffer, qFalse);
96 }
97
98
99 /*
100 =============
101 R_DrawRectangle
102 =============
103 */
R_DrawRectangle(shader_t * shader,float shaderTime,vec2_t tl,vec2_t tr,vec2_t br,vec2_t bl,float s1,float t1,float s2,float t2,vec4_t color)104 void R_DrawRectangle (shader_t *shader, float shaderTime, vec2_t tl, vec2_t tr, vec2_t br, vec2_t bl, float s1, float t1, float s2, float t2, vec4_t color)
105 {
106 meshFeatures_t features;
107 int bColor;
108
109 if (!shader)
110 return;
111
112 // FIXME: Normalize and FloatToByte?
113 rb_2DColors[0][0] = (color[0] * 255);
114 rb_2DColors[0][1] = (color[1] * 255);
115 rb_2DColors[0][2] = (color[2] * 255);
116 rb_2DColors[0][3] = (color[3] * 255);
117 bColor = *(int *)rb_2DColors[0];
118
119 rb_2DVertices[0][0] = tl[0];
120 rb_2DVertices[0][1] = tl[1];
121 rb_2DTexCoords[0][0] = s1;
122 rb_2DTexCoords[0][1] = t1;
123
124 rb_2DVertices[1][0] = tr[0];
125 rb_2DVertices[1][1] = tr[1];
126 rb_2DTexCoords[1][0] = s2;
127 rb_2DTexCoords[1][1] = t1;
128 *(int *)rb_2DColors[1] = bColor;
129
130 rb_2DVertices[2][0] = br[0];
131 rb_2DVertices[2][1] = br[1];
132 rb_2DTexCoords[2][0] = s2;
133 rb_2DTexCoords[2][1] = t2;
134 *(int *)rb_2DColors[2] = bColor;
135
136 rb_2DVertices[3][0] = bl[0];
137 rb_2DVertices[3][1] = bl[1];
138 rb_2DTexCoords[3][0] = s1;
139 rb_2DTexCoords[3][1] = t2;
140 *(int *)rb_2DColors[3] = bColor;
141
142 rb_2DMBuffer.shader = shader;
143 rb_2DMBuffer.shaderTime = shaderTime;
144
145 features = MF_TRIFAN|shader->features;
146 if (gl_shownormals->intVal)
147 features |= MF_NORMALS;
148 // if (!(shader->flags & SHADER_ENTITY_MERGABLE) || r_debugBatching->intVal == 2)
149 features |= MF_NONBATCHED;
150
151 RB_PushMesh (&rb_2DMesh, features);
152 RB_RenderMeshBuffer (&rb_2DMBuffer, qFalse);
153 }
154
155 /*
156 ===============================================================================
157
158 INIT / SHUTDOWN
159
160 ===============================================================================
161 */
162
163 /*
164 =============
165 RF_2DInit
166 =============
167 */
RF_2DInit(void)168 void RF_2DInit (void)
169 {
170 rb_2DVertices[0][2] = 1;
171 rb_2DVertices[1][2] = 1;
172 rb_2DVertices[2][2] = 1;
173 rb_2DVertices[3][2] = 1;
174
175 rb_2DMesh.numIndexes = 0;
176 rb_2DMesh.numVerts = 4;
177
178 rb_2DMesh.colorArray = rb_2DColors;
179 rb_2DMesh.coordArray = rb_2DTexCoords;
180 rb_2DMesh.indexArray = NULL;
181 rb_2DMesh.lmCoordArray = NULL;
182 rb_2DMesh.normalsArray = rb_2DNormals;
183 rb_2DMesh.sVectorsArray = NULL;
184 rb_2DMesh.tVectorsArray = NULL;
185 rb_2DMesh.trNeighborsArray = NULL;
186 rb_2DMesh.trNormalsArray = NULL;
187 rb_2DMesh.vertexArray = rb_2DVertices;
188
189 rb_2DMBuffer.sortKey = 0;
190 rb_2DMBuffer.entity = ri.scn.defaultEntity;
191 rb_2DMBuffer.mesh = NULL;
192 }
193