Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

BlendSpriteState.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * ブレンドスプライトステート実装
00022  * @author Junpee
00023  */
00024 
00025 #include "LampBasic.h"
00026 #include "Graphics2D/SpriteState/BlendSpriteState.h"
00027 #include "Graphics/Renderer/RenderingDevice.h"
00028 
00029 namespace Lamp{
00030 
00031 // 半透明
00032 const BlendSpriteState BlendSpriteState::translucent(blendModeAdd,
00033     blendStateSourceAlpha, blendStateInverseSourceAlpha);
00034 
00035 // 加算
00036 const BlendSpriteState BlendSpriteState::addState(blendModeAdd,
00037     blendStateSourceAlpha, blendStateOne);
00038 
00039 // デフォルト
00040 const BlendSpriteState BlendSpriteState::defaultState(translucent);
00041 
00042 // ブレンドモード文字列テーブル
00043 const String BlendSpriteState::blendModeStringTable[] = {
00044     "Disable",
00045     "Add",
00046     "Subtract",
00047     "InverseSubtract",
00048     "Minimum",
00049     "Maximum",
00050 };
00051 
00052 // ブレンドステート文字列テーブル
00053 const String BlendSpriteState::blendStateStringTable[] = {
00054     "Zero",
00055     "One",
00056     "SourceColor",
00057     "InverseSourceColor",
00058     "SourceAlpha",
00059     "InverseSourceAlpha",
00060     "SourceAlphaSaturate",
00061     "DestinationColor",
00062     "InverseDestinationColor",
00063     "DestinationAlpha",
00064     "InverseDestinationAlpha",
00065 };
00066 
00067 //------------------------------------------------------------------------------
00068 // コンストラクタ
00069 BlendSpriteState::BlendSpriteState() :
00070     blendMode_(blendModeAdd), blendSource_(blendStateSourceAlpha),
00071     blendDestination_(blendStateInverseSourceAlpha){
00072 }
00073 //------------------------------------------------------------------------------
00074 // コンストラクタ
00075 BlendSpriteState::BlendSpriteState(BlendMode blendMode,
00076     BlendState blendSource, BlendState blendDestination) :
00077     blendMode_(blendMode), blendSource_(blendSource),
00078     blendDestination_(blendDestination){
00079     Assert((blendMode_ >= 0) && (blendMode_ < blendModeMax));
00080     Assert((blendSource_ >= 0) && (blendSource_ < blendStateMax));
00081     Assert((blendDestination_ >= 0) && (blendDestination_ < blendStateMax));
00082 }
00083 //------------------------------------------------------------------------------
00084 // デストラクタ
00085 BlendSpriteState::~BlendSpriteState(){
00086 }
00087 //------------------------------------------------------------------------------
00088 // 描画
00089 //------------------------------------------------------------------------------
00090 // 適用
00091 void BlendSpriteState::apply(SpriteRenderState* renderState){
00092     RenderingDevice* device = RenderingDevice::getInstance();
00093     if(blendMode_ == blendModeDisable){
00094         device->setBlending(false);
00095     }else{
00096         device->setBlending(true);
00097         device->setBlendMode(blendMode_, blendSource_, blendDestination_);
00098     }
00099 }
00100 //------------------------------------------------------------------------------
00101 // ブレンドモード
00102 //------------------------------------------------------------------------------
00103 // ブレンドモードから文字列への変換
00104 const String& BlendSpriteState::blendModeToString(BlendMode blendMode){
00105     Assert(blendMode >= 0);
00106     Assert(blendMode < blendModeMax);
00107     return blendModeStringTable[blendMode];
00108 }
00109 //------------------------------------------------------------------------------
00110 // 文字列からブレンドモードへの変換
00111 BlendSpriteState::BlendMode BlendSpriteState::blendModeFromString(
00112     const String& blendModeString){
00113     for(int i = 0; i < blendModeMax; i++){
00114         if(blendModeStringTable[i].equals(blendModeString)){
00115             return BlendMode(i);
00116         }
00117     }
00118     ErrorOut("BlendSpriteState::blendModeFromString() " + blendModeString);
00119     return blendModeMax;
00120 }
00121 //------------------------------------------------------------------------------
00122 // ブレンドステート
00123 //------------------------------------------------------------------------------
00124 // ブレンドステートから文字列への変換
00125 const String& BlendSpriteState::blendStateToString(BlendState blendState){
00126     Assert(blendState >= 0);
00127     Assert(blendState < blendStateMax);
00128     return blendStateStringTable[blendState];
00129 }
00130 //------------------------------------------------------------------------------
00131 // 文字列からブレンドステートへの変換
00132 BlendSpriteState::BlendState BlendSpriteState::blendStateFromString(
00133     const String& blendStateString){
00134     for(int i = 0; i < blendStateMax; i++){
00135         if(blendStateStringTable[i].equals(blendStateString)){
00136             return BlendState(i);
00137         }
00138     }
00139     ErrorOut("BlendSpriteState::blendStateFromString() " + blendStateString);
00140     return blendStateMax;
00141 }
00142 //------------------------------------------------------------------------------
00143 } // End of namespace Lamp
00144 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:28 2005 for Lamp by doxygen 1.3.2