Glide Plugin GLES2 port from mupen64plus-ae, but with special FrameSkip code
[mupen64plus-pandora.git] / source / gles2glide64 / src / Glide64 / ucode07.h
CommitLineData
98e75f2d 1/*
2* Glide64 - Glide video plugin for Nintendo 64 emulators.
3* Copyright (c) 2002 Dave2001
4* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2 of the License, or
9* any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21//****************************************************************
22//
23// Glide64 - Glide Plugin for Nintendo 64 emulators
24// Project started on December 29th, 2001
25//
26// Authors:
27// Dave2001, original author, founded the project in 2001, left it in 2002
28// Gugaman, joined the project in 2002, left it in 2002
29// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002
30// Hiroshi 'KoolSmoky' Morii, joined the project in 2007
31//
32//****************************************************************
33//
34// To modify Glide64:
35// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.
36// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.
37//
38//****************************************************************
39//
40// Oct 2002 Created by Gonetz (Gonetz@ngs.ru)
41// Info about this ucode is taken from TR64 OGL plugin. Thanks, Icepir8!
42// Oct 2003 Modified by Gonetz (Gonetz@ngs.ru)
43// Bugs fixed with help from glN64 sources. Thanks, Orkin!
44//****************************************************************
45
46wxUint32 pd_col_addr = 0;
47
48static void uc7_colorbase ()
49{
50 LRDP("uc7_colorbase\n");
51 pd_col_addr = segoffset(rdp.cmd1);
52}
53
54
55typedef struct
56{
57 short y;
58 short x;
59 wxUint16 idx;
60
61 short z;
62
63 short t;
64 short s;
65
66} vtx_uc7;
67
68static void uc7_vertex ()
69{
70Check_FrameSkip;
71
72 if (rdp.update & UPDATE_MULT_MAT)
73 {
74 rdp.update ^= UPDATE_MULT_MAT;
75 MulMatrices(rdp.model, rdp.proj, rdp.combined);
76 }
77
78 // This is special, not handled in update()
79 if (rdp.update & UPDATE_LIGHTS)
80 {
81 rdp.update ^= UPDATE_LIGHTS;
82
83 // Calculate light vectors
84 for (wxUint32 l=0; l<rdp.num_lights; l++)
85 {
86 InverseTransformVector(&rdp.light[l].dir_x, rdp.light_vector[l], rdp.model);
87 NormalizeVector (rdp.light_vector[l]);
88 }
89 }
90
91 wxUint32 addr = segoffset(rdp.cmd1);
92 wxUint32 v0, i, n;
93 float x, y, z;
94
95 rdp.v0 = v0 = (rdp.cmd0 & 0x0F0000) >> 16;
96 rdp.vn = n = ((rdp.cmd0 & 0xF00000) >> 20) + 1;
97
98 FRDP ("uc7:vertex n: %d, v0: %d, from: %08lx\n", n, v0, addr);
99
100 vtx_uc7 *vertex = (vtx_uc7 *)&gfx.RDRAM[addr];
101
102 for(i = 0; i < n; i++)
103 {
104 VERTEX *v = &rdp.vtx[v0 + i];
105 x = (float)vertex->x;
106 y = (float)vertex->y;
107 z = (float)vertex->z;
108 v->flags = 0;
109 v->ou = (float)vertex->s;
110 v->ov = (float)vertex->t;
111 v->uv_scaled = 0;
112
113#ifdef EXTREME_LOGGING
114// FRDP ("before: v%d - x: %f, y: %f, z: %f, flags: %04lx, ou: %f, ov: %f\n", i>>4, x, y, z, v->flags, v->ou, v->ov);
115#endif
116
117 v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
118 v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
119 v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
120 v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
121
122
123 if (fabs(v->w) < 0.001) v->w = 0.001f;
124 v->oow = 1.0f / v->w;
125 v->x_w = v->x * v->oow;
126 v->y_w = v->y * v->oow;
127 v->z_w = v->z * v->oow;
128
129 v->uv_calculated = 0xFFFFFFFF;
130 v->screen_translated = 0;
131
132 v->scr_off = 0;
133 if (v->x < -v->w) v->scr_off |= 1;
134 if (v->x > v->w) v->scr_off |= 2;
135 if (v->y < -v->w) v->scr_off |= 4;
136 if (v->y > v->w) v->scr_off |= 8;
137 if (v->w < 0.1f) v->scr_off |= 16;
138
139 wxUint8 *color = &gfx.RDRAM[pd_col_addr + (vertex->idx & 0xff)];
140
141 v->a = color[0];
142 CalculateFog (v);
143
144 if (rdp.geom_mode & 0x00020000)
145 {
146 v->vec[0] = (char)color[3];
147 v->vec[1] = (char)color[2];
148 v->vec[2] = (char)color[1];
149
150 if (rdp.geom_mode & 0x80000)
151 {
152 calc_linear (v);
153#ifdef EXTREME_LOGGING
154 FRDP ("calc linear: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
155#endif
156 }
157 else if (rdp.geom_mode & 0x40000)
158 {
159 calc_sphere (v);
160#ifdef EXTREME_LOGGING
161 FRDP ("calc sphere: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
162#endif
163 }
164
165 NormalizeVector (v->vec);
166
167 calc_light (v);
168 }
169 else
170 {
171 v->r = color[3];
172 v->g = color[2];
173 v->b = color[1];
174 }
175#ifdef EXTREME_LOGGING
176 FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f\n", i>>4, v->x, v->y, v->z, v->w, v->ou, v->ov);
177#endif
178 vertex++;
179 }
180}
181