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

# Shader.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/Shader/Shader.h"
    00027 #include "Graphics/Renderer/Renderer.h"
    00028 #include "Graphics/Renderer/RenderingDevice.h"
    00029 #include "Graphics/Renderer/DrawRequest.h"
    00030 #include "Graphics/Mesh/Mesh.h"
    00031 #include "Graphics/Material/Material.h"
    00032 #include "Graphics/Texture/Texture.h"
    00033
    00034 namespace Lamp{
    00035
    00036 // 最大アクティブライト数
    00037 const int Shader::maxActiveLightCount_ = Renderer::maxActiveLightCount_;
    00038
    00039 //------------------------------------------------------------------------------
    00040 // コンストラクタ
    00041 Shader::Shader(){
    00042     device_ = RenderingDevice::getInstance();
    00043 }
    00044 //------------------------------------------------------------------------------
    00045 // デストラクタ
    00046 Shader::~Shader(){
    00047 }
    00048 //------------------------------------------------------------------------------
    00049 // マテリアル開始の構築
    00050 void Shader::buildMaterialStart(Material* material){
    00051     // アルファ値はFixedとProgrammableで扱いが違うのでサブクラスで設定する
    00052
    00053     // アルファブレンド
    00054     if(material->isBlendEnabled()){
    00055         device_->setBlendMode(material->getBlendMode(),
    00056             material->getBlendSource(), material->getBlendDestination());
    00057     }
    00058
    00059     // Z書き込み
    00060     device_->setRenderState(D3DRS_ZWRITEENABLE, material->useZWrite());
    00061     // Zテスト
    00062     device_->setZTest(material->useZTest());
    00063 }
    00064 //------------------------------------------------------------------------------
    00065 // マテリアル終了の構築
    00066 //void Shader::buildMaterialEnd(Material* material){
    00067 //}
    00068 //------------------------------------------------------------------------------
    00069 // 描画
    00070 //------------------------------------------------------------------------------
    00071 // 描画コール
    00072 void Shader::drawCall(DrawRequest* request){
    00073     Mesh* mesh = request->getMesh();
    00074     // インデックスを持つか
    00075     if(mesh->hasVertexIndices()){
    00076         // パイプラインに関係なく、同じメッシュデータならば設定を行わない
    00077         if(request->isMeshDataChanged()){
    00078             // インデックスバッファを設定
    00079             device_->setIndexBuffer(mesh->getIndexBuffer());
    00080         }
    00081         // インデックス三角リスト描画
    00082         device_->drawIndexedTriangleList(
    00083             mesh->getVertexCount(), mesh->getPrimitiveCount());
    00084     }else{
    00085         // 三角リスト描画
    00086         device_->drawTriangleList(mesh->getPrimitiveCount());
    00087     }
    00088 }
    00089 //------------------------------------------------------------------------------
    00090 } // End of namespace Lamp
    00091 //------------------------------------------------------------------------------