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

BasicMaterial.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 "Graphics/Material/BasicMaterial.h"
00027 #include "Graphics/Scene/Scene.h"
00028 #include "Graphics/Material/MaterialManager.h"
00029 #include "Graphics/Texture/Texture.h"
00030 #include "Graphics/Shader/ShaderManager.h"
00031 #include "Graphics/Shader/BasicShaderFixed.h"
00032 
00033 namespace Lamp{
00034 
00035 //------------------------------------------------------------------------------
00036 // コンストラクタ
00037 BasicMaterial::BasicMaterial(const String& name, Scene* scene) :
00038     Material(name, scene), baseTexture_(NULL), glossTexture_(NULL),
00039     lightTexture_(NULL), stainTexture_(NULL),
00040     diffuseColor_(1.f, 1.f, 1.f), specularColor_(0.f, 0.f, 0.f),
00041     ambientColor_(1.f, 1.f, 1.f), emissiveColor_(0.f, 0.f, 0.f),
00042     specularPower_(0.f),
00043     baseUVIndex_(0), glossUVIndex_(0), lightUVIndex_(0), stainUVIndex_(0){
00044 }
00045 //------------------------------------------------------------------------------
00046 // デストラクタ
00047 BasicMaterial::~BasicMaterial(){
00048 }
00049 //------------------------------------------------------------------------------
00050 // 子の破棄
00051 int BasicMaterial::destroyChildren(){
00052     int result = 0;
00053     Texture* texture;
00054     // ベーステクスチャの破棄
00055     texture = getBaseTexture();
00056     if(texture != NULL){
00057         removeBaseTexture();
00058         result += Texture::recursiveDestroy(texture);
00059     }
00060     // 光沢テクスチャの破棄
00061     texture = getGlossTexture();
00062     if(texture != NULL){
00063         removeGlossTexture();
00064         result += Texture::recursiveDestroy(texture);
00065     }
00066     // ライトテクスチャの破棄
00067     texture = getLightTexture();
00068     if(texture != NULL){
00069         removeLightTexture();
00070         result += Texture::recursiveDestroy(texture);
00071     }
00072     // 汚れテクスチャの破棄
00073     texture = getStainTexture();
00074     if(texture != NULL){
00075         removeStainTexture();
00076         result += Texture::recursiveDestroy(texture);
00077     }
00078     return result;
00079 }
00080 //------------------------------------------------------------------------------
00081 // ステートブロックの構築
00082 void BasicMaterial::buildStateBlock(
00083     Direct3DStateBlock** startBlock, Direct3DStateBlock** endBlock){
00084     ShaderManager* shaderManager = ShaderManager::getInstance();
00085     // ハードウェアの対応状況を調べ、適切なシェーダでステートブロックを構築する
00086     setPipelineMode(pipelineModeFixed);
00087     BasicShaderFixed* fixedShader = shaderManager->getBasicShaderFixed();
00088     fixedShader->buildStateBlock(startBlock, endBlock, this,
00089         baseTexture_, baseUVIndex_,  lightTexture_, lightUVIndex_,
00090         stainTexture_, stainUVIndex_, diffuseColor_, specularColor_,
00091         ambientColor_, emissiveColor_, specularPower_);
00092 }
00093 //------------------------------------------------------------------------------
00094 // 描画
00095 void BasicMaterial::draw(DrawRequest* request){
00096     // 描画のセットアップ
00097     drawSetup(request);
00098 
00099     ShaderManager* shaderManager = ShaderManager::getInstance();
00100     // ハードウェアの対応状況を調べ、適切なシェーダにリクエストを送る
00101     setPipelineMode(pipelineModeFixed);
00102     BasicShaderFixed* fixedShader = shaderManager->getBasicShaderFixed();
00103     fixedShader->draw(request);
00104 }
00105 //------------------------------------------------------------------------------
00106 // 基本マテリアルのコピー
00107 BasicMaterial* BasicMaterial::copyBasicMaterial(u_int copyMask) const{
00108     MaterialManager* manager = scene_->getMaterialManager();
00109     BasicMaterial* destination =
00110         manager->createBasicMaterial(manager->rename(name_));
00111     // マテリアルのコピー
00112     copyMaterialValue(destination);
00113     // メンバのコピー
00114     destination->setDiffuseColor(diffuseColor_);
00115     destination->setSpecularColor(specularColor_);
00116     destination->setAmbientColor(ambientColor_);
00117     destination->setEmissiveColor(emissiveColor_);
00118     destination->setSpecularPower(specularPower_);
00119     destination->setBaseUVIndex(baseUVIndex_);
00120     destination->setGlossUVIndex(glossUVIndex_);
00121     destination->setLightUVIndex(lightUVIndex_);
00122     destination->setStainUVIndex(stainUVIndex_);
00123     // テクスチャ
00124     if((copyMask & copyTexture) == 0){
00125         // テクスチャを共有する
00126         destination->setBaseTexture(baseTexture_);
00127         destination->setGlossTexture(glossTexture_);
00128         destination->setLightTexture(lightTexture_);
00129         destination->setStainTexture(stainTexture_);
00130     }else{
00131         // テクスチャをコピーする
00132         if(baseTexture_ != NULL){
00133             destination->setBaseTexture(baseTexture_->copy(copyMask));
00134         }
00135         if(glossTexture_ != NULL){
00136             destination->setGlossTexture(glossTexture_->copy(copyMask));
00137         }
00138         if(lightTexture_ != NULL){
00139             destination->setLightTexture(lightTexture_->copy(copyMask));
00140         }
00141         if(stainTexture_ != NULL){
00142             destination->setStainTexture(stainTexture_->copy(copyMask));
00143         }
00144     }
00145     return destination;
00146 }
00147 //------------------------------------------------------------------------------
00148 } // End of namespace Lamp
00149 //------------------------------------------------------------------------------

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