void VegetationView::draw(const GameTime& gameTime) { GraphicsManager& manager = getManager(); const VegetationController& controller = getController(); GraphicsDevice device = manager.getDevice(); unsigned long prevCullMode = device.getRenderState(D3DRS_CULLMODE); device.setRenderState(D3DRS_CULLMODE, D3DCULL_NONE); Matrix world = controller.getWorld() * manager.getWorld(); const Matrix& view = manager.getView(); const Matrix& projection = manager.getProjection(); for (Vegetation::iterator it = vegetation.begin(); it != vegetation.end(); ++it) { FBXModel& model = it->model; model.setClipPlane(manager.getClipPlane()); model.setCamera(manager.getCamera()); model.setLight(manager.getLight()); model.draw(device, gameTime, world, view, projection, it->transforms, it->transforms.size(), manager.isRenderShadowMap()); } device.setRenderState(D3DRS_CULLMODE, prevCullMode); }
std::unique_ptr<Shader> HLSLCompiler::CreateShaderFromSource( GraphicsDevice & graphicsDevice, const void* shaderSource, std::size_t byteLength, const std::string& entryPoint, ShaderPipelineStage pipelineStage, const Optional<std::string>& currentDirectory) { POMDOG_ASSERT(shaderSource != nullptr); POMDOG_ASSERT(byteLength > 0); POMDOG_ASSERT(graphicsDevice.GetSupportedLanguage() == ShaderLanguage::HLSL); auto nativeGraphicsDevice = graphicsDevice.GetNativeGraphicsDevice(); ShaderBytecode shaderBytecode; shaderBytecode.Code = shaderSource; shaderBytecode.ByteLength = byteLength; ShaderCompileOptions compileOptions; compileOptions.EntryPoint = entryPoint; compileOptions.Profile.PipelineStage = pipelineStage; compileOptions.Profile.ShaderModel.Major = 4; compileOptions.Profile.ShaderModel.Minor = 0; compileOptions.Precompiled = false; if (currentDirectory) { compileOptions.CurrentDirectory = *currentDirectory; } return nativeGraphicsDevice->CreateShader(shaderBytecode, compileOptions); }
GameAsset* ShaderEffect::Create(StreamReader& reader, GameAsset* existingInstance) { GraphicsDevice* graphicsDevice = static_cast<GraphicsDevice*>(reader.ReadModule(GraphicsDevice::ClassID)); reader.ReadInt(); // NOT USED const int codeLength = reader.ReadInt(); byte* code = BBStackAlloc(byte, codeLength); reader.Read(code, codeLength); ID3DXEffect* handle = nullptr; ID3DXBuffer* errorBuffer = nullptr; HRESULT result = D3DXCreateEffect(graphicsDevice->GetD3DDevice(), code, codeLength, NULL, NULL, D3DXSHADER_OPTIMIZATION_LEVEL3, 0, &handle, &errorBuffer); if (result != D3D_OK) { Log::Error("ShaderEffect", Int::ToString(result).CStr()); if (errorBuffer) Log::Error("ShaderEffect", reinterpret_cast<const char*>(errorBuffer->GetBufferPointer())); } if (existingInstance == nullptr) existingInstance = new ShaderEffect(graphicsDevice); static_cast<ShaderEffect*>(existingInstance)->Setup(handle); BBStackFree(code); return existingInstance; }
void LuckyLeprechauns::toggleWireframe() { GraphicsDevice device = getGraphicsDevice(); unsigned long fillMode = device.getRenderState(D3DRS_FILLMODE) == D3DFILL_SOLID ? D3DFILL_WIREFRAME : D3DFILL_SOLID; device.setRenderState(D3DRS_FILLMODE, fillMode); }
SpriteBatch::SpriteBatch(GraphicsDevice &window) { changes = true; size = vector2f((float) window.GetSize().x, (float) window.GetSize().y); (this->graphicsDevice) = &window; glGenBuffers(2, &buffer[0]); }
void GameLoop::updateRender(RenderContext &rc) { const DisplayCaps settings = m_window.getSettings(); const core::math::Vec2f screenDims((f32) settings.m_width, (f32) settings.m_height); SceneManager &sm = m_instance.m_sm; CameraSystem &cameraSys = m_instance.m_cameraSys; GraphicsDevice gd; //--------------------- rc.m_fboGBuffer.activate(); // TODO(kulseran): defer rendering pass rc.m_fboGBuffer.deactivate(); //--------------------- /* camera.update((f32) ticker.dt(), settings.m_width, settings.m_height, m_inputManager); fsengine::render::MeshBuffer mesh = drawPrim.beginMesh(fsengine::render::eDrawLayer::DRAW_LAYER_WORLD_DIFUSE, *debugMaterial); fsengine::render::MeshBuilder builder(mesh); core::math::Matrix44 impactLoc = core::math::G_IdentityMatrix44; impactLoc.pos() = core::math::G_ZeroVector4; impactLoc.at() *= 0.5; impactLoc.up() *= 0.5; impactLoc.left() *= 0.5; builder.insertCube(impactLoc, core::math::Color(100, 196, 64, 128)); drawPrim.endMesh(mesh); cameraSys.addCamera(camera); cameraSys.update(screenDims); drawPrim.prerender(sm, fsengine::render::eDrawLayer::DRAW_LAYER_WORLD_DIFUSE); sm.render(fsengine::render::eDrawLayer::DRAW_LAYER_WORLD_DIFUSE, cameraSys, gd); debugDraw.render(camera); debugDraw.clear(); drawPrim.clear(); */ // Render Hud fsengine::hud::HudCamera cameraHud(screenDims); cameraSys.addCamera(cameraHud); cameraSys.update(screenDims); gd.clearDepth(); HudContainer &hud = m_instance.m_hud; hud.update(1.0f / 60.0f, screenDims, m_inputManager); hud.prerender(sm, fsengine::render::eDrawLayer::DRAW_LAYER_HUD_BASE); hud.prerender(sm, fsengine::render::eDrawLayer::DRAW_LAYER_HUD_ICONS); hud.prerender(sm, fsengine::render::eDrawLayer::DRAW_LAYER_HUD_TEXT); hud.prerender(sm, fsengine::render::eDrawLayer::DRAW_LAYER_HUD_CURSOR); sm.render(fsengine::render::eDrawLayer::DRAW_LAYER_HUD_BASE, cameraSys, gd); sm.render(fsengine::render::eDrawLayer::DRAW_LAYER_HUD_ICONS, cameraSys, gd); sm.render(fsengine::render::eDrawLayer::DRAW_LAYER_HUD_TEXT, cameraSys, gd); sm.render(fsengine::render::eDrawLayer::DRAW_LAYER_HUD_CURSOR, cameraSys, gd); // Finish sm.clear(); gd.restoreState(fsengine::device::GraphicsState()); CHECK(gd.verify()); }
void TerrainTessellator::draw(const GraphicsDevice& device, unsigned levelOfDetail, unsigned primitiveCount, const IndexBufferCollection& indexBuffers) const { device.setStreamSource(vertexBuffer, sizeof(TerrainVertex)); device.setIndices(indexBuffers[levelOfDetail]); device.setFVF(TerrainVertex::fvf); device.drawIndexedPrimitive(D3DPT_TRIANGLELIST, primitiveCount, numVertices); }
void D3D11RenderTarget::load(GraphicsDevice &g, const UINT width, const UINT height) { m_graphics = &g.castD3D11(); m_width = width; m_height = height; g.castD3D11().registerAsset(this); reset(); }
void Model::draw(const GraphicsDevice& device) { for (unsigned i = 0; i < materials.size(); ++i) { device.setMaterial(materials[i]); device.setTexture(textures[i]); mesh.drawSubset(i); } }
void WaterView::onResetDevice(const GraphicsDevice& device) { Viewport viewport = device.getViewport(); reflectionmap = Texture::create(device, viewport.Width, viewport.Height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT); refractionmap = Texture::create(device, viewport.Width, viewport.Height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT); reflectionSurface = reflectionmap.getSurfaceLevel(); refractionSurface = refractionmap.getSurfaceLevel(); zBuffer = device.createDepthStencilSurface(viewport.Width, viewport.Height, D3DFMT_D24X8); effect.onResetDevice(); }
void RenderPath2D::ResizeBuffers() { RenderPath::ResizeBuffers(); GraphicsDevice* device = wiRenderer::GetDevice(); wiRenderer::GetDevice()->WaitForGPU(); FORMAT defaultTextureFormat = device->GetBackBufferFormat(); if(GetDepthStencil() != nullptr && wiRenderer::GetResolutionScale() != 1.0f) { TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; desc.Format = defaultTextureFormat; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; device->CreateTexture2D(&desc, nullptr, &rtStenciled); device->SetName(&rtStenciled, "rtStenciled"); } { TextureDesc desc; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; desc.Format = defaultTextureFormat; desc.Width = device->GetScreenWidth(); desc.Height = device->GetScreenHeight(); device->CreateTexture2D(&desc, nullptr, &rtFinal); device->SetName(&rtFinal, "rtFinal"); } }
IndexBuffer TerrainTessellator::createPatchIndexBuffer(const GraphicsDevice& device, unsigned levelOfDetail) { // distance between two neighbor vertices int delta = MathHelper::pow2(levelOfDetail); // size of grid in current lod (e.g. lod 0: 64, lod 1: 32) int lodSize = size / delta; // main indices + skirt indices int numIndices = lodSize * lodSize * 6; IndexCollection indices(numIndices); int count = 0; unsigned interval = min(stripeSize * delta, size); // init main indices for (unsigned i = 0; i < size / interval; ++i) for (unsigned row = 0; row < size; row += delta) for (unsigned col = i * interval; col < (i+1) * interval; col += delta) initQuadIndices(row, col, delta, delta, &indices, &count); IndexBuffer indexBuffer = device.createIndexBuffer(sizeof(TerrainIndex) * numIndices, indexFormat, D3DUSAGE_WRITEONLY); indexBuffer.setData(indices); return indexBuffer; }
void Indicator::RenderBox(GraphicsDevice &GD, MatrixController &MC, float Radius, const Rectangle3f &Rect, RGBColor Color) { RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Min.y, Rect.Min.z), Vec3f(Rect.Max.x, Rect.Min.y, Rect.Min.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Min.y, Rect.Min.z), Vec3f(Rect.Max.x, Rect.Max.y, Rect.Min.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Max.y, Rect.Min.z), Vec3f(Rect.Min.x, Rect.Max.y, Rect.Min.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Max.y, Rect.Min.z), Vec3f(Rect.Min.x, Rect.Min.y, Rect.Min.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Min.y, Rect.Min.z), Vec3f(Rect.Min.x, Rect.Min.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Min.y, Rect.Min.z), Vec3f(Rect.Max.x, Rect.Min.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Max.y, Rect.Min.z), Vec3f(Rect.Max.x, Rect.Max.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Max.y, Rect.Min.z), Vec3f(Rect.Min.x, Rect.Max.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Min.y, Rect.Max.z), Vec3f(Rect.Max.x, Rect.Min.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Min.y, Rect.Max.z), Vec3f(Rect.Max.x, Rect.Max.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Max.x, Rect.Max.y, Rect.Max.z), Vec3f(Rect.Min.x, Rect.Max.y, Rect.Max.z), Color); RenderCylinder(GD, MC, Radius, Vec3f(Rect.Min.x, Rect.Max.y, Rect.Max.z), Vec3f(Rect.Min.x, Rect.Min.y, Rect.Max.z), Color); Matrix4 Scale = Matrix4::Scaling(Rect.Dimensions()); Matrix4 Translate = Matrix4::Translation(Rect.Min); MC.World = Scale * Translate; LPDIRECT3DDEVICE9 Device = GD.CastD3D9().GetDevice(); D3DCOLOR D3DColor = RGBColor(90, 90, 90); Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_BLENDFACTOR); Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVBLENDFACTOR); Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); Device->SetRenderState(D3DRS_BLENDFACTOR, D3DColor); _Box.SetColor(Color); _Box.Render(); Device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); }
VertexBuffer::VertexBuffer( GraphicsDevice & graphicsDevice, const void* vertices, std::size_t vertexCountIn, std::size_t strideInBytesIn, BufferUsage bufferUsageIn) : vertexCount(static_cast<decltype(vertexCount)>(vertexCountIn)) , strideInBytes(static_cast<decltype(strideInBytes)>(strideInBytesIn)) , bufferUsage(bufferUsageIn) { POMDOG_ASSERT(vertices != nullptr); POMDOG_ASSERT(vertexCount > 0); POMDOG_ASSERT(strideInBytes > 0); auto sizeInBytes = vertexCount * strideInBytes; auto nativeDevice = graphicsDevice.GetNativeGraphicsDevice(); POMDOG_ASSERT(nativeDevice != nullptr); using Detail::BufferBindMode; nativeVertexBuffer = nativeDevice->CreateBuffer( vertices, sizeInBytes, bufferUsage, BufferBindMode::VertexBuffer); POMDOG_ASSERT(nativeVertexBuffer); }
/// Creates and returns the renderer if valid GraphicsDevice* Window::createRenderer() { GraphicsDevice* renderer = NULL; // Try to assemble the renderer #ifdef NEPHILIM_DESKTOP renderer = new RendererOpenGL(); #elif defined NEPHILIM_ANDROID || defined NEPHILIM_IOS if (gEnv->glesHint == 2) renderer = new RendererGLES2(); /*else renderer = new RendererGLES();*/ #endif if (renderer) { // renderer->m_target = this; renderer->m_window = this; renderer->setDefaultTarget(); renderer->setDefaultShader(); renderer->setDefaultBlending(); renderer->setDefaultTransforms(); renderer->setDefaultViewport(); renderer->setDefaultDepthTesting(); } return renderer; }
void RenderBatch::render(GraphicsDevice& device) { radixSort(queue); for(size_t i = 0; i < queue.size(); i++) device.draw(queue[i].second); queue.clear(); }
void BuildAtlasInfo(const GraphicsDevice& gfxDevice, const Model& model, const ObjMaterialLib& materials, AtlasInfo* atlasInfo) { for (uint i = 0; i < model.getBatchCount(); ++i) { const MaterialShaderData& matData = materials.getMaterialShaderData(model.getBatchMaterialName(i)); uint texWidth, texHeight; gfxDevice.getTextureSize(matData.GetAlbedoMap(), &texWidth, &texHeight); } }
void D3D9PixelShader::Reset(GraphicsDevice &graphics) { FreeMemory(); HRESULT hr; _device = graphics.CastD3D9().GetDevice(); Assert(_device != NULL, "_device == NULL"); DWORD dwShaderFlags = 0; #ifdef DEBUG_PS dwShaderFlags |= D3DXSHADER_SKIPOPTIMIZATION | D3DXSHADER_DEBUG; #endif LPD3DXBUFFER pCode = NULL; LPD3DXBUFFER pErrors = NULL; PersistentAssert(Utility::FileExists(_shaderFile), String("Shader file not found: ") + _shaderFile); // Assemble the vertex shader from the file hr = D3DXCompileShaderFromFile( _shaderFile.CString(), NULL, NULL, "PShaderEntry", "ps_3_0", dwShaderFlags, &pCode, &pErrors, &_constantTable ); String ErrorString; if(pErrors) { char *ErrorMessage = (char *)pErrors->GetBufferPointer(); DWORD ErrorLength = pErrors->GetBufferSize(); ofstream file("ShaderDebug.txt"); for(UINT i = 0; i < ErrorLength; i++) { file << ErrorMessage[i]; ErrorString += String(ErrorMessage[i]); } file.close(); } PersistentAssert(!FAILED(hr), String("D3DXCompileShaderFromFile failed: ") + ErrorString); hr = _device->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(), &_shader ); if(pErrors) { pErrors->Release(); } if(pCode) { pCode->Release(); } PersistentAssert(!FAILED(hr), "CreatePixelShader failed"); }
void CubeMesh::DrawRay(const D3DXVECTOR2& screenPos, const D3DXMATRIX& matWorld, const D3DXMATRIX& matView, const D3DXMATRIX& matProj) { HRESULT hr = S_FALSE; GraphicsDevice* pGDevice = GraphicsDevice::getInstance(); IDirect3DDevice9* pDevice = pGDevice->m_pD3DDevice; Ray ray = CalcPickingRay((int)screenPos.x, (int)screenPos.y, pGDevice->mCubeViewport, matView, matProj ); PCVertex rayLine[] = { {D3DXVECTOR3(0.0f,0.0f,0.0f), D3DCOLOR_ARGB(255,255,0,0)}, {ray.Origin + 1000*ray.Direction, D3DCOLOR_ARGB(255,255,0,0)}, }; PCVertex intersectPoint[] = { {p, D3DCOLOR_ARGB(255,0,0,255)}, {p+D3DXVECTOR3(0.5f,0.0f,0.0f), D3DCOLOR_ARGB(255,0,0,255)}, {p+D3DXVECTOR3(0.0f,0.5f,0.0f), D3DCOLOR_ARGB(255,0,0,255)}, {p+D3DXVECTOR3(0.0f,0.0f,0.5f), D3DCOLOR_ARGB(255,0,0,255)}, {p+D3DXVECTOR3(-0.5f,0.0f,0.0f), D3DCOLOR_ARGB(255,0,0,255)}, {p+D3DXVECTOR3(0.0f,-0.5f,0.0f), D3DCOLOR_ARGB(255,0,0,255)}, {p+D3DXVECTOR3(0.0f,0.0f,-0.5f), D3DCOLOR_ARGB(255,0,0,255)}, }; pGDevice->SetViewport(pGDevice->mCubeViewport); pDevice->SetVertexShader(NULL); pDevice->SetPixelShader(NULL); V(pDevice->SetTransform(D3DTS_WORLD, &matWorld)); V(pDevice->SetTransform(D3DTS_VIEW, &matView)); V(pDevice->SetTransform(D3DTS_PROJECTION, &matProj)); V(pDevice->SetRenderState(D3DRS_LIGHTING, FALSE)); V(pDevice->SetRenderState(D3DRS_ZENABLE, FALSE)); V(pDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE)); V(pDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, rayLine, sizeof(PCVertex))); V(pDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 7, intersectPoint, sizeof(PCVertex))); V(pDevice->SetFVF(NULL)); V(pDevice->SetRenderState(D3DRS_ZENABLE, TRUE)); V(pDevice->SetRenderState(D3DRS_LIGHTING, TRUE)); pGDevice->ResetViewport(); }
std::unique_ptr<Shader> HLSLCompiler::CreateShaderFromBinary( GraphicsDevice & graphicsDevice, const void* shaderSource, std::size_t byteLength, ShaderPipelineStage pipelineStage) { POMDOG_ASSERT(shaderSource != nullptr); POMDOG_ASSERT(byteLength > 0); POMDOG_ASSERT(graphicsDevice.GetSupportedLanguage() == ShaderLanguage::HLSL); auto nativeGraphicsDevice = graphicsDevice.GetNativeGraphicsDevice(); ShaderBytecode shaderBytecode; shaderBytecode.Code = shaderSource; shaderBytecode.ByteLength = byteLength; ShaderCompileOptions compileOptions; compileOptions.Profile.PipelineStage = pipelineStage; compileOptions.Precompiled = true; return nativeGraphicsDevice->CreateShader(shaderBytecode, compileOptions); }
void AssetRenderer::init(GraphicsDevice &g) { m_graphics = &g.castD3D11(); m_shaders.init(g); m_shaders.registerShader("../../shaders/modelRendererColor.shader", "basicColor"); m_shaders.registerShader("../../shaders/modelRendererTexture.shader", "basicTexture"); m_constants.init(g); m_sphere.load(g, ml::shapes::sphere(1.0f, vec3f::origin)); m_cylinder.load(g, ml::shapes::cylinder(0.01f, 1.0f, 2, 15, ml::vec4f(1.0f, 1.0f, 1.0f, 1.0f))); m_box.load(g, ml::shapes::box(1.0f)); }
bool IndexBuffer::initialize(GraphicsDevice& device, UsageType usage, void* initialData, unsigned int size) { assert(data.buffer == nullptr); assert(device.getDeviceData().d3dContext != nullptr); ID3D11Device* d3dDevice = device.getDeviceData().d3dDevice; D3D11_BUFFER_DESC bufferDesc; bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; bufferDesc.CPUAccessFlags = 0; bufferDesc.MiscFlags = 0; bufferDesc.ByteWidth = size; bufferDesc.StructureByteStride = 0; bufferDesc.Usage = static_cast<D3D11_USAGE>(usage); if(usage == UsageType::Dynamic) bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; D3D11_SUBRESOURCE_DATA bufferData; bufferData.pSysMem = initialData; bufferData.SysMemPitch = 0; bufferData.SysMemSlicePitch = 0; D3D11_SUBRESOURCE_DATA* bufferDataPtr = nullptr; if(initialData != nullptr) bufferDataPtr = &bufferData; if(FAILED(d3dDevice->CreateBuffer(&bufferDesc, bufferDataPtr, &data.buffer))) { release(); return false; } data.context = device.getDeviceData().d3dContext; return true; }
void TerrainTessellator::init(const GraphicsDevice& device, unsigned size, unsigned numPatches, unsigned stripeSize) { this->size = size; this->stripeSize = stripeSize; this->numPatches = numPatches; numVertices = (size + 3) * (size + 3); unsigned lod = (unsigned)MathHelper::log2(size) + 1; patchIndexBuffers = IndexBufferCollection(lod); skirtIndexBuffers = IndexBufferCollection(lod); for (unsigned i = 0; i < lod; ++i) { patchIndexBuffers[i] = createPatchIndexBuffer(device, i); skirtIndexBuffers[i] = createSkirtIndexBuffer(device, i); } VertexCollection vertices(numVertices); for (int row = -1; row <= (int)size + 1; ++row) for (int col = -1; col <= (int)size + 1; ++col) { int r = MathHelper::clamp(row, 0, (int)size); int c = MathHelper::clamp(col, 0, (int)size); float y = (r == row && c == col) ? 0.0f : -1.0f; vertices[getIndex(row, col)].position = Vector3((float)c, y, (float)r); } vertexBuffer = device.createVertexBuffer(sizeof(TerrainVertex) * numVertices, TerrainVertex::fvf, D3DUSAGE_WRITEONLY); vertexBuffer.setData(vertices); instanceVertexDeclaration = device.createVertexDeclaration(TerrainGeometry::vertexElements); }
void FBXModel::load(const GraphicsDevice& device, const std::string& filename, unsigned keyframes) { if (effect.resource == 0) effect = Effect::createFromFile<FBXEffect>(device, Config::getValue(ConfigKeys::fbxEffectPath)); defaultTexture = Texture::createFromFile(device, defaultTexturePath); vertexDeclaration = device.createVertexDeclaration(FBXInstance::vertexElements); KFbxSdkManager* sdkManager = KFbxSdkManager::Create(); KFbxIOSettings* ios = KFbxIOSettings::Create(sdkManager, IOSROOT); sdkManager->SetIOSettings(ios); // Create an importer using our sdk manager. KFbxImporter* importer = KFbxImporter::Create(sdkManager, ""); importer->Initialize(filename.c_str(), -1, sdkManager->GetIOSettings()); // Create a new scene so it can be populated by the imported file. KFbxScene* scene = KFbxScene::Create(sdkManager, ""); // Import the contents of the file into the scene. importer->Import(scene); KFbxNode* rootBone = 0; KFbxNode* rootNode = scene->GetRootNode(); KFbxAnimStack* animStack = KFbxCast<KFbxAnimStack>(scene->GetSrcObject(FBX_TYPE(KFbxAnimStack), 0)); KFbxAnimLayer* animLayer = 0; if (animStack) { animLayer = animStack->GetMember(FBX_TYPE(KFbxAnimLayer), 0); scene->GetEvaluator()->SetContext(animStack); } loadBones(rootNode, &rootBone, animLayer); loadMeshes(rootNode, device, KFbxGeometryConverter(sdkManager)); if (animLayer) { for (unsigned i = 0; i <= keyframes; ++i) boneMatricesMap[i] = traverseBones(i, rootBone, Matrix::identity, MatrixCollection(bones.size())); } sdkManager->Destroy(); loaded = true; }
void WaterView::draw(const GameTime& gameTime) { GraphicsManager& manager = getManager(); GraphicsDevice device = manager.getDevice(); Surface renderTarget = device.getRenderTarget(); if (renderTarget == reflectionSurface || renderTarget == refractionSurface || manager.isRenderShadowMap()) return; effect.setWorldViewProjection(manager.getWorldViewProjection()); effect.setReflectionmap(reflectionmap); effect.setRefractionmap(refractionmap); effect.setTime(gameTime.total); effect.setCameraPosition(manager.getCamera().getPosition()); effect.beginSinglePass(); terrain->getTessellator().drawPatch(device); effect.endSinglePass(); }
void TerrainTessellator::draw(const GraphicsDevice& device, unsigned levelOfDetail, unsigned primitiveCount, const IndexBufferCollection& indexBuffers, const std::vector<TerrainInstance>& instances, unsigned numInstances) const { instanceVertexBuffer.setData(instances, D3DLOCK_DISCARD); device.setStreamSource(vertexBuffer, sizeof(TerrainVertex)); device.setStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | numInstances); device.setStreamSource(instanceVertexBuffer, sizeof(TerrainInstance), 1); device.setStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1); device.setVertexDeclaration(instanceVertexDeclaration); device.setIndices(indexBuffers[levelOfDetail]); device.drawIndexedPrimitive(D3DPT_TRIANGLELIST, primitiveCount, numVertices); }
void ml::D3D11TriMesh::initVB(GraphicsDevice &g) { if (m_triMesh.getVertices().size() == 0) return; auto &device = g.castD3D11().getDevice(); D3D11_BUFFER_DESC bufferDesc; ZeroMemory( &bufferDesc, sizeof(bufferDesc) ); bufferDesc.Usage = D3D11_USAGE_DEFAULT; bufferDesc.ByteWidth = sizeof(TriMeshf::Vertex<float>) * (UINT)m_triMesh.getVertices().size(); bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bufferDesc.CPUAccessFlags = 0; D3D11_SUBRESOURCE_DATA data; ZeroMemory( &data, sizeof(data) ); data.pSysMem = &m_triMesh.getVertices()[0]; D3D_VALIDATE(device.CreateBuffer( &bufferDesc, &data, &m_vertexBuffer )); }
void GUIButton::Render(GraphicsDevice &GD, WindowManager &WM) { if(_ButtonMesh.VertexCount() == 0) { _ButtonMesh.SetGD(GD); _ButtonMesh.CreatePlane(1.0f, 2, 2); _ButtonMesh.Vertices()[0].Pos = Vec3f(_Dimensions.Min.x, _Dimensions.Min.y, 0.01f); _ButtonMesh.Vertices()[1].Pos = Vec3f(_Dimensions.Max.x, _Dimensions.Min.y, 0.01f); _ButtonMesh.Vertices()[2].Pos = Vec3f(_Dimensions.Min.x, _Dimensions.Max.y, 0.01f); _ButtonMesh.Vertices()[3].Pos = Vec3f(_Dimensions.Max.x, _Dimensions.Max.y, 0.01f); _ButtonMesh.SetColor(RGBColor::White); } _ButtonMesh.Render(); Vec2f TopLeft = WM.MapRelativeWindowCoordToAbsolute(_Dimensions.Min); GD.DrawStringFloat(_Name, float(TopLeft.x), float(TopLeft.y), RGBColor::Blue); }
void ml::D3D11TriMesh::initIB(GraphicsDevice &g) { auto &indices = m_triMesh.getIndices(); if (indices.size() == 0) return; auto &device = g.castD3D11().getDevice(); D3D11_BUFFER_DESC bufferDesc; ZeroMemory( &bufferDesc, sizeof(bufferDesc) ); bufferDesc.Usage = D3D11_USAGE_DEFAULT; bufferDesc.ByteWidth = sizeof( vec3ui ) * (UINT)indices.size(); bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; bufferDesc.CPUAccessFlags = 0; D3D11_SUBRESOURCE_DATA data; ZeroMemory( &data, sizeof(data) ); data.pSysMem = &indices[0]; D3D_VALIDATE(device.CreateBuffer( &bufferDesc, &data, &m_indexBuffer )); }
void ml::D3D11GeometryShader::init( GraphicsDevice& g, const std::string& filename, const std::string& entryPoint, const std::string& shaderModel, const std::vector<std::pair<std::string, std::string>>& shaderMacros) { m_graphics = &g.castD3D11(); releaseGPU(); SAFE_RELEASE(m_blob); m_filename = filename; //g.castD3D11().registerAsset(this); m_blob = D3D11Utility::CompileShader(m_filename, entryPoint, shaderModel, shaderMacros); MLIB_ASSERT_STR(m_blob != nullptr, "CompileShader failed"); createGPU(); }