| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of OGRE |
|---|
| 4 | (Object-oriented Graphics Rendering Engine) |
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
|---|
| 6 | |
|---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
|---|
| 8 | Also see acknowledgements in Readme.html |
|---|
| 9 | |
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 13 | version. |
|---|
| 14 | |
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 23 | |
|---|
| 24 | You may alternatively use this source under the terms of a specific version of |
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
|---|
| 26 | Torus Knot Software Ltd. |
|---|
| 27 | ----------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | #include "OgreStableHeaders.h" |
|---|
| 30 | #include "OgreCompositionPass.h" |
|---|
| 31 | #include "OgreMaterialManager.h" |
|---|
| 32 | |
|---|
| 33 | namespace Ogre { |
|---|
| 34 | |
|---|
| 35 | CompositionPass::CompositionPass(CompositionTargetPass *parent): |
|---|
| 36 | mParent(parent), |
|---|
| 37 | mType(PT_RENDERQUAD), |
|---|
| 38 | mIdentifier(0), |
|---|
| 39 | mFirstRenderQueue(RENDER_QUEUE_SKIES_EARLY), |
|---|
| 40 | mLastRenderQueue(RENDER_QUEUE_SKIES_LATE), |
|---|
| 41 | mClearBuffers(FBT_COLOUR|FBT_DEPTH), |
|---|
| 42 | mClearColour(0.0,0.0,0.0,0.0), |
|---|
| 43 | mClearDepth(1.0f), |
|---|
| 44 | mClearStencil(0), |
|---|
| 45 | mStencilCheck(false), |
|---|
| 46 | mStencilFunc(CMPF_ALWAYS_PASS), |
|---|
| 47 | mStencilRefValue(0), |
|---|
| 48 | mStencilMask(0xFFFFFFFF), |
|---|
| 49 | mStencilFailOp(SOP_KEEP), |
|---|
| 50 | mStencilDepthFailOp(SOP_KEEP), |
|---|
| 51 | mStencilPassOp(SOP_KEEP), |
|---|
| 52 | mStencilTwoSidedOperation(false) |
|---|
| 53 | { |
|---|
| 54 | } |
|---|
| 55 | //----------------------------------------------------------------------- |
|---|
| 56 | CompositionPass::~CompositionPass() |
|---|
| 57 | { |
|---|
| 58 | } |
|---|
| 59 | //----------------------------------------------------------------------- |
|---|
| 60 | void CompositionPass::setType(CompositionPass::PassType type) |
|---|
| 61 | { |
|---|
| 62 | mType = type; |
|---|
| 63 | } |
|---|
| 64 | //----------------------------------------------------------------------- |
|---|
| 65 | CompositionPass::PassType CompositionPass::getType() const |
|---|
| 66 | { |
|---|
| 67 | return mType; |
|---|
| 68 | } |
|---|
| 69 | //----------------------------------------------------------------------- |
|---|
| 70 | void CompositionPass::setIdentifier(uint32 id) |
|---|
| 71 | { |
|---|
| 72 | mIdentifier = id; |
|---|
| 73 | } |
|---|
| 74 | //----------------------------------------------------------------------- |
|---|
| 75 | uint32 CompositionPass::getIdentifier() const |
|---|
| 76 | { |
|---|
| 77 | return mIdentifier; |
|---|
| 78 | } |
|---|
| 79 | //----------------------------------------------------------------------- |
|---|
| 80 | void CompositionPass::setMaterial(const MaterialPtr& mat) |
|---|
| 81 | { |
|---|
| 82 | mMaterial = mat; |
|---|
| 83 | } |
|---|
| 84 | //----------------------------------------------------------------------- |
|---|
| 85 | void CompositionPass::setMaterialName(const String &name) |
|---|
| 86 | { |
|---|
| 87 | mMaterial = MaterialManager::getSingleton().getByName(name); |
|---|
| 88 | } |
|---|
| 89 | //----------------------------------------------------------------------- |
|---|
| 90 | const MaterialPtr& CompositionPass::getMaterial() const |
|---|
| 91 | { |
|---|
| 92 | return mMaterial; |
|---|
| 93 | } |
|---|
| 94 | //----------------------------------------------------------------------- |
|---|
| 95 | void CompositionPass::setClearBuffers(uint32 val) |
|---|
| 96 | { |
|---|
| 97 | mClearBuffers = val; |
|---|
| 98 | } |
|---|
| 99 | //----------------------------------------------------------------------- |
|---|
| 100 | uint32 CompositionPass::getClearBuffers() |
|---|
| 101 | { |
|---|
| 102 | return mClearBuffers; |
|---|
| 103 | } |
|---|
| 104 | //----------------------------------------------------------------------- |
|---|
| 105 | void CompositionPass::setClearColour(ColourValue val) |
|---|
| 106 | { |
|---|
| 107 | mClearColour = val; |
|---|
| 108 | } |
|---|
| 109 | //----------------------------------------------------------------------- |
|---|
| 110 | const ColourValue &CompositionPass::getClearColour() |
|---|
| 111 | { |
|---|
| 112 | return mClearColour; |
|---|
| 113 | } |
|---|
| 114 | //----------------------------------------------------------------------- |
|---|
| 115 | void CompositionPass::setInput(size_t id, const String &input) |
|---|
| 116 | { |
|---|
| 117 | assert(id<OGRE_MAX_TEXTURE_LAYERS); |
|---|
| 118 | mInputs[id] = input; |
|---|
| 119 | } |
|---|
| 120 | //----------------------------------------------------------------------- |
|---|
| 121 | const String &CompositionPass::getInput(size_t id) |
|---|
| 122 | { |
|---|
| 123 | assert(id<OGRE_MAX_TEXTURE_LAYERS); |
|---|
| 124 | return mInputs[id]; |
|---|
| 125 | } |
|---|
| 126 | //----------------------------------------------------------------------- |
|---|
| 127 | size_t CompositionPass::getNumInputs() |
|---|
| 128 | { |
|---|
| 129 | size_t count = 0; |
|---|
| 130 | for(size_t x=0; x<OGRE_MAX_TEXTURE_LAYERS; ++x) |
|---|
| 131 | { |
|---|
| 132 | if(!mInputs[x].empty()) |
|---|
| 133 | count = x+1; |
|---|
| 134 | } |
|---|
| 135 | return count; |
|---|
| 136 | } |
|---|
| 137 | //----------------------------------------------------------------------- |
|---|
| 138 | void CompositionPass::clearAllInputs() |
|---|
| 139 | { |
|---|
| 140 | for(size_t x=0; x<OGRE_MAX_TEXTURE_LAYERS; ++x) |
|---|
| 141 | { |
|---|
| 142 | mInputs[x].clear(); |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | //----------------------------------------------------------------------- |
|---|
| 146 | CompositionTargetPass *CompositionPass::getParent() |
|---|
| 147 | { |
|---|
| 148 | return mParent; |
|---|
| 149 | } |
|---|
| 150 | //----------------------------------------------------------------------- |
|---|
| 151 | void CompositionPass::setFirstRenderQueue(uint8 id) |
|---|
| 152 | { |
|---|
| 153 | mFirstRenderQueue = id; |
|---|
| 154 | } |
|---|
| 155 | //----------------------------------------------------------------------- |
|---|
| 156 | uint8 CompositionPass::getFirstRenderQueue() |
|---|
| 157 | { |
|---|
| 158 | return mFirstRenderQueue; |
|---|
| 159 | } |
|---|
| 160 | //----------------------------------------------------------------------- |
|---|
| 161 | void CompositionPass::setLastRenderQueue(uint8 id) |
|---|
| 162 | { |
|---|
| 163 | mLastRenderQueue = id; |
|---|
| 164 | } |
|---|
| 165 | //----------------------------------------------------------------------- |
|---|
| 166 | uint8 CompositionPass::getLastRenderQueue() |
|---|
| 167 | { |
|---|
| 168 | return mLastRenderQueue; |
|---|
| 169 | } |
|---|
| 170 | //----------------------------------------------------------------------- |
|---|
| 171 | void CompositionPass::setClearDepth(Real depth) |
|---|
| 172 | { |
|---|
| 173 | mClearDepth = depth; |
|---|
| 174 | } |
|---|
| 175 | Real CompositionPass::getClearDepth() |
|---|
| 176 | { |
|---|
| 177 | return mClearDepth; |
|---|
| 178 | } |
|---|
| 179 | void CompositionPass::setClearStencil(uint32 value) |
|---|
| 180 | { |
|---|
| 181 | mClearStencil = value; |
|---|
| 182 | } |
|---|
| 183 | uint32 CompositionPass::getClearStencil() |
|---|
| 184 | { |
|---|
| 185 | return mClearStencil; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | void CompositionPass::setStencilCheck(bool value) |
|---|
| 189 | { |
|---|
| 190 | mStencilCheck = value; |
|---|
| 191 | } |
|---|
| 192 | bool CompositionPass::getStencilCheck() |
|---|
| 193 | { |
|---|
| 194 | return mStencilCheck; |
|---|
| 195 | } |
|---|
| 196 | void CompositionPass::setStencilFunc(CompareFunction value) |
|---|
| 197 | { |
|---|
| 198 | mStencilFunc = value; |
|---|
| 199 | } |
|---|
| 200 | CompareFunction CompositionPass::getStencilFunc() |
|---|
| 201 | { |
|---|
| 202 | return mStencilFunc; |
|---|
| 203 | } |
|---|
| 204 | void CompositionPass::setStencilRefValue(uint32 value) |
|---|
| 205 | { |
|---|
| 206 | mStencilRefValue = value; |
|---|
| 207 | } |
|---|
| 208 | uint32 CompositionPass::getStencilRefValue() |
|---|
| 209 | { |
|---|
| 210 | return mStencilRefValue; |
|---|
| 211 | } |
|---|
| 212 | void CompositionPass::setStencilMask(uint32 value) |
|---|
| 213 | { |
|---|
| 214 | mStencilMask = value; |
|---|
| 215 | } |
|---|
| 216 | uint32 CompositionPass::getStencilMask() |
|---|
| 217 | { |
|---|
| 218 | return mStencilMask; |
|---|
| 219 | } |
|---|
| 220 | void CompositionPass::setStencilFailOp(StencilOperation value) |
|---|
| 221 | { |
|---|
| 222 | mStencilFailOp = value; |
|---|
| 223 | } |
|---|
| 224 | StencilOperation CompositionPass::getStencilFailOp() |
|---|
| 225 | { |
|---|
| 226 | return mStencilFailOp; |
|---|
| 227 | } |
|---|
| 228 | void CompositionPass::setStencilDepthFailOp(StencilOperation value) |
|---|
| 229 | { |
|---|
| 230 | mStencilDepthFailOp = value; |
|---|
| 231 | } |
|---|
| 232 | StencilOperation CompositionPass::getStencilDepthFailOp() |
|---|
| 233 | { |
|---|
| 234 | return mStencilDepthFailOp; |
|---|
| 235 | } |
|---|
| 236 | void CompositionPass::setStencilPassOp(StencilOperation value) |
|---|
| 237 | { |
|---|
| 238 | mStencilPassOp = value; |
|---|
| 239 | } |
|---|
| 240 | StencilOperation CompositionPass::getStencilPassOp() |
|---|
| 241 | { |
|---|
| 242 | return mStencilPassOp; |
|---|
| 243 | } |
|---|
| 244 | void CompositionPass::setStencilTwoSidedOperation(bool value) |
|---|
| 245 | { |
|---|
| 246 | mStencilTwoSidedOperation = value; |
|---|
| 247 | } |
|---|
| 248 | bool CompositionPass::getStencilTwoSidedOperation() |
|---|
| 249 | { |
|---|
| 250 | return mStencilTwoSidedOperation; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | //----------------------------------------------------------------------- |
|---|
| 254 | bool CompositionPass::_isSupported(void) |
|---|
| 255 | { |
|---|
| 256 | // A pass is supported if material referenced have a supported technique |
|---|
| 257 | |
|---|
| 258 | if (mType == PT_RENDERQUAD) |
|---|
| 259 | { |
|---|
| 260 | if (mMaterial.isNull()) |
|---|
| 261 | { |
|---|
| 262 | return false; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | mMaterial->compile(); |
|---|
| 266 | if (mMaterial->getNumSupportedTechniques() == 0) |
|---|
| 267 | { |
|---|
| 268 | return false; |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | return true; |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | } |
|---|