void D3D10System::LoadVertexShader(Shader *vShader) { if(curVertexShader != vShader) { if(vShader) { D3D10VertexBuffer *lastVertexBuffer = curVertexBuffer; if(curVertexBuffer) LoadVertexBuffer(NULL); D3D10VertexShader *shader = static_cast<D3D10VertexShader*>(vShader); d3d->VSSetShader(shader->vertexShader); d3d->IASetInputLayout(shader->inputLayout); d3d->VSSetConstantBuffers(0, 1, &shader->constantBuffer); if(lastVertexBuffer) LoadVertexBuffer(lastVertexBuffer); } else { LPVOID lpNULL = NULL; d3d->VSSetShader(NULL); d3d->VSSetConstantBuffers(0, 1, (ID3D10Buffer**)&lpNULL); } curVertexShader = static_cast<D3D10VertexShader*>(vShader); } }
void MeshEntity::RenderBare(BOOL bUseTransform) { traceInFast(MeshEntity::RenderBare); if(!mesh) return; if(bUseTransform) { MatrixPush(); MatrixMultiply(invTransform); if(bHasScale) MatrixScale(scale); } LoadVertexBuffer(VertBuffer); LoadIndexBuffer(mesh->IdxBuffer); GS->DrawBare(GS_TRIANGLES, 0, 0, mesh->nFaces*3); LoadVertexBuffer(NULL); LoadIndexBuffer(NULL); if(bUseTransform) MatrixPop(); traceOutFast; }
void MeshObject::RenderBare() { traceIn(MeshObject::RenderBare); LoadVertexBuffer(mesh->VertBuffer); LoadIndexBuffer(mesh->IdxBuffer); GS->DrawBare(GS_TRIANGLES, 0, 0, mesh->nFaces*3); LoadVertexBuffer(NULL); LoadIndexBuffer(NULL); traceOut; }
void MT_Terrain::Init(ID3D11Device *d3dDevice, ID3D11DeviceContext *d3dDeviceContext) { m_shader = new MT_Shader(); m_shader->Init(d3dDevice, d3dDeviceContext, k_VertexShaderFileName, k_PixelShaderFileName); m_heightMap = new MT_HeightMap(); m_heightMap->Init(TERRAIN_HEIGHTMAP_PATH); m_texture = new MT_Texture(); m_texture->LoadTexture(d3dDevice, d3dDeviceContext, TERRAIN_TEXTURE_GRASS_PATH); m_texture->LoadTexture(d3dDevice, d3dDeviceContext, TERRAIN_TEXTURE_ROCK_PATH); m_texture->LoadTexture(d3dDevice, d3dDeviceContext, TERRAIN_TEXTURE_WATER_PATH); m_texture->LoadSampler(d3dDevice, d3dDeviceContext); m_light = new MT_Light(); LightBufferValues lightValues; lightValues.ambient = k_Light_Ambient; lightValues.diffuse = k_Light_Diffuse; lightValues.direction = k_Light_Direction; lightValues.light_enabled = LIGHT_TOGGLE; lightValues.texture_enabled = TEXTURE_TOGGLE; m_light->Init(d3dDevice, d3dDeviceContext, lightValues); CreateInputLayoutObjectForVertexBuffer(d3dDevice, d3dDeviceContext, m_shader->GetVertexShaderBlob()); m_toggle_flatGrid = TOGGLE_FLAT_GRID; LoadVertexBuffer(d3dDevice, d3dDeviceContext); LoadIndexBuffer(d3dDevice, d3dDeviceContext); }
void D3D10System::UnloadAllData() { LoadVertexShader(NULL); LoadPixelShader(NULL); LoadVertexBuffer(NULL); for(UINT i=0; i<8; i++) { LoadSamplerState(NULL, i); LoadTexture(NULL, i); } UINT zeroVal = 0; LPVOID nullBuff[8]; float bla[4] = {1.0f, 1.0f, 1.0f, 1.0f}; zero(nullBuff, sizeof(nullBuff)); d3d->VSSetConstantBuffers(0, 1, (ID3D10Buffer**)nullBuff); d3d->PSSetConstantBuffers(0, 1, (ID3D10Buffer**)nullBuff); d3d->OMSetDepthStencilState(NULL, 0); d3d->PSSetSamplers(0, 1, (ID3D10SamplerState**)nullBuff); d3d->OMSetBlendState(NULL, bla, 0xFFFFFFFF); d3d->OMSetRenderTargets(1, (ID3D10RenderTargetView**)nullBuff, NULL); d3d->IASetVertexBuffers(0, 8, (ID3D10Buffer**)nullBuff, &zeroVal, &zeroVal); d3d->PSSetShaderResources(0, 8, (ID3D10ShaderResourceView**)nullBuff); d3d->IASetInputLayout(NULL); d3d->PSSetShader(NULL); d3d->VSSetShader(NULL); d3d->RSSetState(NULL); }
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; }
//Loads the Vertex and Index buffers void ColladaMesh::LoadBuffers(daeElement *geometry) { if(diffuseTexture == 0) { HR(D3DX11CreateShaderResourceViewFromFile(device, L"../Assets/Textures/stone2.jpg", 0, 0, &diffuseTexture, 0 )); } //Create the vertex buffer by passing the pointer to the mesh daeElement LoadVertexBuffer(geometry->getChild("mesh")); //Create the index buffer by passing the pointer to the mesh daeElement LoadIndexBuffer(geometry->getChild("mesh")); }
void D3D10System::DrawSpriteEx(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2) { if(!curPixelShader) return; if(!texture) { AppWarning(TEXT("Trying to draw a sprite with a NULL texture")); return; } HANDLE hColor = curPixelShader->GetParameterByName(TEXT("outputColor")); if(hColor) curPixelShader->SetColor(hColor, color); if(x2 == -998.0f && y2 == -998.0f) { x2 = float(texture->Width()); y2 = float(texture->Height()); } if(u == -998.0f && v == -998.0f) { u = 0.0f; v = 0.0f; } if(u2 == -998.0f && v2 == -998.0f) { u2 = 1.0f; v2 = 1.0f; } VBData *data = spriteVertexBuffer->GetData(); data->VertList[0].Set(x, y, 0.0f); data->VertList[1].Set(x, y2, 0.0f); data->VertList[2].Set(x2, y, 0.0f); data->VertList[3].Set(x2, y2, 0.0f); List<UVCoord> &coords = data->UVList[0]; coords[0].Set(u, v); coords[1].Set(u, v2); coords[2].Set(u2, v); coords[3].Set(u2, v2); spriteVertexBuffer->FlushBuffers(); LoadVertexBuffer(spriteVertexBuffer); LoadTexture(texture); Draw(GS_TRIANGLESTRIP); }
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; }
/** **************************************************************************************************** \fn bool Initialize( void ) \brief Initialize the sphere class \param NONE \return boolean \retval SUCCESS success \retval FAIL otherwise **************************************************************************************************** */ bool RendererEngine::Sphere::Initialize( void ) { _vertexBuffer = NULL; m_hashedVertexShader = Utilities::StringHash( "original.vp" ); if ( !CreateVertexShader("original.vp") ) return FAIL; m_hashedFragmentShader = Utilities::StringHash( "original.fp" ); if( !CreateFragmentShader("original.fp") ) return FAIL; S_SPHERE_TO_DRAW sphere = { D3DXVECTOR3(0.0f, 0.0f, 0.0f), Utilities::WHITE, Utilities::DEFAULT_DEBUG_SPHERE_RADIUS }; if( !LoadVertexBuffer(sphere) ) return FAIL; return SUCCESS; }
void D3D10System::DrawBox(const Vect2 &upperLeft, const Vect2 &size) { VBData *data = boxVertexBuffer->GetData(); Vect2 bottomRight = upperLeft+size; data->VertList[0] = upperLeft; data->VertList[1].Set(bottomRight.x, upperLeft.y); data->VertList[2].Set(bottomRight.x, bottomRight.y); data->VertList[3].Set(upperLeft.x, bottomRight.y); data->VertList[4] = upperLeft; boxVertexBuffer->FlushBuffers(); LoadVertexBuffer(boxVertexBuffer); Draw(GS_LINESTRIP); }
void CAnimatedInstanceModel::Initialize(CAnimatedCoreModel *AnimatedCoreModel) { m_AnimatedCoreModel = AnimatedCoreModel; m_CalModel = new CalModel(m_AnimatedCoreModel->GetCalCoreModel()); m_CalHardwareModel = new CalHardwareModel(m_AnimatedCoreModel->GetCalCoreModel()); // attach all meshes to the model //int meshId; //for (meshId = 0; meshId < AnimatedCoreModel->GetCalCoreModel()->getCoreMeshCount(); meshId++) //{ // m_CalModel->attachMesh(meshId); //} LoadVertexBuffer(); LoadMaterials(); BlendCycle(1, 1.0f, 0.0f); Update(0.0f); }
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 MeshEntity::RenderWireframe() { traceInFast(MeshEntity::RenderWireframe); Shader *shader = GetCurrentVertexShader(); if(shader) shader->SetColor(shader->GetParameter(1), wireframeColor | 0xFF000000); MatrixPush(); MatrixMultiply(invTransform); LoadVertexBuffer(VertBuffer); LoadIndexBuffer(mesh->WireframeBuffer); GS->DrawBare(GS_LINES); MatrixPop(); traceOutFast; }
void D3D10System::DrawSpriteExRotate(Texture *texture, DWORD color, float x, float y, float x2, float y2, float degrees, float u, float v, float u2, float v2, float texDegrees) { if(!curPixelShader) return; if(!texture) { AppWarning(TEXT("Trying to draw a sprite with a NULL texture")); return; } HANDLE hColor = curPixelShader->GetParameterByName(TEXT("outputColor")); if(hColor) curPixelShader->SetColor(hColor, color); //------------------------------ // crop positional values Vect2 totalSize = Vect2(x2-x, y2-y); Vect2 invMult = Vect2(totalSize.x < 0.0f ? -1.0f : 1.0f, totalSize.y < 0.0f ? -1.0f : 1.0f); totalSize.Abs(); if(y2-y < 0) { float tempFloat = curCropping[1]; curCropping[1] = curCropping[3]; curCropping[3] = tempFloat; } if(x2-x < 0) { float tempFloat = curCropping[0]; curCropping[0] = curCropping[2]; curCropping[2] = tempFloat; } x += curCropping[0] * invMult.x; y += curCropping[1] * invMult.y; x2 -= curCropping[2] * invMult.x; y2 -= curCropping[3] * invMult.y; //------------------------------ // crop texture coordinate values float cropMult[4]; cropMult[0] = curCropping[0]/totalSize.x; cropMult[1] = curCropping[1]/totalSize.y; cropMult[2] = curCropping[2]/totalSize.x; cropMult[3] = curCropping[3]/totalSize.y; Vect2 totalUVSize = Vect2(u2-u, v2-v); u += cropMult[0] * totalUVSize.x; v += cropMult[1] * totalUVSize.y; u2 -= cropMult[2] * totalUVSize.x; v2 -= cropMult[3] * totalUVSize.y; //------------------------------ // draw VBData *data = spriteVertexBuffer->GetData(); data->VertList[0].Set(x, y, 0.0f); data->VertList[1].Set(x, y2, 0.0f); data->VertList[2].Set(x2, y, 0.0f); data->VertList[3].Set(x2, y2, 0.0f); if (!CloseFloat(degrees, 0.0f)) { List<Vect> &coords = data->VertList; Vect2 center(x+totalSize.x/2, y+totalSize.y/2); Matrix rotMatrix; rotMatrix.SetIdentity(); rotMatrix.Rotate(AxisAngle(0.0f, 0.0f, 1.0f, RAD(degrees))); for (int i = 0; i < 4; i++) { Vect val = coords[i]-Vect(center); val.TransformVector(rotMatrix); coords[i] = val; coords[i] += Vect(center); } } List<UVCoord> &coords = data->UVList[0]; coords[0].Set(u, v); coords[1].Set(u, v2); coords[2].Set(u2, v); coords[3].Set(u2, v2); if (!CloseFloat(texDegrees, 0.0f)) { Matrix rotMatrix; rotMatrix.SetIdentity(); rotMatrix.Rotate(AxisAngle(0.0f, 0.0f, 1.0f, -RAD(texDegrees))); Vect2 minVal = Vect2(0.0f, 0.0f); for (int i = 0; i < 4; i++) { Vect val = Vect(coords[i]); val.TransformVector(rotMatrix); coords[i] = val; minVal.ClampMax(coords[i]); } for (int i = 0; i < 4; i++) coords[i] -= minVal; } spriteVertexBuffer->FlushBuffers(); LoadVertexBuffer(spriteVertexBuffer); LoadTexture(texture); Draw(GS_TRIANGLESTRIP); }
void RotationManipulator::RenderScaled(const Vect &cameraDir, float scale) { traceInFast(RotationManipulator::RenderScaled); DWORD i; Shader *rotManipShader = GetVertexShader(TEXT("Editor:RotationManipulator.vShader")); LoadVertexShader(rotManipShader); LoadPixelShader(GetPixelShader(TEXT("Base:SolidColor.pShader"))); rotManipShader->SetVector(rotManipShader->GetParameter(2), cameraDir); MatrixPush(); MatrixTranslate(GetWorldPos()); MatrixScale(scale, scale, scale); for(i=0; i<3; i++) { Vect axisColor(0.0f, 0.0f, 0.0f); axisColor.ptr[i] = 1.0f; if(i == activeAxis) axisColor.Set(1.0f, 1.0f, 0.0f); else axisColor.ptr[i] = 1.0f; rotManipShader->SetVector(rotManipShader->GetParameter(1), axisColor); LoadVertexBuffer(axisBuffers[i]); LoadIndexBuffer(NULL); Draw(GS_LINESTRIP); } LoadVertexBuffer(NULL); //---------------------------------------------------- Shader *solidShader = GetVertexShader(TEXT("Base:SolidColor.vShader")); LoadVertexShader(solidShader); MatrixPush(); MatrixRotate(Quat().SetLookDirection(cameraDir)); LoadVertexBuffer(axisBuffers[2]); LoadIndexBuffer(NULL); solidShader->SetColor(solidShader->GetParameter(1), 0.5, 0.5, 0.5, 0.5); Draw(GS_LINESTRIP); MatrixScale(1.25f, 1.25f, 1.25f); //--------------- if(activeAxis == 4) solidShader->SetColor(solidShader->GetParameter(1), 1.0f, 1.0f, 0.0, 1.0f); else solidShader->SetColor(solidShader->GetParameter(1), 0.8, 0.8, 0.8, 0.8); Draw(GS_LINESTRIP); MatrixPop(); MatrixPop(); LoadVertexShader(NULL); LoadPixelShader(NULL); traceOutFast; }
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; }
void D3D10System::DrawSpriteEx(Texture *texture, DWORD color, float x, float y, float x2, float y2, float u, float v, float u2, float v2) { if(!curPixelShader) return; if(!texture) { AppWarning(TEXT("Trying to draw a sprite with a NULL texture")); return; } HANDLE hColor = curPixelShader->GetParameterByName(TEXT("outputColor")); if(hColor) curPixelShader->SetColor(hColor, color); //------------------------------ // crop positional values Vect2 totalSize = Vect2(x2-x, y2-y); Vect2 invMult = Vect2(totalSize.x < 0.0f ? -1.0f : 1.0f, totalSize.y < 0.0f ? -1.0f : 1.0f); totalSize.Abs(); x += curCropping[0] * invMult.x; y += curCropping[1] * invMult.y; x2 -= curCropping[2] * invMult.x; y2 -= curCropping[3] * invMult.y; //------------------------------ // crop texture coordinate values float cropMult[4]; cropMult[0] = curCropping[0]/totalSize.x; cropMult[1] = curCropping[1]/totalSize.y; cropMult[2] = curCropping[2]/totalSize.x; cropMult[3] = curCropping[3]/totalSize.y; Vect2 totalUVSize = Vect2(u2-u, v2-v); u += cropMult[0] * totalUVSize.x; v += cropMult[1] * totalUVSize.y; u2 -= cropMult[2] * totalUVSize.x; v2 -= cropMult[3] * totalUVSize.y; //------------------------------ // draw VBData *data = spriteVertexBuffer->GetData(); data->VertList[0].Set(x, y, 0.0f); data->VertList[1].Set(x, y2, 0.0f); data->VertList[2].Set(x2, y, 0.0f); data->VertList[3].Set(x2, y2, 0.0f); List<UVCoord> &coords = data->UVList[0]; coords[0].Set(u, v); coords[1].Set(u, v2); coords[2].Set(u2, v); coords[3].Set(u2, v2); spriteVertexBuffer->FlushBuffers(); LoadVertexBuffer(spriteVertexBuffer); LoadTexture(texture); Draw(GS_TRIANGLESTRIP); }