00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 }
00149