mirror of
https://github.com/redstrate/Novus.git
synced 2025-05-14 20:47:46 +00:00
Draw spheres at every instance object location
Now we can see where each object is (there's no way to tell them apart yet.) The rendering is also extremely inefficient, so don't be surprised if it slows down on your computer.
This commit is contained in:
parent
fc327ba8b5
commit
dfef9fdccf
7 changed files with 46 additions and 65 deletions
|
@ -10,13 +10,14 @@
|
|||
#include <physis.hpp>
|
||||
|
||||
struct GameData;
|
||||
class AppState;
|
||||
|
||||
class MapView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MapView(GameData *data, FileCache &cache, QWidget *parent = nullptr);
|
||||
explicit MapView(GameData *data, FileCache &cache, AppState *appState, QWidget *parent = nullptr);
|
||||
|
||||
MDLPart &part() const;
|
||||
|
||||
|
@ -28,4 +29,4 @@ private:
|
|||
|
||||
GameData *data;
|
||||
FileCache &cache;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -7,20 +7,22 @@
|
|||
|
||||
class RenderManager;
|
||||
class Device;
|
||||
class AppState;
|
||||
|
||||
class ObjectPass : public RendererPass
|
||||
{
|
||||
public:
|
||||
ObjectPass(RenderManager *renderer);
|
||||
ObjectPass(RenderManager *renderer, AppState *appState);
|
||||
|
||||
void render(VkCommandBuffer commandBuffer, Camera &camera) override;
|
||||
|
||||
private:
|
||||
void createPipeline();
|
||||
|
||||
VkPipeline pipeline_ = nullptr;
|
||||
VkPipelineLayout pipelineLayout_ = nullptr;
|
||||
VkPipeline m_pipeline = nullptr;
|
||||
VkPipelineLayout m_pipelineLayout = nullptr;
|
||||
|
||||
RenderManager *m_renderer;
|
||||
Device &m_device;
|
||||
AppState *m_appState;
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ MainWindow::MainWindow(GameData *data)
|
|||
objectListWidget->setMaximumWidth(400);
|
||||
dummyWidget->addWidget(objectListWidget);
|
||||
|
||||
mapView = new MapView(data, cache);
|
||||
mapView = new MapView(data, cache, m_appState);
|
||||
dummyWidget->addWidget(mapView);
|
||||
|
||||
setupActions();
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
#include "filecache.h"
|
||||
#include "objectpass.h"
|
||||
|
||||
MapView::MapView(GameData *data, FileCache &cache, QWidget *parent)
|
||||
MapView::MapView(GameData *data, FileCache &cache, AppState *appState, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, data(data)
|
||||
, cache(cache)
|
||||
{
|
||||
mdlPart = new MDLPart(data, cache);
|
||||
mdlPart->enableFreemode();
|
||||
connect(mdlPart, &MDLPart::initializeRender, this, [this] {
|
||||
mdlPart->manager()->addPass(new ObjectPass(mdlPart->manager()));
|
||||
connect(mdlPart, &MDLPart::initializeRender, this, [this, appState] {
|
||||
mdlPart->manager()->addPass(new ObjectPass(mdlPart->manager(), appState));
|
||||
});
|
||||
|
||||
auto layout = new QVBoxLayout();
|
||||
|
|
|
@ -10,9 +10,12 @@
|
|||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
ObjectPass::ObjectPass(RenderManager *renderer)
|
||||
#include "appstate.h"
|
||||
|
||||
ObjectPass::ObjectPass(RenderManager *renderer, AppState *appState)
|
||||
: m_renderer(renderer)
|
||||
, m_device(m_renderer->device())
|
||||
, m_appState(appState)
|
||||
{
|
||||
createPipeline();
|
||||
|
||||
|
@ -27,60 +30,35 @@ void ObjectPass::render(VkCommandBuffer commandBuffer, Camera &camera)
|
|||
labelExt.pLabelName = "Object Pass";
|
||||
m_renderer->device().beginDebugMarker(commandBuffer, labelExt);
|
||||
|
||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline);
|
||||
|
||||
Primitives::DrawSphere(commandBuffer);
|
||||
for (const auto &[_, lgb] : m_appState->lgbFiles) {
|
||||
for (int i = 0; i < lgb.num_chunks; i++) {
|
||||
const auto chunk = lgb.chunks[i];
|
||||
for (int j = 0; j < chunk.num_layers; j++) {
|
||||
const auto layer = chunk.layers[j];
|
||||
for (int z = 0; z < layer.num_objects; z++) {
|
||||
const auto object = layer.objects[z];
|
||||
|
||||
glm::mat4 vp = camera.perspective * camera.view;
|
||||
|
||||
vkCmdPushConstants(commandBuffer, m_pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), &vp);
|
||||
|
||||
auto m = glm::mat4(1.0f);
|
||||
m = glm::translate(m, {object.transform.translation[0], object.transform.translation[1], object.transform.translation[2]});
|
||||
|
||||
vkCmdPushConstants(commandBuffer, m_pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(glm::mat4), sizeof(glm::mat4), &m);
|
||||
|
||||
Primitives::DrawSphere(commandBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_renderer->device().endDebugMarker(commandBuffer);
|
||||
} else {
|
||||
qWarning() << "Can't render object pass in non-simple renderer for now!!";
|
||||
}
|
||||
|
||||
/*VkClearValue clearValue = {};
|
||||
clearValue.color = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
|
||||
VkRenderPassBeginInfo renderPassInfo = {};
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
renderPassInfo.renderPass = m_renderPass;
|
||||
renderPassInfo.framebuffer = target->sobelFramebuffers[target->currentResource];
|
||||
renderPassInfo.renderArea.extent = target->extent;
|
||||
renderPassInfo.clearValueCount = 1;
|
||||
renderPassInfo.pClearValues = &clearValue;
|
||||
|
||||
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
||||
|
||||
if(extraInfo != nullptr) {
|
||||
for (auto mesh: collection.meshes) {
|
||||
bool shouldRender = false;
|
||||
for (int i = 0; i < extraInfo->numSelectedEntities; i++) {
|
||||
if (extraInfo->selectedEntities[i] == mesh.entity)
|
||||
shouldRender = true;
|
||||
}
|
||||
|
||||
if (shouldRender) {
|
||||
glm::mat4 mvp;
|
||||
mvp = glm::perspective(glm::radians(collection.camera.camera->fov),
|
||||
(float) target->extent.width / target->extent.height,
|
||||
collection.camera.camera->near, collection.camera.camera->far);
|
||||
mvp *= glm::lookAt(collection.camera.transform->position, collection.camera.camera->target,
|
||||
glm::vec3(0, -1, 0));
|
||||
mvp = glm::translate(mvp, mesh.transform->position);
|
||||
|
||||
vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4),
|
||||
&mvp);
|
||||
|
||||
const VkDeviceSize offsets[] = {0};
|
||||
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &mesh.mesh->mesh->vertexBuffer, offsets);
|
||||
vkCmdBindIndexBuffer(commandBuffer, mesh.mesh->mesh->indexBuffer, 0, VK_INDEX_TYPE_UINT32);
|
||||
|
||||
vkCmdDrawIndexed(commandBuffer, mesh.mesh->mesh->indices.size(), 1, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vkCmdEndRenderPass(commandBuffer);*/
|
||||
}
|
||||
|
||||
void ObjectPass::createPipeline()
|
||||
|
@ -100,7 +78,7 @@ void ObjectPass::createPipeline()
|
|||
const std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages = {vertexShaderStageInfo, fragmentShaderStageInfo};
|
||||
|
||||
VkVertexInputBindingDescription vertexBindingDescription = {};
|
||||
vertexBindingDescription.stride = sizeof(Vertex);
|
||||
vertexBindingDescription.stride = sizeof(glm::vec3);
|
||||
|
||||
VkVertexInputAttributeDescription positionAttributeDescription = {};
|
||||
positionAttributeDescription.format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
|
@ -156,7 +134,7 @@ void ObjectPass::createPipeline()
|
|||
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
||||
pipelineLayoutInfo.pPushConstantRanges = &pushConstant;
|
||||
|
||||
vkCreatePipelineLayout(m_device.device, &pipelineLayoutInfo, nullptr, &pipelineLayout_);
|
||||
vkCreatePipelineLayout(m_device.device, &pipelineLayoutInfo, nullptr, &m_pipelineLayout);
|
||||
|
||||
VkPipelineDepthStencilStateCreateInfo depthStencil = {};
|
||||
depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
||||
|
@ -179,8 +157,8 @@ void ObjectPass::createPipeline()
|
|||
pipelineInfo.pColorBlendState = &colorBlending;
|
||||
pipelineInfo.pDynamicState = &dynamicState;
|
||||
pipelineInfo.pDepthStencilState = &depthStencil;
|
||||
pipelineInfo.layout = pipelineLayout_;
|
||||
pipelineInfo.layout = m_pipelineLayout;
|
||||
pipelineInfo.renderPass = renderer->renderPass();
|
||||
|
||||
vkCreateGraphicsPipelines(m_device.device, nullptr, 1, &pipelineInfo, nullptr, &pipeline_);
|
||||
vkCreateGraphicsPipelines(m_device.device, nullptr, 1, &pipelineInfo, nullptr, &m_pipeline);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ void Primitives::Initialize(RenderManager *renderer)
|
|||
std::vector<glm::vec3> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
unsigned int xResolution = 64;
|
||||
unsigned int yResolution = 64;
|
||||
unsigned int xResolution = 2;
|
||||
unsigned int yResolution = 2;
|
||||
float PI = 3.14159265359f;
|
||||
|
||||
for (unsigned int y = 0; y <= yResolution; ++y) {
|
||||
|
|
2
extern/libphysis
vendored
2
extern/libphysis
vendored
|
@ -1 +1 @@
|
|||
Subproject commit bf8aa831d0c57e40d724602bfd5c311cf1422390
|
||||
Subproject commit f0b53912ef8ef9361aaede623ae0a38d1bd833bb
|
Loading…
Add table
Reference in a new issue