Debian Codegraph @

renderer/HardwareTransforms.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * 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, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "3d.h"cxx . . $ `<file>/lib/3d.h`/
20 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
21 #include "HardwareInternal.h"cxx . . $ `<file>/renderer/HardwareInternal.h`/
22 #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/
23 #include <string.h>
24
25 // Whether or not to use T&L transforms or the pass-thru ones
26 static int sUseTransformPassthrucxx . . $ sUseTransformPassthru. = -1;
27
28 extern float Z_biascxx . . $ Z_bias.;
29 void g3_GetModelViewMatrixcxx . . $ g3_GetModelViewMatrix(f698744c99c0df38).(const vectorcxx . . $ vector# *viewPos, const matrixcxx . . $ matrix# *viewMatrix, float *mvMat) {
30 matrixcxx . . $ matrix# localOrient = (*viewMatrix);
31 vectorcxx . . $ vector# localPos = -cxx . . $ operator-(9e07539e219c6f20).(*viewPos);
32 mvMat[0] = localOrient.rveccxx . . $ matrix#rvec..xcxx . . $ vector#x.;
33 mvMat[1] = localOrient.uveccxx . . $ matrix#uvec..xcxx . . $ vector#x.;
34 mvMat[2] = localOrient.fveccxx . . $ matrix#fvec..xcxx . . $ vector#x.;
35 mvMat[3] = 0.0f;
36 mvMat[4] = localOrient.rveccxx . . $ matrix#rvec..ycxx . . $ vector#y.;
37 mvMat[5] = localOrient.uveccxx . . $ matrix#uvec..ycxx . . $ vector#y.;
38 mvMat[6] = localOrient.fveccxx . . $ matrix#fvec..ycxx . . $ vector#y.;
39 mvMat[7] = 0.0f;
40 mvMat[8] = localOrient.rveccxx . . $ matrix#rvec..zcxx . . $ vector#z.;
41 mvMat[9] = localOrient.uveccxx . . $ matrix#uvec..zcxx . . $ vector#z.;
42 mvMat[10] = localOrient.fveccxx . . $ matrix#fvec..zcxx . . $ vector#z.;
43 mvMat[11] = 0.0f;
44 mvMat[12] = localPos *cxx . . $ `operator*`(4a721543d64e126a). localOrient.rveccxx . . $ matrix#rvec.;
45 mvMat[13] = localPos *cxx . . $ `operator*`(4a721543d64e126a). localOrient.uveccxx . . $ matrix#uvec.;
46 mvMat[14] = localPos *cxx . . $ `operator*`(4a721543d64e126a). localOrient.fveccxx . . $ matrix#fvec. + Z_biascxx . . $ Z_bias.;
47 mvMat[15] = 1.0f;
48 }
49
50 void g3_TransformVertcxx . . $ g3_TransformVert(f8d5765aeee8bc35).(float res[4], float pt[4], float a[4][4]) {
51 int y;
52 for (y = 0; y < 4; ++y) {
53 res[y] = (pt[0] * a[0][y]) + (pt[1] * a[1][y]) + (pt[2] * a[2][y]) + (pt[3] * a[3][y]);
54 }
55 }
56
57 void g3_TransformMultcxx . . $ g3_TransformMult(893694c8b8ecb2b3).(float res[4][4], float a[4][4], float b[4][4]) {
58 float temp[4][4];
59
60 int x, y;
61 for (y = 0; y < 4; ++y) {
62 for (x = 0; x < 4; ++x) {
63 temp[y][x] = (a[y][0] * b[0][x]) + (a[y][1] * b[1][x]) + (a[y][2] * b[2][x]) + (a[y][3] * b[3][x]);
64 }
65 }
66 memcpy(res, temp, 16 * sizeof(float));
67 }
68
69 void g3_TransformTranscxx . . $ g3_TransformTrans(c276010c1ec1d768).(float res[4][4], float t[4][4]) {
70 float temp[4][4];
71 int y;
72 for (y = 0; y < 4; ++y) {
73 int x;
74 for (x = 0; x < 4; ++x) {
75 temp[x][y] = t[y][x];
76 }
77 }
78 memcpy(res, temp, 16 * sizeof(float));
79 }
80
81 void g3_UpdateFullTransformcxx . . $ g3_UpdateFullTransform(49f6e7a06ebc5aa8).() {
82 // ModelView -> projection
83 g3_TransformMultcxx . . $ g3_TransformMult(893694c8b8ecb2b3).(gTransformFullcxx . . $ gTransformFull., gTransformModelViewcxx . . $ gTransformModelView., gTransformProjectioncxx . . $ gTransformProjection.);
84
85 // projection -> ViewPort
86 g3_TransformMultcxx . . $ g3_TransformMult(893694c8b8ecb2b3).(gTransformFullcxx . . $ gTransformFull., gTransformFullcxx . . $ gTransformFull., gTransformViewPortcxx . . $ gTransformViewPort.);
87 }
88
89 void g3_ForceTransformRefreshcxx . . $ g3_ForceTransformRefresh(49f6e7a06ebc5aa8).(void) { sUseTransformPassthrucxx . . $ sUseTransformPassthru. = -1; }
90
91 void g3_RefreshTransformscxx . . $ g3_RefreshTransforms(b45ddcbc8423892c).(bool usePassthru) {
92 if (sUseTransformPassthrucxx . . $ sUseTransformPassthru. == 1 && usePassthru) {
93 // we don't have to do anything because we are already setup for pass-thru
94 return;
95 }
96
97 if (usePassthru) {
98 // setup OpenGL to use pass-thru
99 rend_TransformSetToPassthrucxx . . $ rend_TransformSetToPassthru(49f6e7a06ebc5aa8).();
100 } else {
101 // extract the viewport data from the renderer
102 int viewportWidth, viewportHeight, viewportX, viewportY;
103 rend_GetProjectionScreenParameterscxx . . $ rend_GetProjectionScreenParameters(a90a5d8ba88c22b1).(viewportX, viewportY, viewportWidth, viewportHeight);
104
105 // setup OpenGL to use full transform stack
106 // TODO: in the future we only need to set those that have changed
107 rend_TransformSetViewportcxx . . $ rend_TransformSetViewport(748afa4755bc9595).(viewportX, viewportY, viewportWidth, viewportHeight);
108 rend_TransformSetProjectioncxx . . $ rend_TransformSetProjection(9fb3ef344050b01e).(gTransformProjectioncxx . . $ gTransformProjection.);
109 rend_TransformSetModelViewcxx . . $ rend_TransformSetModelView(9fb3ef344050b01e).(gTransformModelViewcxx . . $ gTransformModelView.);
110 }
111
112 // store the pass-thru
113 sUseTransformPassthrucxx . . $ sUseTransformPassthru. = (usePassthru) ? 1 : 0;
114 }