| 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 | #include "CombinerBase.h" |
| 23 | #include "CombinerStructs.h" |
| 24 | |
| 25 | //----------------------------------------------------------------------------- |
| 26 | //! Constructor |
| 27 | //----------------------------------------------------------------------------- |
| 28 | CombinerBase::CombinerBase() |
| 29 | { |
| 30 | m_fillColor[0] = m_blendColor[0] = m_primColor[0] = m_envColor[0] = 0; |
| 31 | m_fillColor[1] = m_blendColor[1] = m_primColor[1] = m_envColor[1] = 0; |
| 32 | m_fillColor[2] = m_blendColor[2] = m_primColor[2] = m_envColor[2] = 0; |
| 33 | m_fillColor[3] = m_blendColor[3] = m_primColor[3] = m_envColor[3] = 1; |
| 34 | } |
| 35 | |
| 36 | //----------------------------------------------------------------------------- |
| 37 | //! Destructor |
| 38 | //----------------------------------------------------------------------------- |
| 39 | CombinerBase::~CombinerBase() |
| 40 | { |
| 41 | |
| 42 | } |
| 43 | |
| 44 | //----------------------------------------------------------------------------- |
| 45 | //! Set Fill Color |
| 46 | //! @param r Red component of color (0.0 - 1.0) |
| 47 | //! @param g Green component of color (0.0 - 1.0) |
| 48 | //! @param b Blue component of color (0.0 - 1.0) |
| 49 | //! @param a Alpha component of color (0.0 - 1.0) |
| 50 | //----------------------------------------------------------------------------- |
| 51 | void CombinerBase::setFillColor (float r, float g, float b, float a) |
| 52 | { |
| 53 | m_fillColor[0] = r; |
| 54 | m_fillColor[1] = g; |
| 55 | m_fillColor[2] = b; |
| 56 | m_fillColor[3] = a; |
| 57 | } |
| 58 | |
| 59 | //----------------------------------------------------------------------------- |
| 60 | //! Set Blend Color |
| 61 | //! @param r Red component of color (0.0 - 1.0) |
| 62 | //! @param g Green component of color (0.0 - 1.0) |
| 63 | //! @param b Blue component of color (0.0 - 1.0) |
| 64 | //! @param a Alpha component of color (0.0 - 1.0) |
| 65 | //----------------------------------------------------------------------------- |
| 66 | void CombinerBase::setBlendColor(float r, float g, float b, float a) |
| 67 | { |
| 68 | m_blendColor[0] = r; |
| 69 | m_blendColor[1] = g; |
| 70 | m_blendColor[2] = b; |
| 71 | m_blendColor[3] = a; |
| 72 | } |
| 73 | |
| 74 | //----------------------------------------------------------------------------- |
| 75 | //! Set Prim Color |
| 76 | //! @param r Red component of color (0.0 - 1.0) |
| 77 | //! @param g Green component of color (0.0 - 1.0) |
| 78 | //! @param b Blue component of color (0.0 - 1.0) |
| 79 | //! @param a Alpha component of color (0.0 - 1.0) |
| 80 | //----------------------------------------------------------------------------- |
| 81 | void CombinerBase::setPrimColor (float r, float g, float b, float a) |
| 82 | { |
| 83 | m_primColor[0] = r; |
| 84 | m_primColor[1] = g; |
| 85 | m_primColor[2] = b; |
| 86 | m_primColor[3] = a; |
| 87 | } |
| 88 | |
| 89 | //----------------------------------------------------------------------------- |
| 90 | //! Set Enviroment Color |
| 91 | //! @param r Red component of color (0.0 - 1.0) |
| 92 | //! @param g Green component of color (0.0 - 1.0) |
| 93 | //! @param b Blue component of color (0.0 - 1.0) |
| 94 | //! @param a Alpha component of color (0.0 - 1.0) |
| 95 | //----------------------------------------------------------------------------- |
| 96 | void CombinerBase::setEnvColor(float r, float g, float b, float a) |
| 97 | { |
| 98 | m_envColor[0] = r; |
| 99 | m_envColor[1] = g; |
| 100 | m_envColor[2] = b; |
| 101 | m_envColor[3] = a; |
| 102 | } |
| 103 | |
| 104 | //----------------------------------------------------------------------------- |
| 105 | //! Get Combiner Color |
| 106 | //! @param[in] colorSource From which colorsource to retrive color values |
| 107 | //! \arg \c PRIMITIVE Get color from primative color |
| 108 | //! \arg \c ENVIRONMENT Get color from environment color |
| 109 | //! \arg \c PRIMITIVE_ALPHA Get color from primatives alpha value |
| 110 | //! \arg \c ENV_ALPHA Get color from environment colors alpha value |
| 111 | //! \arg \c PRIM_LOD_FRAC Get color from primative-LOD-frac value |
| 112 | //! \arg \c ONE Get white color |
| 113 | //! \arg \c ZERO Get black color |
| 114 | //! @param[in] alphaSource From which alphasource to retrive alpha value |
| 115 | //! \arg \c PRIMITIVE_ALPHA Get alpha value from primitive colors alpha value |
| 116 | //! \arg \c ENV_ALPHA Get alpha value from environment colors alpha value |
| 117 | //! \arg \c PRIM_LOD_FRAC Get alpha value from primative-LOD-frac value |
| 118 | //! \arg \c ONE Set alpha value to 1.0 |
| 119 | //! \arg \c ZERO Set alpha value to 0.0 |
| 120 | //! @param[out] out The combiner color with color and alpha value |
| 121 | //----------------------------------------------------------------------------- |
| 122 | void CombinerBase::getCombinerColor(float out[4], short colorSrc, short alphaSrc) |
| 123 | { |
| 124 | //Set color values |
| 125 | switch ( colorSrc ) |
| 126 | { |
| 127 | case PRIMITIVE: |
| 128 | out[0] = m_primColor[0]; |
| 129 | out[1] = m_primColor[1]; |
| 130 | out[2] = m_primColor[2]; |
| 131 | break; |
| 132 | case ENVIRONMENT: |
| 133 | out[0] = m_envColor[0]; |
| 134 | out[1] = m_envColor[1]; |
| 135 | out[2] = m_envColor[2]; |
| 136 | break; |
| 137 | case PRIMITIVE_ALPHA: |
| 138 | out[0] = m_primColor[3]; |
| 139 | out[1] = m_primColor[3]; |
| 140 | out[2] = m_primColor[3]; |
| 141 | break; |
| 142 | case ENV_ALPHA: |
| 143 | out[0] = m_envColor[3]; |
| 144 | out[1] = m_envColor[3]; |
| 145 | out[2] = m_envColor[3]; |
| 146 | break; |
| 147 | case PRIM_LOD_FRAC: |
| 148 | out[0] = m_primLodFrac; |
| 149 | out[1] = m_primLodFrac; |
| 150 | out[2] = m_primLodFrac; |
| 151 | break; |
| 152 | case ONE: |
| 153 | out[0] = 1.0f; |
| 154 | out[1] = 1.0f; |
| 155 | out[2] = 1.0f; |
| 156 | break; |
| 157 | case ZERO: |
| 158 | out[0] = 0.0f; |
| 159 | out[1] = 0.0f; |
| 160 | out[2] = 0.0f; |
| 161 | break; |
| 162 | } |
| 163 | |
| 164 | //Set alpha value |
| 165 | switch ( alphaSrc ) |
| 166 | { |
| 167 | case PRIMITIVE_ALPHA: |
| 168 | out[3] = m_primColor[3]; |
| 169 | break; |
| 170 | case ENV_ALPHA: |
| 171 | out[3] = m_envColor[3]; |
| 172 | break; |
| 173 | case PRIM_LOD_FRAC: |
| 174 | out[3] = m_primLodFrac; |
| 175 | break; |
| 176 | case ONE: |
| 177 | out[3] = 1.0f; |
| 178 | break; |
| 179 | case ZERO: |
| 180 | out[3] = 0.0f; |
| 181 | break; |
| 182 | } |
| 183 | } |