Skip to content
Permalink
Browse files

Merge pull request #454 from invor/Compositing

Updates to mesh loading and handling
  • Loading branch information...
tobiasrau committed Sep 17, 2019
2 parents d3a56d0 + 8feb813 commit 858bc042e1c54af29b2f4defd2b89d65e5c72dfd
@@ -1,5 +1,5 @@
#
# MegaMol™ compositing Plugin
# MegaMol™ compositing_gl Plugin
# Copyright 2017, by MegaMol Team
# Alle Rechte vorbehalten. All rights reserved.
#
@@ -17,7 +17,7 @@
// that uses this DLL. This way any other project whose source files include this file see
// TRISOUPPLUGIN_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef compositing_gl_EXPORTS
#ifdef COMPOSITING_GL_EXPORTS
#define COMPOSITING_GL_API __declspec(dllexport)
#else
#define COMPOSITING_GL_API __declspec(dllimport)
@@ -28,7 +28,7 @@

#include "mmcore/utility/plugins/Plugin200Instance.h"

#ifdef compositing_EXPORTS
#ifdef COMPOSITING_GL_EXPORTS
#ifdef __cplusplus
extern "C" {
#endif
@@ -29,7 +29,7 @@ namespace {
: ::megamol::core::utility::plugins::Plugin200Instance(

/* machine-readable plugin assembly name */
"compositing", // TODO: Change this!
"compositing_gl", // TODO: Change this!

/* human-readable plugin description */
"Describing compositing (TODO: Change this!)") {
@@ -0,0 +1,5 @@
out layout(location = 0) vec4 frag_colour;

void main(void) {
frag_colour = vec4(1.0);
}
@@ -0,0 +1,21 @@
#extension GL_ARB_shader_draw_parameters : require

struct MeshShaderParams
{
mat4 transform;
};

layout(std430, binding = 0) readonly buffer MeshShaderParamsBuffer { MeshShaderParams[] mesh_shader_params; };

uniform mat4 view_mx;
uniform mat4 proj_mx;

layout(location = 0) in vec3 v_position;
layout(location = 1) in vec3 v_normal;
layout(location = 2) in vec2 v_uv;

void main()
{
mat4 object_transform = mesh_shader_params[gl_DrawIDARB].transform;
gl_Position = proj_mx * view_mx * object_transform * vec4(v_position,1.0);
}
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<btf type="MegaMolGLSLShader" version="1.0" namespace="wavefrontObjExample">
<include file="common"/>

<shader name="vertex">
<snippet type="version">430</snippet>
<snippet name="CommonDefines" type="file">commondefines.glsl</snippet>
<snippet name="Main" type="file">mesh/wavefrontObj_example_v.glsl</snippet>
</shader>

<shader name="fragment">
<snippet type="version">430</snippet>
<snippet name="CommonDefines" type="file">commondefines.glsl</snippet>
<snippet name="Main" type="file">mesh/wavefrontObj_example_f.glsl</snippet>
</shader>

</btf>
@@ -10,16 +10,54 @@
#include "mesh.h"

#ifndef MESH_DATA_ACCESS_COLLECTION_H_INCLUDED
#define MESH_DATA_ACCESS_COLLECTION_H_INCLUDED
# define MESH_DATA_ACCESS_COLLECTION_H_INCLUDED

namespace megamol {
namespace mesh {

class MESH_API MeshDataAccessCollection {
public:

enum ValueType { BYTE, UNSIGNED_BYTE, SHORT, UNSIGNED_SHORT, INT, UNSIGNED_INT, HALF_FLOAT, FLOAT, DOUBLE };

static constexpr unsigned int convertToGLType(ValueType value_type) {
unsigned int retval = 0;

switch (value_type) {

case BYTE:
retval = 0x1400;
break;
case UNSIGNED_BYTE:
retval = 0x1401;
break;
case SHORT:
retval = 0x1402;
break;
case UNSIGNED_SHORT:
retval = 0x1403;
break;
case INT:
retval = 0x1404;
break;
case UNSIGNED_INT:
retval = 0x1405;
break;
case HALF_FLOAT:
retval = 0x140B;
break;
case FLOAT:
retval = 0x1406;
break;
case DOUBLE:
retval = 0x140A;
break;
default:
break;
}

return retval;
}

static constexpr size_t getByteSize(ValueType value_type) {
size_t retval = 0;

@@ -59,23 +97,27 @@ class MESH_API MeshDataAccessCollection {
}

struct VertexAttribute {
uint8_t* data;
size_t byte_size;
uint8_t* data;
size_t byte_size;
unsigned int component_cnt;
ValueType component_type;
size_t stride;
size_t offset;
ValueType component_type;
size_t stride;
size_t offset;
};

struct IndexData {
uint8_t* data;
size_t byte_size;
uint8_t* data;
size_t byte_size;
ValueType type;
};

struct Mesh {

Mesh(std::vector<VertexAttribute> const& attribs, IndexData indices)
: attributes(attribs), indices(indices) {}

std::vector<VertexAttribute> attributes;
IndexData indices;
IndexData indices;

// TODO interleaved flag?
};
@@ -84,30 +126,27 @@ class MESH_API MeshDataAccessCollection {
~MeshDataAccessCollection() = default;

void addMesh(std::vector<VertexAttribute> const& attribs, IndexData const& indices);
void addMesh(std::vector<VertexAttribute> && attribs, IndexData const& indices);
void addMesh(std::vector<VertexAttribute>&& attribs, IndexData const& indices);

// TODO delete functionality

std::vector<Mesh>& accessMesh(size_t mesh_idx);
std::vector<Mesh> const& accessMesh();

private:

std::vector<Mesh> meshes;
};

inline void MeshDataAccessCollection::addMesh(std::vector<VertexAttribute> const& attribs, IndexData const& indices) {
meshes.push_back({attribs, indices});
meshes.emplace_back(Mesh(attribs, indices));
}

inline void MeshDataAccessCollection::addMesh(std::vector<VertexAttribute>&& attribs, IndexData const& indices) {
meshes.push_back({attribs, indices});
meshes.emplace_back(Mesh(attribs, indices));
}

inline std::vector<MeshDataAccessCollection::Mesh>& MeshDataAccessCollection::accessMesh(size_t mesh_idx) {
return meshes;
}
inline std::vector<MeshDataAccessCollection::Mesh> const& MeshDataAccessCollection::accessMesh() { return meshes; }

}
}
} // namespace mesh
} // namespace megamol

#endif // !MESH_DATA_ACCESS_COLLECTION_H_INCLUDED
@@ -57,12 +57,12 @@ bool megamol::mesh::DebugGPURenderTaskDataSource::getDataCallback(core::Call & c
auto const& gpu_batch_mesh = gpu_mesh_storage->getMeshes()[sub_mesh.batch_index].mesh;
auto const& shader = gpu_mtl_storage->getMaterials().front().shader_program;

std::vector<glowl::DrawElementsCommand> draw_commands(1000, sub_mesh.sub_mesh_draw_command);
std::vector<glowl::DrawElementsCommand> draw_commands(1, sub_mesh.sub_mesh_draw_command);

std::vector<vislib::math::Matrix<GLfloat, 4, vislib::math::COLUMN_MAJOR >> object_transform(1000);
std::vector<vislib::math::Matrix<GLfloat, 4, vislib::math::COLUMN_MAJOR >> object_transform(1);
typedef std::vector<vislib::math::Matrix<GLfloat, 4, vislib::math::COLUMN_MAJOR >> PerTaskData;

for (int i = 0; i < 1000; ++i)
for (int i = 0; i < 1; ++i)
{
GLfloat scale = distr(generator);
scale = 0.1f;
@@ -11,7 +11,7 @@ megamol::mesh::GPUMeshes::GPUMeshes()
this->MakeSlotAvailable(&this->m_mesh_slot);
}

megamol::mesh::GPUMeshes::~GPUMeshes() {}
megamol::mesh::GPUMeshes::~GPUMeshes() { this->Release(); }

bool megamol::mesh::GPUMeshes::create() {
m_gpu_meshes = std::make_shared<GPUMeshCollection>();
@@ -29,11 +29,11 @@ bool megamol::mesh::GPUMeshes::getDataCallback(core::Call& caller) {
std::shared_ptr<GPUMeshCollection> mesh_collection(nullptr);

if (lhs_mesh_call->getData() == nullptr) {
// no incoming material -> use your own material storage
// no incoming mesh -> use your own mesh storage
mesh_collection = this->m_gpu_meshes;
lhs_mesh_call->setData(mesh_collection);
} else {
// incoming material -> use it (delete local?)
// incoming mesh -> use it (delete local?)
mesh_collection = lhs_mesh_call->getData();
}

@@ -44,9 +44,63 @@ bool megamol::mesh::GPUMeshes::getDataCallback(core::Call& caller) {
if (mc->getMetaData().m_data_hash > m_mesh_cached_hash) {
m_mesh_cached_hash = mc->getMetaData().m_data_hash;

if (!m_mesh_collection_indices.empty()) {
// TODO delete all exisiting render task from this module
for (auto& submesh_idx : m_mesh_collection_indices) {
// mesh_collection->deleteSubMesh()
}

//TODO
m_mesh_collection_indices.clear();
}

auto& meta_data = mc->getMetaData();

m_bbox[0] = meta_data.m_bboxs.ObjectSpaceBBox().Left();
m_bbox[1] = meta_data.m_bboxs.ObjectSpaceBBox().Bottom();
m_bbox[2] = meta_data.m_bboxs.ObjectSpaceBBox().Back();
m_bbox[3] = meta_data.m_bboxs.ObjectSpaceBBox().Right();
m_bbox[4] = meta_data.m_bboxs.ObjectSpaceBBox().Top();
m_bbox[5] = meta_data.m_bboxs.ObjectSpaceBBox().Front();

auto meshes = mc->getData()->accessMesh();

for (auto& mesh : meshes)
{

std::vector<glowl::VertexLayout::Attribute> attribs;
std::vector < std::pair<uint8_t*, uint8_t* >> vb_iterators;
std::pair<uint8_t*, uint8_t*> ib_iterators;

ib_iterators = {mesh.indices.data, mesh.indices.data + mesh.indices.byte_size};

for (auto attrib : mesh.attributes) {

attribs.push_back(
glowl::VertexLayout::Attribute(attrib.component_cnt ,
MeshDataAccessCollection::convertToGLType(attrib.component_type),
GL_FALSE /*ToDO*/, attrib.offset));

// TODO vb_iterators
vb_iterators.push_back({attrib.data, attrib.data + attrib.byte_size});
}

glowl::VertexLayout vertex_descriptor(0,attribs);
mesh_collection->addMesh(
vertex_descriptor,
vb_iterators,
ib_iterators,
MeshDataAccessCollection::convertToGLType(mesh.indices.type),
GL_STATIC_DRAW,
GL_TRIANGLES);
}

}

// if there is a mesh connection to the right, pass on the mesh collection
CallGPUMeshData* rhs_mesh_call = this->m_mesh_callerSlot.CallAs<CallGPUMeshData>();
if (rhs_mesh_call != NULL) {
rhs_mesh_call->setData(mesh_collection);

if (!(*rhs_mesh_call)(0)) return false;
}
}

0 comments on commit 858bc04

Please sign in to comment.
You can’t perform that action at this time.