Arachnoid GLESv1.1 plugin. Compile and run (a bit glitchy and no frameskip) on the...
[mupen64plus-pandora.git] / source / mupen64plus-video-arachnoid / src / Combiner / CombinerStageMerger.cpp
CommitLineData
22726e4d 1/******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
4 *
5 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *****************************************************************************/
21
22//*****************************************************************************
23//
24// NOTE THAT THIS FILE IS BASED ON MATERIAL FROM glN64.
25// http://gln64.emulation64.com/
26//
27//*****************************************************************************
28
29#include "CombinerStructs.h"
30
31//-----------------------------------------------------------------------------
32//* Merge Stages
33//! Try two merge to stages into one
34//! From glN64
35//-----------------------------------------------------------------------------
36void mergeStages(Combiner* c)
37{
38
39 // If all we have is a load in the first stage we can just replace
40 // each occurance of COMBINED in the second stage with it
41 if ((c->stage[0].numOps == 1) && (c->stage[0].op[0].op == LOAD))
42 {
43 int combined = c->stage[0].op[0].param1;
44
45 for (int i = 0; i < c->stage[1].numOps; i++)
46 {
47 c->stage[0].op[i].op = c->stage[1].op[i].op;
48 c->stage[0].op[i].param1 = (c->stage[1].op[i].param1 == COMBINED) ? combined : c->stage[1].op[i].param1;
49 c->stage[0].op[i].param2 = (c->stage[1].op[i].param2 == COMBINED) ? combined : c->stage[1].op[i].param2;
50 c->stage[0].op[i].param3 = (c->stage[1].op[i].param3 == COMBINED) ? combined : c->stage[1].op[i].param3;
51 }
52
53 c->stage[0].numOps = c->stage[1].numOps;
54 c->numStages = 1;
55 }
56 // We can't do any merging on an interpolation
57 else if (c->stage[1].op[0].op != INTERPOLATE)
58 {
59 int numCombined = 0;
60
61 // See how many times the first stage is used in the second one
62 for (int i = 0; i < c->stage[1].numOps; i++)
63 if (c->stage[1].op[i].param1 == COMBINED)
64 numCombined++;
65
66 // If it's not used, just replace the first stage with the second
67 if (numCombined == 0)
68 {
69 for (int i = 0; i < c->stage[1].numOps; i++)
70 {
71 c->stage[0].op[i].op = c->stage[1].op[i].op;
72 c->stage[0].op[i].param1 = c->stage[1].op[i].param1;
73 c->stage[0].op[i].param2 = c->stage[1].op[i].param2;
74 c->stage[0].op[i].param3 = c->stage[1].op[i].param3;
75 }
76 c->stage[0].numOps = c->stage[1].numOps;
77
78 c->numStages = 1;
79 }
80 // If it's only used once
81 else if (numCombined == 1)
82 {
83 // It's only used in the load, so stack on the ops from stage 2 on stage 1
84 if (c->stage[1].op[0].param1 == COMBINED)
85 {
86 for (int i = 1; i < c->stage[1].numOps; i++)
87 {
88 c->stage[0].op[c->stage[0].numOps].op = c->stage[1].op[i].op;
89 c->stage[0].op[c->stage[0].numOps].param1 = c->stage[1].op[i].param1;
90 c->stage[0].numOps++;
91 }
92
93 c->numStages = 1;
94 }
95 // Otherwise, if it's used in the second op, and that op isn't SUB
96 // we can switch the parameters so it works out to tack the ops onto stage 1
97 else if ((c->stage[1].op[1].param1 == COMBINED) && (c->stage[1].op[1].op != SUB))
98 {
99 c->stage[0].op[c->stage[0].numOps].op = c->stage[1].op[1].op;
100 c->stage[0].op[c->stage[0].numOps].param1 = c->stage[1].op[0].param1;
101 c->stage[0].numOps++;
102
103 // If there's another op, tack it onto stage 1 too
104 if (c->stage[1].numOps > 2)
105 {
106 c->stage[0].op[c->stage[0].numOps].op = c->stage[1].op[2].op;
107 c->stage[0].op[c->stage[0].numOps].param1 = c->stage[1].op[2].param1;
108 c->stage[0].numOps++;
109 }
110
111 c->numStages = 1;
112 }
113 }
114 }
115}