| 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 | #ifndef ADVANCED_TEX_ENV_COMBINER_H_ |
| 23 | #define ADVANCED_TEX_ENV_COMBINER_H_ |
| 24 | |
| 25 | #include "CombinerBase.h" |
| 26 | #include "CombinerStructs.h" |
| 27 | |
| 28 | struct TexEnvCombiner; |
| 29 | |
| 30 | #ifndef GL_ARB_texture_env_combine |
| 31 | #define GL_ARB_texture_env_combine 1 |
| 32 | #ifndef HAVE_GLES |
| 33 | #define GL_COMBINE_ARB 0x8570 |
| 34 | #define GL_COMBINE_RGB_ARB 0x8571 |
| 35 | #define GL_COMBINE_ALPHA_ARB 0x8572 |
| 36 | #define GL_SOURCE0_RGB_ARB 0x8580 |
| 37 | #define GL_SOURCE1_RGB_ARB 0x8581 |
| 38 | #define GL_SOURCE2_RGB_ARB 0x8582 |
| 39 | #define GL_SOURCE0_ALPHA_ARB 0x8588 |
| 40 | #define GL_SOURCE1_ALPHA_ARB 0x8589 |
| 41 | #define GL_SOURCE2_ALPHA_ARB 0x858A |
| 42 | #define GL_OPERAND0_RGB_ARB 0x8590 |
| 43 | #define GL_OPERAND1_RGB_ARB 0x8591 |
| 44 | #define GL_OPERAND2_RGB_ARB 0x8592 |
| 45 | #define GL_OPERAND0_ALPHA_ARB 0x8598 |
| 46 | #define GL_OPERAND1_ALPHA_ARB 0x8599 |
| 47 | #define GL_OPERAND2_ALPHA_ARB 0x859A |
| 48 | #define GL_RGB_SCALE_ARB 0x8573 |
| 49 | #define GL_ADD_SIGNED_ARB 0x8574 |
| 50 | #define GL_INTERPOLATE_ARB 0x8575 |
| 51 | #define GL_CONSTANT_ARB 0x8576 |
| 52 | #define GL_PRIMARY_COLOR_ARB 0x8577 |
| 53 | #define GL_PREVIOUS_ARB 0x8578 |
| 54 | #define GL_SUBTRACT_ARB 0x84E7 |
| 55 | #endif |
| 56 | #endif |
| 57 | #define SetColorCombinerValues( n, a, s, o ) \ |
| 58 | envCombiner->color[n].a.source = s; \ |
| 59 | envCombiner->color[n].a.operand = o |
| 60 | |
| 61 | #define SetAlphaCombinerValues( n, a, s, o ) \ |
| 62 | envCombiner->alpha[n].a.source = s; \ |
| 63 | envCombiner->alpha[n].a.operand = o |
| 64 | |
| 65 | #define SetAlphaCombinerArg( n, a, i ) \ |
| 66 | if (TexEnvArgs[i].source == GL_CONSTANT_ARB) \ |
| 67 | { \ |
| 68 | if ((envCombiner->alpha[n].constant == COMBINED) || (envCombiner->alpha[n].constant == i)) \ |
| 69 | { \ |
| 70 | envCombiner->alpha[n].constant = i; \ |
| 71 | envCombiner->alpha[n].a.source = GL_CONSTANT_ARB; \ |
| 72 | envCombiner->alpha[n].a.operand = GL_SRC_ALPHA; \ |
| 73 | } \ |
| 74 | else if ((envCombiner->vertex.alpha == COMBINED) || (envCombiner->vertex.alpha == i)) \ |
| 75 | { \ |
| 76 | envCombiner->vertex.alpha = i; \ |
| 77 | envCombiner->alpha[n].a.source = GL_PRIMARY_COLOR_ARB; \ |
| 78 | envCombiner->alpha[n].a.operand = GL_SRC_ALPHA; \ |
| 79 | } \ |
| 80 | } \ |
| 81 | else \ |
| 82 | { \ |
| 83 | envCombiner->alpha[n].a.source = TexEnvArgs[i].source; \ |
| 84 | envCombiner->alpha[n].a.operand = GL_SRC_ALPHA; \ |
| 85 | } |
| 86 | |
| 87 | #define SetColorCombinerArg( n, a, i ) \ |
| 88 | if (TexEnvArgs[i].source == GL_CONSTANT_ARB) \ |
| 89 | { \ |
| 90 | if ((i > 5) && ((envCombiner->alpha[n].constant == COMBINED) || (envCombiner->alpha[n].constant == i))) \ |
| 91 | { \ |
| 92 | envCombiner->alpha[n].constant = i; \ |
| 93 | envCombiner->color[n].a.source = GL_CONSTANT_ARB; \ |
| 94 | envCombiner->color[n].a.operand = GL_SRC_ALPHA; \ |
| 95 | } \ |
| 96 | else if ((i > 5) && ((envCombiner->vertex.alpha == COMBINED) || (envCombiner->vertex.alpha == i))) \ |
| 97 | { \ |
| 98 | envCombiner->vertex.alpha = i; \ |
| 99 | envCombiner->color[n].a.source = GL_PRIMARY_COLOR_ARB; \ |
| 100 | envCombiner->color[n].a.operand = GL_SRC_ALPHA; \ |
| 101 | } \ |
| 102 | else if ((envCombiner->color[n].constant == COMBINED) || (envCombiner->color[n].constant == i)) \ |
| 103 | { \ |
| 104 | envCombiner->color[n].constant = i; \ |
| 105 | envCombiner->color[n].a.source = GL_CONSTANT_ARB; \ |
| 106 | envCombiner->color[n].a.operand = GL_SRC_COLOR; \ |
| 107 | } \ |
| 108 | else if ( ATIX_texture_env_route && ((envCombiner->vertex.secondaryColor == COMBINED) || (envCombiner->vertex.secondaryColor == i))) \ |
| 109 | { \ |
| 110 | envCombiner->vertex.secondaryColor = i; \ |
| 111 | envCombiner->color[n].a.source = GL_SECONDARY_COLOR_ATIX; \ |
| 112 | envCombiner->color[n].a.operand = GL_SRC_COLOR; \ |
| 113 | } \ |
| 114 | else if ((envCombiner->vertex.color == COMBINED) || (envCombiner->vertex.color == i))\ |
| 115 | { \ |
| 116 | envCombiner->vertex.color = i; \ |
| 117 | envCombiner->color[n].a.source = GL_PRIMARY_COLOR_ARB; \ |
| 118 | envCombiner->color[n].a.operand = GL_SRC_COLOR; \ |
| 119 | } \ |
| 120 | } \ |
| 121 | else \ |
| 122 | { \ |
| 123 | envCombiner->color[n].a.source = TexEnvArgs[i].source; \ |
| 124 | envCombiner->color[n].a.operand = TexEnvArgs[i].operand; \ |
| 125 | } |
| 126 | |
| 127 | //***************************************************************************** |
| 128 | //! Advanced Texture Environment Combiner |
| 129 | //! Class used to combine colors by setting texture enviroment using OpenGL |
| 130 | //***************************************************************************** |
| 131 | class AdvancedTexEnvCombiner : public CombinerBase |
| 132 | { |
| 133 | public: |
| 134 | |
| 135 | //Constructor / Destructor |
| 136 | AdvancedTexEnvCombiner(); |
| 137 | ~AdvancedTexEnvCombiner(); |
| 138 | |
| 139 | //Initialize |
| 140 | void initialize(); |
| 141 | |
| 142 | //Begin / End Texture Update |
| 143 | void beginTextureUpdate(); |
| 144 | void endTextureUpdate(TexEnvCombiner* texEnv); |
| 145 | |
| 146 | //Sets texture enviorment colors |
| 147 | void setTextureEnviromentColors(TexEnvCombiner* texEnv); |
| 148 | |
| 149 | //Create New Texture Environment |
| 150 | TexEnvCombiner* createNewTextureEnviroment(Combiner* colorCombiner, Combiner *alphaCombiner); |
| 151 | |
| 152 | //Sets texture enviorment |
| 153 | void setTextureEnviroment(TexEnvCombiner* texEnv); |
| 154 | |
| 155 | private: |
| 156 | |
| 157 | //Extensions |
| 158 | bool ARB_texture_env_combine; |
| 159 | bool ARB_texture_env_crossbar; |
| 160 | bool ATI_texture_env_combine3; |
| 161 | bool ATIX_texture_env_route; |
| 162 | bool NV_texture_env_combine4; |
| 163 | |
| 164 | }; |
| 165 | |
| 166 | #endif |