diff options
author | rtk0c <[email protected]> | 2022-04-25 20:22:07 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-04-25 20:22:07 -0700 |
commit | 855da86feae1a5cc14dc2d486ccf115f484dbc2e (patch) | |
tree | 8284c6a6bdfb1a919eb1a22f466f4180a329c7f3 /source/SceneThings.cpp | |
parent | d78a55de5003dbb040f1d1c369409e63a2c806d8 (diff) |
Changeset: 16 Initial work on rendering sprites to screen
Diffstat (limited to 'source/SceneThings.cpp')
-rw-r--r-- | source/SceneThings.cpp | 72 |
1 files changed, 62 insertions, 10 deletions
diff --git a/source/SceneThings.cpp b/source/SceneThings.cpp index 894ea58..2a25fb6 100644 --- a/source/SceneThings.cpp +++ b/source/SceneThings.cpp @@ -1,19 +1,71 @@ #include "SceneThings.hpp" -void BuildingObject::SetMeshMaterial(Material* material) { - mMaterial.Attach(material); - // TODO update render +#include "CommonVertexIndex.hpp" +#include "Rect.hpp" + +#include <utility> + +SimpleGeometryObject::SimpleGeometryObject(GameWorld* world) + : GameObject(KD_SimpleGeometry, world) + , mRenderObject() + , mSize{ 20.0f, 20.0f } + , mColor(60, 60, 60) { + mRenderObject.SetMaterial(gDefaultMaterial.Get()); + mRenderObject.SetFormat(gVformatStandardPacked.Get(), Tags::IT_16Bit); + mRenderObject.RebuildIfNecessary(); +} + +void SimpleGeometryObject::SetSize(glm::vec2 size) { + mSize = size; +} + +void SimpleGeometryObject::SetColor(RgbaColor color) { + mColor = color; +} + +std::span<const RenderObject> SimpleGeometryObject::GetRenderObjects() const { + return { &mRenderObject, 1 }; } -const Material* BuildingObject::GetMeshMaterial() const { - return mMaterial.Get(); +void SimpleGeometryObject::UpdateRenderObject() { + using namespace Tags; + + uint16_t indices[6]; + Index_U16::Assign(indices, 0); + mRenderObject.GetIndexBuffer()->Upload((const std::byte*)indices, IT_16Bit, std::size(indices)); + + Vertex_PTC vertices[4]; + Vertex_PTC::Assign(vertices, Rect<float>{ GetPos(), mSize }); + Vertex_PTC::Assign(vertices, 0.0f); + Vertex_PTC::Assign(vertices, mColor); + mRenderObject.GetVertexBufferBindings().bindings[0]->Upload((const std::byte*)vertices, sizeof(vertices)); } -void BuildingObject::SetMesh(GpuMesh* mesh) { - mMesh.Attach(mesh); - // TODO update render +BuildingObject::BuildingObject(GameWorld* world) + : GameObject(KD_Building, world) { + mRenderObject.SetMaterial(gDefaultMaterial.Get()); + mRenderObject.SetFormat(gVformatStandardPacked.Get(), Tags::IT_32Bit); + mRenderObject.RebuildIfNecessary(); } -const GpuMesh* BuildingObject::GetMesh() const { - return mMesh.Get(); +// void BuildingObject::SetMeshMaterial(Material* material) { +// mMaterial.Attach(material); +// // TODO update render +// } + +// const Material* BuildingObject::GetMeshMaterial() const { +// return mMaterial.Get(); +// } + +// void BuildingObject::SetMesh(GpuMesh* mesh) { +// mMesh.Attach(mesh); +// // TODO update render +// } + +// const GpuMesh* BuildingObject::GetMesh() const { +// return mMesh.Get(); +// } + +std::span<const RenderObject> BuildingObject::GetRenderObjects() const { + return { &mRenderObject, 1 }; } |