RenderViewer::RenderViewer() { mLayout = new MGUI::Layout(NULL, NULL); mTextBox = new MGUI::TextBox(NULL, mLayout); mTextBox->SetAlign(MGUI::eAlign::LEFT | MGUI::eAlign::BOTTOM); // create grid mesh mGridMesh = new Mesh(); SubMesh * pMeshBuffer = mGridMesh->NewSubMesh(); pMeshBuffer->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::POSITION, eVertexType::FLOAT2); pMeshBuffer->GetRenderOp()->vertexBuffers[0] = HWBufferManager::Instance()->NewVertexBuffer(2 * sizeof(float), (GRID_SIZE + 1) * 2 * 2); int index = 0; float * data = (float *)pMeshBuffer->GetRenderOp()->vertexBuffers[0]->Lock(eLockFlag::WRITE); { float _s = -GRID_SIZE / 2 * METER_LEN; float _e = GRID_SIZE / 2 * METER_LEN; float y = _s; float dy = METER_LEN; for (int i = 0; i < GRID_SIZE + 1; ++i) { data[index++] = _s; data[index++] = y; data[index++] = _e; data[index++] = y; y += dy; } float x = _s; float dx = METER_LEN; for (int i = 0; i < GRID_SIZE + 1; ++i) { data[index++] = x; data[index++] = _s; data[index++] = x; data[index++] = _e; x += dx; } } pMeshBuffer->GetRenderOp()->vertexBuffers[0]->Unlock(); pMeshBuffer->GetRenderOp()->primCount = (GRID_SIZE + 1) * 2; pMeshBuffer->GetRenderOp()->primType = ePrimType::LINE_LIST; ShaderFX * pShaderFX = ShaderFXManager::Instance()->Load("Grid", "Grid.mfx"); d_assert(pShaderFX != NULL); pMeshBuffer->SetShaderFX(pShaderFX); mGridMesh->SetLocalAabb(Aabb::Infinite); Layout(); World::Instance()->E_RenderEnd += new cListener0<RenderViewer>(this, &RenderViewer::OnUpdate); }
void PS_Mesh::_update(Particle * p) { Float3 Position = p->Position; if (mParent->IsLocalSpace()) Position.TransformA(mParent->GetParent()->GetWorldTM()); mMesh->SetPosition(Position); mMesh->SetOpacity(p->Color.a); mMesh->SetRotationEx(p->Rotation); mMesh->SetScale(p->Size); mMesh->_updateTM(); int blendMode = mParent->GetBlendMode(); for (int i = 0; i < mMesh->GetSubMeshCount(); ++i) { SubMesh * submesh = mMesh->GetSubMesh(i); Material * mtl = submesh->GetMaterial(); mtl->diffuse = Float3(p->Color.r, p->Color.g, p->Color.b); if (mParent->_getTexture() != NULL) { mtl->maps[eMapType::DIFFUSE] = mParent->_getTexture(); } if (mParent->GetShaderEnable()) { mtl->depthMode = eDepthMode::N_LESS_EQUAL; if (blendMode == PS_BlendMode::ADD) { mtl->blendMode = eBlendMode::ADD; } else if (blendMode == PS_BlendMode::ALPHA_BLEND) { mtl->blendMode = eBlendMode::ALPHA_BLEND; } else if (blendMode == PS_BlendMode::COLOR_BLEND) { mtl->blendMode = eBlendMode::COLOR_BLEND; } else { mtl->blendMode = eBlendMode::OPACITY; mtl->depthMode = eDepthMode::LESS_EQUAL; } submesh->SetShaderFX(mParent->_getShaderFX()); submesh->SetRenderCallBack(eRenderCallBack::SHADER, mParent->GetShader().c_ptr()); } } }