void MeshObject::Render() { traceIn(MeshObject::Render); LoadVertexBuffer(mesh->VertBuffer); LoadIndexBuffer(mesh->IdxBuffer); for(DWORD i=0;i<mesh->nSections;i++) { DrawSection §ion = mesh->SectionList[i]; Material *material = MaterialList[i]; if(!material) continue; if(material->GetEffect() == GetActiveEffect()) material->LoadParameters(); if(material->GetFlags() & MATERIAL_TWOSIDED) { GSCullMode cullMode; cullMode = GetCullMode(); SetCullMode(GS_NEITHER); GS->Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); SetCullMode(cullMode); } else GS->Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); } traceOut; }
void Actor::SetCullMode( CString s ) { s.MakeLower(); if (s=="back") SetCullMode( CULL_BACK ); else if(s=="front") SetCullMode( CULL_FRONT ); else if(s=="none") SetCullMode( CULL_NONE ); else ASSERT(0); }
void MeshEntity::QuickRender() { traceInFast(MeshEntity::QuickRender); if(!mesh) return; if(GetActiveEffect()) LoadEffectData(); else { MatrixPush(); MatrixMultiply(invTransform); if(bHasScale) MatrixScale(scale); } LoadVertexBuffer(VertBuffer); LoadIndexBuffer(mesh->IdxBuffer); for(DWORD i=0;i<mesh->nSections;i++) { DrawSection §ion = mesh->SectionList[i]; Material *material = MaterialList[i]; if(!material) continue; if(material->effect == GetActiveEffect()) material->LoadParameters(); if(material->flags & MATERIAL_TWOSIDED) { GSCullMode cullMode; cullMode = GetCullMode(); SetCullMode(GS_NEITHER); GS->Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); SetCullMode(cullMode); } else GS->Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); } if(GetActiveEffect()) ResetEffectData(); else MatrixPop(); traceOutFast; }
Object::Object() { vertexBuffer = NULL; indexBuffer = NULL; vertexBufferTangent = NULL; //vertexShader = NULL; //pixelShader = NULL; vertex = NULL; face = NULL; tangent = NULL; isCreated = false; isFinished = false; SetEnvmapEnable(false); SetCullMode(CULL_CW); SetTexture(NULL); SetLightmap(NULL); SetFlipNormals(false); SetCalculateNormals(true); SetEnabled(true); SetTransparency(BLEND_NONE); SetWriteZBuffer(true); //SetPerPixelLighting(false); SetScale(1, 1, 1); SetLocation(0, 0, 0); SetRotation(0, 0, 0); }
bool DX9RenderSystem::Begin2d( ) { SetCullMode( CullMode::NONE ); SetFillMode( FillMode::SOLID ); SetProjectionMatrix( Matrix4::CreateOrthoLH( (float)mSize.x, -(float)mSize.y, 0.0f, 1.0f ) ); SetViewMatrix( Matrix4::IDENTITY ); SetWorldMatrix( Matrix4::IDENTITY ); SetVertexDeclaration( m2dDecl ); SetTextureStageState( 0, TextureState::TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); SetTextureStageState( 0, TextureState::COLOROP, BlendOp::MODULATE ); SetTextureStageState( 0, TextureState::COLORARG1, BlendArg::TEXTURE ); SetTextureStageState( 0, TextureState::COLORARG2, BlendArg::DIFFUSE ); SetTextureStageState( 0, TextureState::ALPHAOP, BlendOp::MODULATE ); SetTextureStageState( 0, TextureState::ALPHAARG1, BlendArg::TEXTURE ); SetTextureStageState( 0, TextureState::ALPHAARG2, BlendArg::DIFFUSE ); SetTextureStageState( 1, TextureState::COLOROP, BlendOp::DISABLE ); SetTextureStageState( 1, TextureState::ALPHAOP, BlendOp::DISABLE ); SetAlphaBlendEnabled( true ); SetAlphaTestEnabled( false ); SetDepthWriteEnabled( true ); SetDepthBufferEnabled( false ); SetSpecularEnabled( false ); return true; };
void RenderingContext::Draw( const std::shared_ptr<IMesh>& mesh ) { if ( mesh == nullptr ) { return; } RenderingDevice* pDevice = RenderingDevice::GetInstance(); Assert( pDevice ); Assert( m_inputAssembler ); Assert( m_vertexShader ); Assert( m_rasterizer ); Assert( m_pixelShader ); Assert( m_outputMerger ); // Set a constant buffer for WVP transform. ConstantBuffer& cbuffer = GetSharedConstantBuffer(); const Matrix4& w = cbuffer.GetMatrix4( ConstantBuffer::WorldMatrix ); Matrix4 wv = w * pDevice->GetViewMatrix(); Matrix4 wvp = wv * pDevice->GetProjectionMatrix(); cbuffer.SetMatrix4( ConstantBuffer::WVPMatrix, wvp ); // Draw primitives here. if ( mesh->GetPrimitiveType() == PrimitiveType::Undefined ) { if ( const IrregularMesh* pMesh = dynamic_cast< const IrregularMesh* >( mesh.get() ) ) { for ( size_t face = 0; face < pMesh->NumFaces(); ++face ) { const unsigned char* color = pMesh->GetFaceColor( face ); cbuffer.SetVector4( ConstantBuffer::DiffuseColor, Vector4( static_cast<byte>( color[0] / 255.0f ), static_cast<byte>( color[1] / 255.0f ), static_cast<byte>( color[2] / 255.0f ), static_cast<byte>( color[3] / 255.0f ) ) ); m_inputAssembler->SetFaceIndex( face ); SetCullMode( CullMode::None ); DrawInternal( mesh, GetPrimitiveTypeFromNumberOfVertices( pMesh->NumVerticesInFace( face ) ) ); } } } else { SetCullMode( CullMode::CCW ); DrawInternal( mesh ); } }
void MeshEntity::RenderInitialPass() { traceInFast(MeshEntity::RenderInitialPass); profileSegment("MeshEntity::RenderInitialPass"); if(!mesh) return; LoadEffectData(); LoadVertexBuffer(VertBuffer); LoadIndexBuffer(mesh->IdxBuffer); for(DWORD i=0;i<mesh->nSections;i++) { DrawSection §ion = mesh->SectionList[i]; Material *material = MaterialList[i]; if(material && section.numFaces) { if(material->effect == GetActiveEffect()) { material->LoadParameters(); if(material->flags & MATERIAL_TWOSIDED) { GSCullMode cullMode; cullMode = GetCullMode(); SetCullMode(GS_NEITHER); Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); SetCullMode(cullMode); } else Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); } } } ResetEffectData(); traceOutFast; }
void RendererCommon::ApplyRenderState(const SRenderState& RenderState) { SetCullMode(RenderState.m_CullMode); SetZEnable(RenderState.m_ZEnable); SetZWriteEnable(RenderState.m_ZWriteEnable); SetAlphaBlendEnable(RenderState.m_AlphaBlendEnable); if (m_RenderState.m_AlphaBlendEnable == EABE_True) { SetBlend(RenderState.m_SrcBlend, RenderState.m_DestBlend); } }
void RageDisplay::SetDefaultRenderStates() { SetLighting( false ); SetCullMode( CULL_NONE ); SetZWrite( false ); SetZTestMode( ZTEST_OFF ); SetAlphaTest( true ); SetBlendMode( BLEND_NORMAL ); SetTextureFiltering( true ); LoadMenuPerspective(0, SCREEN_CENTER_X, SCREEN_CENTER_Y); // 0 FOV = ortho ChangeCentering(0,0,0,0); }
void RageDisplay::SetDefaultRenderStates() { SetLighting( false ); SetCullMode( CULL_NONE ); SetZWrite( false ); SetZTestMode( ZTEST_OFF ); SetAlphaTest( true ); SetBlendMode( BLEND_NORMAL ); SetTextureFiltering( TextureUnit_1, true ); SetZBias( 0 ); LoadMenuPerspective( 0, 640, 480, 320, 240 ); // 0 FOV = ortho }
bool POD3DLayer::Initialize() { RETURN_FALSE_IF_FALSE(BaseCaseLayer::Initialize()); auto state = this->MutableRenderState().AllocState<RasterizerRenderState>(); state->SetCullMode(GraphicsFace::Back); state->Enable(true); auto depthState = this->MutableRenderState().AllocState<DepthStencilRenderState>(); depthState->EnableDepthTest(true); auto* shape1 = NodeFactory::Instance().CreatePODSprite("Scene.pod"); //shape1->SetAnchor(0.5f, 0.5f); //shape1->SetDock(DockPoint::MiddleCenter); AddChild(shape1); return true; }
bool Material::Load(const XMLElement& source) { ResetToDefaults(); if (source.IsNull()) { LOGERROR("Can not load material from null XML element"); return false; } ResourceCache* cache = GetSubsystem<ResourceCache>(); XMLElement techniqueElem = source.GetChild("technique"); techniques_.Clear(); while (techniqueElem) { Technique* tech = cache->GetResource<Technique>(techniqueElem.GetAttribute("name")); if (tech) { TechniqueEntry newTechnique; newTechnique.technique_ = tech; if (techniqueElem.HasAttribute("quality")) newTechnique.qualityLevel_ = techniqueElem.GetInt("quality"); if (techniqueElem.HasAttribute("loddistance")) newTechnique.lodDistance_ = techniqueElem.GetFloat("loddistance"); techniques_.Push(newTechnique); } techniqueElem = techniqueElem.GetNext("technique"); } SortTechniques(); XMLElement textureElem = source.GetChild("texture"); while (textureElem) { TextureUnit unit = TU_DIFFUSE; if (textureElem.HasAttribute("unit")) { String unitName = textureElem.GetAttributeLower("unit"); if (unitName.Length() > 1) { unit = ParseTextureUnitName(unitName); if (unit >= MAX_MATERIAL_TEXTURE_UNITS) LOGERROR("Unknown or illegal texture unit " + unitName); } else unit = (TextureUnit)Clamp(ToInt(unitName), 0, MAX_MATERIAL_TEXTURE_UNITS - 1); } if (unit != MAX_MATERIAL_TEXTURE_UNITS) { String name = textureElem.GetAttribute("name"); // Detect cube maps by file extension: they are defined by an XML file if (GetExtension(name) == ".xml") SetTexture(unit, cache->GetResource<TextureCube>(name)); else SetTexture(unit, cache->GetResource<Texture2D>(name)); } textureElem = textureElem.GetNext("texture"); } XMLElement parameterElem = source.GetChild("parameter"); while (parameterElem) { String name = parameterElem.GetAttribute("name"); SetShaderParameter(name, ParseShaderParameterValue(parameterElem.GetAttribute("value"))); parameterElem = parameterElem.GetNext("parameter"); } XMLElement cullElem = source.GetChild("cull"); if (cullElem) SetCullMode((CullMode)GetStringListIndex(cullElem.GetAttribute("value").CString(), cullModeNames, CULL_CCW)); XMLElement shadowCullElem = source.GetChild("shadowcull"); if (shadowCullElem) SetShadowCullMode((CullMode)GetStringListIndex(shadowCullElem.GetAttribute("value").CString(), cullModeNames, CULL_CCW)); XMLElement depthBiasElem = source.GetChild("depthbias"); if (depthBiasElem) SetDepthBias(BiasParameters(depthBiasElem.GetFloat("constant"), depthBiasElem.GetFloat("slopescaled"))); // Calculate memory use unsigned memoryUse = sizeof(Material); memoryUse += techniques_.Size() * sizeof(TechniqueEntry); memoryUse += MAX_MATERIAL_TEXTURE_UNITS * sizeof(SharedPtr<Texture>); memoryUse += shaderParameters_.Size() * sizeof(MaterialShaderParameter); SetMemoryUse(memoryUse); CheckOcclusion(); return true; }
void Actor::HandleCommand( const ParsedCommand &command ) { HandleParams; const CString& sName = sParam(0); // Commands that go in the tweening queue: if ( sName=="sleep" ) Sleep( fParam(1) ); else if( sName=="linear" ) BeginTweening( fParam(1), TWEEN_LINEAR ); else if( sName=="accelerate" ) BeginTweening( fParam(1), TWEEN_ACCELERATE ); else if( sName=="decelerate" ) BeginTweening( fParam(1), TWEEN_DECELERATE ); else if( sName=="bouncebegin" ) BeginTweening( fParam(1), TWEEN_BOUNCE_BEGIN ); else if( sName=="bounceend" ) BeginTweening( fParam(1), TWEEN_BOUNCE_END ); else if( sName=="spring" ) BeginTweening( fParam(1), TWEEN_SPRING ); else if( sName=="stoptweening" ) { StopTweening(); BeginTweening( 0.0001f, TWEEN_LINEAR ); } // Why BeginT again? -Chris else if( sName=="finishtweening" ) FinishTweening(); else if( sName=="hurrytweening" ) HurryTweening( fParam(1) ); else if( sName=="x" ) SetX( fParam(1) ); else if( sName=="y" ) SetY( fParam(1) ); else if( sName=="z" ) SetZ( fParam(1) ); else if( sName=="addx" ) SetX( GetDestX()+fParam(1) ); else if( sName=="addy" ) SetY( GetDestY()+fParam(1) ); else if( sName=="addz" ) SetZ( GetDestZ()+fParam(1) ); else if( sName=="zoom" ) SetZoom( fParam(1) ); else if( sName=="zoomx" ) SetZoomX( fParam(1) ); else if( sName=="zoomy" ) SetZoomY( fParam(1) ); else if( sName=="zoomz" ) SetZoomZ( fParam(1) ); else if( sName=="zoomtowidth" ) ZoomToWidth( fParam(1) ); else if( sName=="zoomtoheight" ) ZoomToHeight( fParam(1) ); else if( sName=="stretchto" ) StretchTo( RectF( fParam(1), fParam(2), fParam(3), fParam(4) ) ); else if( sName=="cropleft" ) SetCropLeft( fParam(1) ); else if( sName=="croptop" ) SetCropTop( fParam(1) ); else if( sName=="cropright" ) SetCropRight( fParam(1) ); else if( sName=="cropbottom" ) SetCropBottom( fParam(1) ); else if( sName=="fadeleft" ) SetFadeLeft( fParam(1) ); else if( sName=="fadetop" ) SetFadeTop( fParam(1) ); else if( sName=="faderight" ) SetFadeRight( fParam(1) ); else if( sName=="fadebottom" ) SetFadeBottom( fParam(1) ); else if( sName=="fadecolor" ) SetFadeDiffuseColor( cParam(1) ); else if( sName=="diffuse" ) SetDiffuse( cParam(1) ); else if( sName=="diffuseleftedge" ) SetDiffuseLeftEdge( cParam(1) ); else if( sName=="diffuserightedge" ) SetDiffuseRightEdge( cParam(1) ); else if( sName=="diffusetopedge" ) SetDiffuseTopEdge( cParam(1) ); else if( sName=="diffusebottomedge" ) SetDiffuseBottomEdge( cParam(1) ); /* Add left/right/top/bottom for alpha if needed. */ else if( sName=="diffusealpha" ) SetDiffuseAlpha( fParam(1) ); else if( sName=="diffusecolor" ) SetDiffuseColor( cParam(1) ); else if( sName=="glow" ) SetGlow( cParam(1) ); else if( sName=="glowmode" ) { if(!sParam(1).CompareNoCase("whiten")) SetGlowMode( GLOW_WHITEN ); else if(!sParam(1).CompareNoCase("brighten")) SetGlowMode( GLOW_BRIGHTEN ); else ASSERT(0); } else if( sName=="rotationx" ) SetRotationX( fParam(1) ); else if( sName=="rotationy" ) SetRotationY( fParam(1) ); else if( sName=="rotationz" ) SetRotationZ( fParam(1) ); else if( sName=="heading" ) AddRotationH( fParam(1) ); else if( sName=="pitch" ) AddRotationP( fParam(1) ); else if( sName=="roll" ) AddRotationR( fParam(1) ); else if( sName=="shadowlength" ) SetShadowLength( fParam(1) ); else if( sName=="horizalign" ) SetHorizAlign( sParam(1) ); else if( sName=="vertalign" ) SetVertAlign( sParam(1) ); else if( sName=="diffuseblink" ) SetEffectDiffuseBlink(); else if( sName=="diffuseshift" ) SetEffectDiffuseShift(); else if( sName=="glowblink" ) SetEffectGlowBlink(); else if( sName=="glowshift" ) SetEffectGlowShift(); else if( sName=="rainbow" ) SetEffectRainbow(); else if( sName=="wag" ) SetEffectWag(); else if( sName=="bounce" ) SetEffectBounce(); else if( sName=="bob" ) SetEffectBob(); else if( sName=="pulse" ) SetEffectPulse(); else if( sName=="spin" ) SetEffectSpin(); else if( sName=="vibrate" ) SetEffectVibrate(); else if( sName=="stopeffect" ) SetEffectNone(); else if( sName=="effectcolor1" ) SetEffectColor1( cParam(1) ); else if( sName=="effectcolor2" ) SetEffectColor2( cParam(1) ); else if( sName=="effectperiod" ) SetEffectPeriod( fParam(1) ); else if( sName=="effectoffset" ) SetEffectOffset( fParam(1) ); else if( sName=="effectdelay" ) SetEffectDelay( fParam(1) ); else if( sName=="effectclock" ) SetEffectClock( sParam(1) ); else if( sName=="effectmagnitude" ) SetEffectMagnitude( RageVector3(fParam(1),fParam(2),fParam(3)) ); else if( sName=="scaletocover" ) { RectI R(iParam(1), iParam(2), iParam(3), iParam(4)); ScaleToCover(R); } else if( sName=="scaletofit" ) { RectI R(iParam(1), iParam(2), iParam(3), iParam(4)); ScaleToFitInside(R); } // Commands that take effect immediately (ignoring the tweening queue): else if( sName=="animate" ) EnableAnimation( bParam(1) ); else if( sName=="setstate" ) SetState( iParam(1) ); else if( sName=="texturewrapping" ) SetTextureWrapping( bParam(1) ); else if( sName=="additiveblend" ) SetBlendMode( bParam(1) ? BLEND_ADD : BLEND_NORMAL ); else if( sName=="blend" ) SetBlendMode( sParam(1) ); else if( sName=="zbuffer" ) SetUseZBuffer( bParam(1) ); else if( sName=="ztest" ) SetZTestMode( bParam(1)?ZTEST_WRITE_ON_PASS:ZTEST_OFF ); else if( sName=="ztestmode" ) SetZTestMode( sParam(1) ); else if( sName=="zwrite" ) SetZWrite( bParam(1) ); else if( sName=="clearzbuffer" ) SetClearZBuffer( bParam(1) ); else if( sName=="backfacecull" ) SetCullMode( bParam(1) ? CULL_BACK : CULL_NONE ); else if( sName=="cullmode" ) SetCullMode( sParam(1) ); else if( sName=="hidden" ) SetHidden( bParam(1) ); else if( sName=="hibernate" ) SetHibernate( fParam(1) ); else if( sName=="draworder" ) SetDrawOrder( iParam(1) ); else if( sName=="playcommand" ) PlayCommand( sParam(1) ); else if( sName=="queuecommand" ) { ParsedCommand newcommand = command; newcommand.vTokens.erase( newcommand.vTokens.begin() ); QueueCommand( newcommand ); return; // don't do parameter number checking } /* These are commands intended for a Sprite commands, but they will get * sent to all sub-actors (which aren't necessarily Sprites) on * GainFocus and LoseFocus. So, don't run CheckHandledParams * on these commands. */ else if( sName=="customtexturerect" || sName=="texcoordvelocity" || sName=="scaletoclipped" || sName=="stretchtexcoords" || sName=="position" || sName=="loop" || sName=="play" || sName=="pause" || sName=="rate" ) return; else { CString sError = ssprintf( "Actor::HandleCommand: Unrecognized command name '%s'.", sName.c_str() ); LOG->Warn( sError ); Dialog::OK( sError ); } CheckHandledParams; }
bool Pass::Load(const void* wrapper) { EntityUtil::Ptr entityUtil = EntityUtil::Instance(); EnumUtil::Ptr enumUtil = EnumUtil::Instance(); std::string str; if (!IsObject(wrapper)) return false; if (!LoadMemberValue(wrapper, "camera", str)) { LOGE << "Pass param 'camera' not found!"; return false; } if (auto camNode = entityUtil->FindEntity<SceneNode>(str)) SetCameraNode(camNode); if (!LoadMemberValue(wrapper, "blendMode", str)) { LOGE << "Pass param 'blendMode' not found!"; return false; } SetBlendMode(enumUtil->BlendModeFromString(str)); if (!LoadMemberValue(wrapper, "compareMode", str)) { LOGE << "Pass param 'compareMode' not found!"; return false; } SetCompareMode(enumUtil->CompareModeFromString(str)); if (!LoadMemberValue(wrapper, "cullMode", str)) { LOGE << "Pass param 'cullMode' not found!"; return false; } SetCullMode(enumUtil->CullModeFromString(str)); if (!LoadMemberValue(wrapper, "drawMode", str)) { LOGE << "Pass param 'drawMode' not found!"; return false; } SetDrawMode(enumUtil->DrawModeFromString(str)); if (!LoadMemberValue(wrapper, "index", (int&)m_RenderIndex)) { LOGE << "Pass param 'index' not found!"; return false; } if (!LoadArray(wrapper, "shaders", [&](const void* node) -> bool { if (!LoadValue(node, str)) { LOGE << "Pass's shader name not found!"; return false; } if (auto shader = entityUtil->FindEntity<Shader>(str)) { AddShader(shader); return true; } else { LOGW << "Shader " << str << " not found!"; return false; } })) return false; if (!LoadArray(wrapper, "input", [&](const void* node) -> bool { if (!LoadValue(node, str)) { LOGE << "Pass's inputTexture name not found!"; return false; } if (auto texture = entityUtil->FindEntity<Texture>(str)) { AddTexture(texture, true); return true; } else { LOGW << "Input Texture " << str << " not found!"; return false; } })) return false; if (!LoadArray(wrapper, "output", [&](const void* node) -> bool { if (!LoadValue(node, str)) { LOGE << "Pass's outputTexture name not found!"; return false; } if (auto texture = entityUtil->FindEntity<Texture>(str)) { AddTexture(texture, false); return true; } else { LOGW << "Output Texture " << str << " not found!"; return false; } })) return false; return true; }
bool Material::Load(const XMLElement& source) { ResetToDefaults(); if (source.IsNull()) { LOGERROR("Can not load material from null XML element"); return false; } ResourceCache* cache = GetSubsystem<ResourceCache>(); XMLElement techniqueElem = source.GetChild("technique"); techniques_.Clear(); while (techniqueElem) { Technique* tech = cache->GetResource<Technique>(techniqueElem.GetAttribute("name")); if (tech) { TechniqueEntry newTechnique; newTechnique.technique_ = tech; if (techniqueElem.HasAttribute("quality")) newTechnique.qualityLevel_ = techniqueElem.GetInt("quality"); if (techniqueElem.HasAttribute("loddistance")) newTechnique.lodDistance_ = techniqueElem.GetFloat("loddistance"); techniques_.Push(newTechnique); } techniqueElem = techniqueElem.GetNext("technique"); } SortTechniques(); XMLElement textureElem = source.GetChild("texture"); while (textureElem) { TextureUnit unit = TU_DIFFUSE; if (textureElem.HasAttribute("unit")) unit = ParseTextureUnitName(textureElem.GetAttribute("unit")); if (unit < MAX_TEXTURE_UNITS) { String name = textureElem.GetAttribute("name"); // Detect cube maps by file extension: they are defined by an XML file /// \todo Differentiate with 3D textures by actually reading the XML content if (GetExtension(name) == ".xml") { #ifdef DESKTOP_GRAPHICS if (unit == TU_VOLUMEMAP) SetTexture(unit, cache->GetResource<Texture3D>(name)); else #endif SetTexture(unit, cache->GetResource<TextureCube>(name)); } else SetTexture(unit, cache->GetResource<Texture2D>(name)); } textureElem = textureElem.GetNext("texture"); } batchedParameterUpdate_ = true; XMLElement parameterElem = source.GetChild("parameter"); while (parameterElem) { String name = parameterElem.GetAttribute("name"); SetShaderParameter(name, ParseShaderParameterValue(parameterElem.GetAttribute("value"))); parameterElem = parameterElem.GetNext("parameter"); } batchedParameterUpdate_ = false; XMLElement parameterAnimationElem = source.GetChild("parameteranimation"); while (parameterAnimationElem) { String name = parameterAnimationElem.GetAttribute("name"); SharedPtr<ValueAnimation> animation(new ValueAnimation(context_)); if (!animation->LoadXML(parameterAnimationElem)) { LOGERROR("Could not load parameter animation"); return false; } String wrapModeString = parameterAnimationElem.GetAttribute("wrapmode"); WrapMode wrapMode = WM_LOOP; for (int i = 0; i <= WM_CLAMP; ++i) { if (wrapModeString == wrapModeNames[i]) { wrapMode = (WrapMode)i; break; } } float speed = parameterAnimationElem.GetFloat("speed"); SetShaderParameterAnimation(name, animation, wrapMode, speed); parameterAnimationElem = parameterAnimationElem.GetNext("parameteranimation"); } XMLElement cullElem = source.GetChild("cull"); if (cullElem) SetCullMode((CullMode)GetStringListIndex(cullElem.GetAttribute("value").CString(), cullModeNames, CULL_CCW)); XMLElement shadowCullElem = source.GetChild("shadowcull"); if (shadowCullElem) SetShadowCullMode((CullMode)GetStringListIndex(shadowCullElem.GetAttribute("value").CString(), cullModeNames, CULL_CCW)); XMLElement fillElem = source.GetChild("fill"); if (fillElem) SetFillMode((FillMode)GetStringListIndex(fillElem.GetAttribute("value").CString(), fillModeNames, FILL_SOLID)); XMLElement depthBiasElem = source.GetChild("depthbias"); if (depthBiasElem) SetDepthBias(BiasParameters(depthBiasElem.GetFloat("constant"), depthBiasElem.GetFloat("slopescaled"))); RefreshShaderParameterHash(); RefreshMemoryUse(); CheckOcclusion(); return true; }
void MeshEntity::RenderLightmaps() { traceInFast(MeshEntity::RenderLightmaps); if(!mesh || !bLightmapped) return; LoadEffectData(); LoadVertexBuffer(VertBuffer); LoadIndexBuffer(mesh->IdxBuffer); HANDLE param[3]; param[0] = level->GetLightmapU();//GetActiveEffect()->GetParameterByName(TEXT("lightmapU")); param[1] = level->GetLightmapV();//GetActiveEffect()->GetParameterByName(TEXT("lightmapV")); param[2] = level->GetLightmapW();//GetActiveEffect()->GetParameterByName(TEXT("lightmapW")); if(lightmap.X) { GetActiveEffect()->SetTexture(param[0], lightmap.X); GetActiveEffect()->SetTexture(param[1], lightmap.Y); GetActiveEffect()->SetTexture(param[2], lightmap.Z); } else { //actually it should never get here Texture *black = GetTexture(TEXT("Base:Default/black.tga")); GetActiveEffect()->SetTexture(param[0], black); GetActiveEffect()->SetTexture(param[1], black); GetActiveEffect()->SetTexture(param[2], black); } for(DWORD i=0;i<mesh->nSections;i++) { DrawSection §ion = mesh->SectionList[i]; Material *material = MaterialList[i]; if(material && section.numFaces) { if(material->effect == GetActiveEffect()) { material->LoadParameters(); if(material->flags & MATERIAL_TWOSIDED) { GSCullMode cullMode; cullMode = GetCullMode(); SetCullMode(GS_NEITHER); Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); SetCullMode(cullMode); } else Draw(GS_TRIANGLES, 0, section.startFace*3, section.numFaces*3); } } } ResetEffectData(); traceOutFast; }
//! resizes the screen surface void DirectX11Driver::ResizeScreen(const Vector2& vSize) { if(m_Device.Get()) { ID3D11RenderTargetView* nullViews[] = { NULL }; m_ImmediateContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, NULL); m_RenderTargetView = NULL; m_DepthStencilView = NULL; m_SwapChain = NULL; m_MVPBuffer = NULL; m_TextureTransformBuffer = NULL; m_MaterialBuffer = NULL; m_TextureSamplerLinear = NULL; for(int i=0; i<2; ++i) { for(int j=0; j<D3D11_BLEND_INV_SRC1_ALPHA+1; ++j) { for(int k=0; k<D3D11_BLEND_INV_SRC1_ALPHA+1; ++k) { m_BlendState[i][j][k] = NULL; } } } for(int i=0; i<2; ++i) { for(int j=0; j<2; ++j) { for(int k=0; k<D3D11_COMPARISON_ALWAYS+1; ++k) { m_DepthStencilState[i][j][k] = NULL; } } } for(int i=0; i<2; ++i) { for(int j=0; j<D3D11_FILL_SOLID+1; ++j) { for(int k=0; k<D3D11_CULL_BACK+1; ++k) { m_RasterizerState[i][j][k] = NULL; } } } m_ImmediateContext->Flush(); DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0}; swapChainDesc.Width = newSize.Width; swapChainDesc.Height = newSize.Height; swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; swapChainDesc.Stereo = false; swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling. swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 1; // On phone, only single buffering is supported. swapChainDesc.Scaling = DXGI_SCALING_STRETCH; // On phone, only stretch and aspect-ratio stretch scaling are allowed. swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // On phone, no swap effects are supported. swapChainDesc.Flags = 0; COMReference<IDXGIDevice1> XGIDevice1; IDXGIDevice1* pIDXGIDevice1 = NULL; DX_ASSERT(m_Device->QueryInterface(__uuidof(IDXGIDevice1), (void**)&pIDXGIDevice1)); XGIDevice1 = pIDXGIDevice1; COMReference<IDXGIAdapter> XGIAdapter; IDXGIAdapter* pIDXGIAdapter = NULL; DX_ASSERT(XGIDevice1->GetAdapter(&pIDXGIAdapter)); XGIAdapter = pIDXGIAdapter; COMReference<IDXGIFactory2> XGIFactory2; IDXGIFactory2* pFactory = NULL; DX_ASSERT(XGIAdapter->GetParent(__uuidof(IDXGIFactory2), (void**)&pFactory)); XGIFactory2 = pFactory; // create swap chain IDXGISwapChain1* pSwapChain = NULL; #if SHOOT_PLATFORM == SHOOT_PLATFORM_WP8 DX_ASSERT(ShootCreateSwapChainForCoreWindow(XGIFactory2, m_Device, &swapChainDesc, &pSwapChain)); #else DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullScreenDesc; fullScreenDesc.RefreshRate.Numerator = 60; fullScreenDesc.RefreshRate.Denominator = 1; fullScreenDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; fullScreenDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; fullScreenDesc.Windowed = !App::Instance()->IsFullScreen(); DX_ASSERT(XGIFactory2->CreateSwapChainForHwnd(m_Device, m_hWindow, &swapChainDesc, &fullScreenDesc, NULL, &pSwapChain)); #endif m_SwapChain = pSwapChain; // Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and // ensures that the application will only render after each VSync, minimizing power consumption. DX_ASSERT(XGIDevice1->SetMaximumFrameLatency(1)); // Create render target & depth stencil views COMReference<ID3D11Texture2D> backBuffer; ID3D11Texture2D* pBackBuffer = NULL; DX_ASSERT(m_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer)); backBuffer = pBackBuffer; ID3D11RenderTargetView* pRenderTargetView = NULL; DX_ASSERT(m_Device->CreateRenderTargetView(backBuffer, NULL, &pRenderTargetView)); m_RenderTargetView = pRenderTargetView; COMReference<ID3D11Texture2D> depthStencil; ID3D11Texture2D* pDepthStencil = NULL; CD3D11_TEXTURE2D_DESC depthStencilDesc(DXGI_FORMAT_D24_UNORM_S8_UINT, newSize.Width, newSize.Height, 1, 1, D3D11_BIND_DEPTH_STENCIL); DX_ASSERT(m_Device->CreateTexture2D(&depthStencilDesc, NULL, &pDepthStencil)); depthStencil = pDepthStencil; CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D); ID3D11DepthStencilView* pDepthStencilView = NULL; DX_ASSERT(m_Device->CreateDepthStencilView(depthStencil, &depthStencilViewDesc, &pDepthStencilView)); m_DepthStencilView = pDepthStencilView; m_ImmediateContext->OMSetRenderTargets(1, &pRenderTargetView, m_DepthStencilView); m_RenderTargetView = pRenderTargetView; // create the constant buffers D3D11_BUFFER_DESC bd; ZeroMemory(&bd, sizeof(bd)); bd.Usage = D3D11_USAGE_DEFAULT; bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = 0; bd.ByteWidth = sizeof(Matrix44); ID3D11Buffer* pMVP = NULL; DX_ASSERT(m_Device->CreateBuffer(&bd, NULL, &pMVP)); m_MVPBuffer = pMVP; bd.ByteWidth = sizeof(Matrix44); ID3D11Buffer* pTextureTransformBuffer = NULL; DX_ASSERT(m_Device->CreateBuffer(&bd, NULL, &pTextureTransformBuffer)); m_TextureTransformBuffer = pTextureTransformBuffer; bd.ByteWidth = sizeof(Color); ID3D11Buffer* pMaterialBuffer = NULL; DX_ASSERT(m_Device->CreateBuffer(&bd, NULL, &pMaterialBuffer)); m_MaterialBuffer = pMaterialBuffer; // Create the texture samplers D3D11_SAMPLER_DESC sampDesc; ZeroMemory( &sampDesc, sizeof(sampDesc) ); sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; sampDesc.MinLOD = 0; sampDesc.MaxLOD = D3D11_FLOAT32_MAX; ID3D11SamplerState* pSampler = NULL; DX_ASSERT(m_Device->CreateSamplerState(&sampDesc, &pSampler)); m_TextureSamplerLinear = pSampler; // Create blend state ZeroMemory(&m_BlendDesc, sizeof(D3D11_BLEND_DESC)); m_BlendDesc.RenderTarget[0].BlendEnable = false; m_BlendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; m_BlendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; m_BlendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; m_BlendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO; m_BlendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; m_BlendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; m_BlendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; ID3D11BlendState* pBlendState = NULL; DX_ASSERT(m_Device->CreateBlendState(&m_BlendDesc, &pBlendState)); m_BlendState[m_BlendDesc.RenderTarget[0].BlendEnable][m_BlendDesc.RenderTarget[0].SrcBlend][m_BlendDesc.RenderTarget[0].DestBlend] = pBlendState; // Create depth stencil state ZeroMemory(&m_DSDesc, sizeof(D3D11_DEPTH_STENCIL_DESC)); m_DSDesc.DepthEnable = true; m_DSDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; m_DSDesc.DepthFunc = D3D11_COMPARISON_LESS; m_DSDesc.StencilEnable = false; ID3D11DepthStencilState* pDepthStencilState = NULL; DX_ASSERT(m_Device->CreateDepthStencilState(&m_DSDesc, &pDepthStencilState)); m_DepthStencilState[m_DSDesc.DepthEnable][m_DSDesc.DepthWriteMask][m_DSDesc.DepthFunc] = pDepthStencilState; // Create the rasterizer state ZeroMemory(&m_RSDesc, sizeof(D3D11_RASTERIZER_DESC)); m_RSDesc.AntialiasedLineEnable = false; m_RSDesc.CullMode = D3D11_CULL_BACK; m_RSDesc.DepthBias = 0; m_RSDesc.DepthBiasClamp = 0.0f; m_RSDesc.DepthClipEnable = true; m_RSDesc.FillMode = D3D11_FILL_SOLID; m_RSDesc.FrontCounterClockwise = false; m_RSDesc.MultisampleEnable = false; m_RSDesc.ScissorEnable = false; m_RSDesc.SlopeScaledDepthBias = 0.0f; ID3D11RasterizerState* pRasterizerState = NULL; DX_ASSERT(m_Device->CreateRasterizerState(&m_RSDesc, &pRasterizerState)); m_RasterizerState[m_RSDesc.FrontCounterClockwise][m_RSDesc.FillMode][m_RSDesc.CullMode] = pRasterizerState; SetCullMode(CM_CounterClockWise); } super::ResizeScreen(newSize); }
bool Material::Load(Deserializer& source) { PROFILE(LoadMaterial); // In headless mode, do not actually load the material, just return success Graphics* graphics = GetSubsystem<Graphics>(); if (!graphics) return true; ResetToDefaults(); ResourceCache* cache = GetSubsystem<ResourceCache>(); SharedPtr<XMLFile> xml(new XMLFile(context_)); if (!xml->Load(source)) return false; XMLElement rootElem = xml->GetRoot(); XMLElement techniqueElem = rootElem.GetChild("technique"); techniques_.Clear(); while (techniqueElem) { Technique* tech = cache->GetResource<Technique>(techniqueElem.GetAttribute("name")); if (tech) { TechniqueEntry newTechnique; newTechnique.technique_ = tech; if (techniqueElem.HasAttribute("quality")) newTechnique.qualityLevel_ = techniqueElem.GetInt("quality"); if (techniqueElem.HasAttribute("loddistance")) newTechnique.lodDistance_ = techniqueElem.GetFloat("loddistance"); techniques_.Push(newTechnique); } techniqueElem = techniqueElem.GetNext("technique"); } XMLElement textureElem = rootElem.GetChild("texture"); while (textureElem) { TextureUnit unit = TU_DIFFUSE; if (textureElem.HasAttribute("unit")) { String unitName = textureElem.GetAttributeLower("unit"); if (unitName.Length() > 1) { unit = ParseTextureUnitName(unitName); if (unit >= MAX_MATERIAL_TEXTURE_UNITS) LOGERROR("Unknown or illegal texture unit " + unitName); } else unit = (TextureUnit)Clamp(ToInt(unitName), 0, MAX_MATERIAL_TEXTURE_UNITS - 1); } if (unit != MAX_MATERIAL_TEXTURE_UNITS) { String name = textureElem.GetAttribute("name"); // Detect cube maps by file extension: they are defined by an XML file if (GetExtension(name) == ".xml") SetTexture(unit, cache->GetResource<TextureCube>(name)); else SetTexture(unit, cache->GetResource<Texture2D>(name)); } textureElem = textureElem.GetNext("texture"); } XMLElement parameterElem = rootElem.GetChild("parameter"); while (parameterElem) { String name = parameterElem.GetAttribute("name"); Variant value = parameterElem.GetVectorVariant("value"); SetShaderParameter(name, value); parameterElem = parameterElem.GetNext("parameter"); } XMLElement cullElem = rootElem.GetChild("cull"); if (cullElem) SetCullMode((CullMode)GetStringListIndex(cullElem.GetAttribute("value").CString(), cullModeNames, CULL_CCW)); XMLElement shadowCullElem = rootElem.GetChild("shadowcull"); if (shadowCullElem) SetShadowCullMode((CullMode)GetStringListIndex(shadowCullElem.GetAttribute("value").CString(), cullModeNames, CULL_CCW)); XMLElement depthBiasElem = rootElem.GetChild("depthbias"); if (depthBiasElem) SetDepthBias(BiasParameters(depthBiasElem.GetFloat("constant"), depthBiasElem.GetFloat("slopescaled"))); // Calculate memory use unsigned memoryUse = sizeof(Material); memoryUse += techniques_.Size() * sizeof(TechniqueEntry); memoryUse += MAX_MATERIAL_TEXTURE_UNITS * sizeof(SharedPtr<Texture>); memoryUse += shaderParameters_.Size() * sizeof(MaterialShaderParameter); SetMemoryUse(memoryUse); CheckOcclusion(); return true; }