Add GEVulkanCameraSceneNode
This commit is contained in:
parent
4b17d2133a
commit
b8cb96b81f
@ -27,6 +27,7 @@ set(GE_SOURCES
|
||||
src/ge_texture.cpp
|
||||
src/ge_dx9_texture.cpp
|
||||
src/ge_vulkan_2d_renderer.cpp
|
||||
src/ge_vulkan_camera_scene_node.cpp
|
||||
src/ge_vulkan_command_loader.cpp
|
||||
src/ge_vulkan_driver.cpp
|
||||
src/ge_vulkan_dynamic_buffer.cpp
|
||||
|
@ -18,6 +18,11 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
~GEVulkanSceneManager();
|
||||
// ------------------------------------------------------------------------
|
||||
virtual irr::scene::ICameraSceneNode* addCameraSceneNode(
|
||||
irr::scene::ISceneNode* parent = 0,
|
||||
const irr::core::vector3df& position = irr::core::vector3df(0, 0, 0),
|
||||
const irr::core::vector3df& lookat = irr::core::vector3df(0, 0, 100),
|
||||
irr::s32 id = -1, bool make_active = true);
|
||||
}; // GEVulkanSceneManager
|
||||
|
||||
}
|
||||
|
48
lib/graphics_engine/src/ge_vulkan_camera_scene_node.cpp
Normal file
48
lib/graphics_engine/src/ge_vulkan_camera_scene_node.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "ge_vulkan_camera_scene_node.hpp"
|
||||
|
||||
#include "ge_vulkan_dynamic_buffer.hpp"
|
||||
|
||||
namespace GE
|
||||
{
|
||||
// ----------------------------------------------------------------------------
|
||||
GEVulkanCameraSceneNode::GEVulkanCameraSceneNode(irr::scene::ISceneNode* parent,
|
||||
irr::scene::ISceneManager* mgr,
|
||||
irr::s32 id,
|
||||
const irr::core::vector3df& position,
|
||||
const irr::core::vector3df& lookat)
|
||||
: CCameraSceneNode(parent, mgr, id, position, lookat)
|
||||
{
|
||||
m_buffer = new GEVulkanDynamicBuffer(GVDBT_GPU_RAM,
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, sizeof(GEVulkanCameraUBO));
|
||||
} // GEVulkanCameraSceneNode
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GEVulkanCameraSceneNode::~GEVulkanCameraSceneNode()
|
||||
{
|
||||
delete m_buffer;
|
||||
} // ~GEVulkanCameraSceneNode
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GEVulkanCameraSceneNode::render()
|
||||
{
|
||||
irr::scene::CCameraSceneNode::render();
|
||||
memcpy(m_ubo_data.m_view_matrix.data(),
|
||||
ViewArea.getTransform(irr::video::ETS_VIEW).pointer(),
|
||||
16 * sizeof(float));
|
||||
memcpy(m_ubo_data.m_projection_matrix.data(),
|
||||
ViewArea.getTransform(irr::video::ETS_PROJECTION).pointer(),
|
||||
16 * sizeof(float));
|
||||
irr::core::matrix4 mat;
|
||||
ViewArea.getTransform(irr::video::ETS_VIEW).getInverse(mat);
|
||||
memcpy(m_ubo_data.m_inverse_view_matrix.data(), mat.pointer(),
|
||||
16 * sizeof(float));
|
||||
ViewArea.getTransform(irr::video::ETS_PROJECTION).getInverse(mat);
|
||||
memcpy(m_ubo_data.m_inverse_projection_matrix.data(), mat.pointer(),
|
||||
16 * sizeof(float));
|
||||
mat = ViewArea.getTransform(irr::video::ETS_PROJECTION) *
|
||||
ViewArea.getTransform(irr::video::ETS_VIEW);
|
||||
memcpy(m_ubo_data.m_projection_view_matrix.data(), mat.pointer(),
|
||||
16 * sizeof(float));
|
||||
} // render
|
||||
|
||||
}
|
43
lib/graphics_engine/src/ge_vulkan_camera_scene_node.hpp
Normal file
43
lib/graphics_engine/src/ge_vulkan_camera_scene_node.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef HEADER_GE_VULKAN_CAMERA_SCENE_NODE_HPP
|
||||
#define HEADER_GE_VULKAN_CAMERA_SCENE_NODE_HPP
|
||||
|
||||
#include "../source/Irrlicht/CCameraSceneNode.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace GE
|
||||
{
|
||||
struct GEVulkanCameraUBO
|
||||
{
|
||||
std::array<float, 16> m_view_matrix;
|
||||
std::array<float, 16> m_projection_matrix;
|
||||
std::array<float, 16> m_inverse_view_matrix;
|
||||
std::array<float, 16> m_inverse_projection_matrix;
|
||||
std::array<float, 16> m_projection_view_matrix;
|
||||
};
|
||||
|
||||
class GEVulkanDynamicBuffer;
|
||||
|
||||
class GEVulkanCameraSceneNode : public irr::scene::CCameraSceneNode
|
||||
{
|
||||
private:
|
||||
GEVulkanDynamicBuffer* m_buffer;
|
||||
|
||||
GEVulkanCameraUBO m_ubo_data;
|
||||
public:
|
||||
// ------------------------------------------------------------------------
|
||||
GEVulkanCameraSceneNode(irr::scene::ISceneNode* parent,
|
||||
irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||
const irr::core::vector3df& position = irr::core::vector3df(0, 0, 0),
|
||||
const irr::core::vector3df& lookat = irr::core::vector3df(0, 0, 100));
|
||||
// ------------------------------------------------------------------------
|
||||
~GEVulkanCameraSceneNode();
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void render();
|
||||
// ------------------------------------------------------------------------
|
||||
GEVulkanDynamicBuffer* getBuffer() const { return m_buffer; }
|
||||
}; // GEVulkanCameraSceneNode
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,5 +1,6 @@
|
||||
#include "ge_vulkan_scene_manager.hpp"
|
||||
|
||||
#include "ge_vulkan_camera_scene_node.hpp"
|
||||
#include "ge_vulkan_mesh_cache.hpp"
|
||||
|
||||
namespace GE
|
||||
@ -21,4 +22,24 @@ GEVulkanSceneManager::~GEVulkanSceneManager()
|
||||
{
|
||||
} // ~GEVulkanSceneManager
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
irr::scene::ICameraSceneNode* GEVulkanSceneManager::addCameraSceneNode(
|
||||
irr::scene::ISceneNode* parent,
|
||||
const irr::core::vector3df& position,
|
||||
const irr::core::vector3df& lookat,
|
||||
irr::s32 id, bool make_active)
|
||||
{
|
||||
if (!parent)
|
||||
parent = this;
|
||||
|
||||
irr::scene::ICameraSceneNode* node = new GEVulkanCameraSceneNode(parent,
|
||||
this, id, position, lookat);
|
||||
|
||||
if (make_active)
|
||||
setActiveCamera(node);
|
||||
node->drop();
|
||||
|
||||
return node;
|
||||
} // addCameraSceneNode
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user