Skip to content
Permalink
Browse files

Merge pull request #465 from invor/Compositing

Updated GPUMaterialCollection to use glowl texture
  • Loading branch information...
tobiasrau committed Nov 5, 2019
2 parents 7db9e1f + c230e9d commit 8803d23dbf7702403bfbd8d78897768b578fce02
@@ -52,14 +52,16 @@ bool megamol::archvis::FEMMaterialDataSource::getDataCallback(core::Call& caller

m_gpu_materials->clearMaterials();

m_gpu_materials->addMaterial(this->instance(), filename, {tf_texture_name});
//m_gpu_materials->addMaterial(this->instance(), filename, {tf_texture_name});
//TODOD
}

if (tf_call->IsDirty()) {
if (!m_gpu_materials->getMaterials().empty()) {
tf_call->ResetDirty();

m_gpu_materials->updateMaterialTexture(0, 0, tf_texture_name);
//m_gpu_materials->updateMaterialTexture(0, 0, tf_texture_name);
//TODO
}
}

@@ -1,5 +1,7 @@
#include "FEMRenderTaskDataSource.h"

#include <variant>

#include "mesh/GPUMeshCollection.h"
#include "mesh/MeshCalls.h"

@@ -40,10 +42,11 @@ bool megamol::archvis::FEMRenderTaskDataSource::getDataCallback(core::Call& call

// TODO get transfer function texture and add as per frame data
std::vector<GLuint64> texture_handles;
auto textures = gpu_mtl_storage->getMaterials().front().textures_names;
auto textures = gpu_mtl_storage->getMaterials().front().textures;
for (auto texture : textures) {
texture_handles.push_back(glGetTextureHandleARB(texture));
glMakeTextureHandleResidentARB(texture_handles.back());

texture_handles.push_back(texture->getTextureHandle());
//base_texture->makeResident();
}
m_gpu_render_tasks->updatePerFrameDataBuffer(texture_handles, 2);

@@ -85,12 +88,13 @@ bool megamol::archvis::FEMRenderTaskDataSource::getDataCallback(core::Call& call
{
// TODO get transfer function texture and add as per frame data
std::vector<GLuint64> texture_handles;
auto textures = gpu_mtl_storage->getMaterials().front().textures_names;
auto textures = gpu_mtl_storage->getMaterials().front().textures;
for (auto texture : textures) {
texture_handles.push_back(glGetTextureHandleARB(texture));
glMakeTextureHandleResidentARB(texture_handles.back());

texture_handles.push_back(glGetTextureHandleARB(texture->getTextureHandle()));
//base_texture->makeResident();
}
m_gpu_render_tasks->addPerFrameDataBuffer(texture_handles, 2);
m_gpu_render_tasks->updatePerFrameDataBuffer(texture_handles, 2);
}

rtc->setData(m_gpu_render_tasks);
@@ -7,20 +7,22 @@

#ifndef GPU_MATERIAL_COLLECTION_H_INCLUDED
#define GPU_MATERIAL_COLLECTION_H_INCLUDED
#if (defined(_MSC_VER) && (_MSC_VER > 1000))
# pragma once
#endif /* (defined(_MSC_VER) && (_MSC_VER > 1000)) */

//#include "vislib/graphics/gl/GLSLShader.h"
#include "mmcore/CoreInstance.h"
#include "vislib/graphics/gl/GLSLGeometryShader.h"

#include <memory>
#include <variant>
#include <vector>

#include "mesh.h"

#include "glowl/Texture.hpp"
#include "glowl/Texture2D.hpp"
#include "glowl/Texture2DArray.hpp"
#include "glowl/Texture3D.hpp"
#include "glowl/TextureCubemapArray.hpp"

namespace megamol {
namespace mesh {
@@ -29,29 +31,36 @@ typedef vislib::graphics::gl::GLSLGeometryShader Shader;

class MESH_API GPUMaterialCollecton {
public:
using TexturePtrType =
std::variant <
std::shared_ptr<glowl::Texture>,
std::shared_ptr<glowl::Texture2D>,
std::shared_ptr<glowl::Texture2DArray>,
std::shared_ptr<glowl::Texture3D>,
std::shared_ptr<glowl::TextureCubemapArray> >;

struct Material {
std::shared_ptr<Shader> shader_program;
std::vector<GLuint> textures_names;
std::vector<std::shared_ptr<glowl::Texture>> textures;
};

void addMaterial(
megamol::core::CoreInstance* mm_core_inst, std::string shader_btf_name, std::vector<GLuint> texture_names = {});
megamol::core::CoreInstance* mm_core_inst,
std::string const& shader_btf_name,
std::vector<std::shared_ptr<glowl::Texture>> const& textures = {});

void addMaterial(std::shared_ptr<Shader> const& shader, std::vector<GLuint> texture_names);
void addMaterial(
std::shared_ptr<Shader> const& shader,
std::vector<std::shared_ptr<glowl::Texture>> const& textures = {});

void updateMaterialTexture(size_t mtl_idx, size_t tex_idx, GLuint texture_name);
void updateMaterialTexture(size_t mtl_idx, size_t tex_idx, std::shared_ptr<glowl::Texture> const& texture);

void clearMaterials();

inline std::vector<Material> const& getMaterials();

private:
std::vector<Material> m_materials;

/**
* Storage for textures created and managed by this class
*/
std::vector<std::shared_ptr<glowl::Texture2D>> m_texture;
};

inline std::vector<GPUMaterialCollecton::Material> const& GPUMaterialCollecton::getMaterials() { return m_materials; }
@@ -16,7 +16,10 @@ namespace megamol {
namespace mesh {

void GPUMaterialCollecton::addMaterial(
megamol::core::CoreInstance* mm_core_inst, std::string shader_btf_name, std::vector<GLuint> texture_names) {
megamol::core::CoreInstance* mm_core_inst,
std::string const& shader_btf_name,
std::vector<std::shared_ptr<glowl::Texture>> const& textures)
{
std::shared_ptr<Shader> shader = std::make_shared<Shader>();

vislib::graphics::gl::ShaderSource vert_shader_src;
@@ -68,17 +71,21 @@ void GPUMaterialCollecton::addMaterial(
// return false;
}

addMaterial(shader, texture_names);
addMaterial(shader, textures);
}

void GPUMaterialCollecton::addMaterial(std::shared_ptr<Shader> const& shader, std::vector<GLuint> texture_names) {
void GPUMaterialCollecton::addMaterial(
std::shared_ptr<Shader> const& shader,
std::vector<std::shared_ptr<glowl::Texture>> const& textures)
{
m_materials.push_back(Material());
m_materials.back().shader_program = shader;
m_materials.back().textures_names = texture_names;
m_materials.back().textures = textures;
}

void GPUMaterialCollecton::updateMaterialTexture(size_t mtl_idx, size_t tex_idx, GLuint texture_name) {
m_materials[mtl_idx].textures_names[tex_idx] = texture_name;
void GPUMaterialCollecton::updateMaterialTexture(
size_t mtl_idx, size_t tex_idx, std::shared_ptr<glowl::Texture> const& texture) {
m_materials[mtl_idx].textures[tex_idx] = texture;
}

void GPUMaterialCollecton::clearMaterials() { m_materials.clear(); }

0 comments on commit 8803d23

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