Skip to content

Commit

Permalink
Merge branch 'ospray_linux_fix' of https://github.com/braunms/megamol
Browse files Browse the repository at this point in the history
  • Loading branch information
braunms committed Feb 18, 2021
2 parents c89fbc3 + a8b5fc6 commit 026fc70
Show file tree
Hide file tree
Showing 38 changed files with 798 additions and 994 deletions.
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/require_test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: PR with Test Requirements
about: Create a PR with explicit test instructions.
title: ''
labels: needs testing
assignees: ''

---
<!--Add a description here.
Include a list of issues it fixes in the "Fixes #[]" format if applicable.-->

## Summary of Changes
<!--A list of changes that will be copied into the merge commit message and changelog.-->

## References
<!--A list of references of this PR, for instance related PRs or scientific papers.-->

## Additional context
<!--Add any other context about this PR here-->

## Test Instructions
<!--You have selected this template because you believe not only a code review but also a test is required.
Therefore, provide instructions on how to setup a test for this PR.
Include, if possible, the expected behavior.-->
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/standard_pr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Normal PR
about: Create a normal PR without specific test requirements.
title: ''
labels: ''
assignees: ''

---
<!--Add a description here.
Include a list of issues it fixes in the "Fixes #[]" format if applicable.-->

## Summary of Changes
<!--A list of changes that will be copied into the merge commit message and changelog.-->

## References
<!--A list of references of this PR, for instance related PRs or scientific papers.-->

## Additional context
<!--Add any other context about this PR here-->
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,31 @@ namespace stdfs = std::experimental::filesystem;
#endif
#endif

#include "GUIUtils.h"

#include <fstream>
#include <istream>
#include <iostream>
#include <codecvt>
#include <locale>
#include <string>

#include "vislib/sys/FastFile.h"
#include "mmcore/utility/log/Log.h"


namespace megamol {
namespace gui {
namespace core {
namespace utility {

// #### Utility string conversion functions ############################ //

static inline std::string to_string(std::wstring wstr) {
return std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(wstr);
}

static inline std::wstring to_wstring(std::string str) {
return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(str);
}

// ##################################################################### //
/**
* File utility functions.
*/
Expand All @@ -42,7 +56,12 @@ namespace gui {
/**
* Load raw data from file (e.g. texture data)
*/
static size_t LoadRawFile(std::string name, void** outData);
static bool LoadRawFile(const std::wstring& filename, std::vector<char>& out_data) {
return megamol::core::utility::FileUtils::LoadRawFile(
megamol::core::utility::to_string(filename), out_data);
}

static bool LoadRawFile(const std::string& filename, std::vector<char>& out_data);

/**
* Check if file exists.
Expand Down Expand Up @@ -118,7 +137,7 @@ namespace gui {


template<typename T>
bool megamol::gui::FileUtils::FileExists(const T& path_str) {
bool megamol::core::utility::FileUtils::FileExists(const T& path_str) {
auto path = static_cast<stdfs::path>(path_str);
try {
if (stdfs::exists(path) && stdfs::is_regular_file(path)) {
Expand All @@ -130,7 +149,7 @@ namespace gui {


template<typename T>
bool megamol::gui::FileUtils::FileWithExtensionExists(const T& path_str, const std::string& ext) {
bool megamol::core::utility::FileUtils::FileWithExtensionExists(const T& path_str, const std::string& ext) {
if (FileUtils::FileExists<T>(path_str)) {
auto path = static_cast<stdfs::path>(path_str);
return (path.extension().generic_u8string() == std::string("." + ext));
Expand All @@ -140,14 +159,14 @@ namespace gui {


template<typename T>
bool megamol::gui::FileUtils::FileHasExtension(const T& path_str, const std::string& ext) {
bool megamol::core::utility::FileUtils::FileHasExtension(const T& path_str, const std::string& ext) {
auto path = static_cast<stdfs::path>(path_str);
return (path.extension().generic_u8string() == ext);
}


template<typename T>
std::string megamol::gui::FileUtils::GetFilenameStem(const T& path_str) {
std::string megamol::core::utility::FileUtils::GetFilenameStem(const T& path_str) {
auto path = static_cast<stdfs::path>(path_str);
std::string filename;
if (path.has_stem()) {
Expand All @@ -158,7 +177,7 @@ namespace gui {


template<typename T, typename S>
std::string megamol::gui::FileUtils::SearchFileRecursive(const T& search_path_str, const S& search_file_str) {
std::string megamol::core::utility::FileUtils::SearchFileRecursive(const T& search_path_str, const S& search_file_str) {
auto search_path = static_cast<stdfs::path>(search_path_str);
auto file_path = static_cast<stdfs::path>(search_file_str);
std::string found_path;
Expand All @@ -172,7 +191,8 @@ namespace gui {
}


} // namespace gui
} // namespace utility
} // namespace core
} // namespace megamol

#endif // MEGAMOL_GUI_FILEUTILS_INCLUDED
13 changes: 4 additions & 9 deletions core/include/mmcore/utility/SDFFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#endif /* (defined(_MSC_VER) && (_MSC_VER > 1000)) */


#include "mmcore/view/RenderUtils.h"
#include "mmcore/utility/AbstractFont.h"
#include "mmcore/misc/PngBitmapCodec.h"
#include "mmcore/utility/ResourceWrapper.h"
Expand Down Expand Up @@ -95,7 +96,7 @@ namespace utility {
* - Bold,Italic: false
* - Rendering: java
* - Glyph Cache Page - Width,Height: 1024
* - Glyph set: ASCII + ™ + €
* - Glyph set: ASCII + ™ + €
* - Size: ~90 (glyphs must fit on !one! page)
* - Distance Field - Spread: 10
* - Distance Field - Scale: 50 (set in the end, operation is expensive)
Expand Down Expand Up @@ -577,7 +578,7 @@ namespace utility {
vislib::graphics::gl::GLSLShader shadervertcol;

/** The texture of the font. */
vislib::graphics::gl::OpenGLTexture2D texture;
std::shared_ptr<glowl::Texture2D> texture;

/** Vertex buffer object attributes. */
enum VBOAttrib {
Expand Down Expand Up @@ -653,17 +654,11 @@ namespace utility {
bool loadFontBuffers();

/** Load font info from file. */
bool loadFontInfo(vislib::StringA filename);

/** Load texture from file. */
bool loadFontTexture(vislib::StringA filename);
bool loadFontInfo(vislib::StringW filename);

/** Load shaders from files. */
bool loadFontShader(megamol::core::CoreInstance *core);

/** Load file into outData buffer and return size. */
size_t loadFile(vislib::StringA filename, BYTE **outData);

/**
* Answer the number of lines in the glyph run
*
Expand Down
101 changes: 81 additions & 20 deletions core/include/mmcore/view/RenderUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@

#define GLOWL_OPENGL_INCLUDE_GLAD
#include <glowl/BufferObject.hpp>
#include <glowl/Texture2D.hpp>
#include <glowl/GLSLProgram.hpp>

#include "glowl/FramebufferObject.hpp"

#include "mmcore/utility/FileUtils.h"
#include "mmcore/misc/PngBitmapCodec.h"
#include "mmcore/utility/SDFFont.h"
#include "mmcore/utility/ShaderSourceFactory.h"
#include "mmcore/view/Camera_2.h"

#include "vislib/graphics/gl/GLSLShader.h"
#include "vislib/graphics/gl/IncludeAllGL.h"
#include "vislib/graphics/gl/OpenGLTexture2D.h"
#include "vislib/graphics/gl/ShaderSource.h"

namespace megamol::core::view {

Expand Down Expand Up @@ -72,16 +73,76 @@ static inline glm::quat quaternion_from_vectors(glm::vec3 view_vector, glm::vec3
}


// #### Utility transformation functions ################################### //

static inline glm::vec3 worldspace_to_screenspace(
const glm::vec3& vec_world, const glm::mat4& mvp, const glm::vec2& viewport) {

glm::vec4 world = {vec_world.x, vec_world.y, vec_world.z, 1.0f};
world = mvp * world;
world = world / world.w;
glm::vec3 screen;
screen.x = (world.x + 1.0f) / 2.0f * viewport.x;
screen.y = (world.y + 1.0f) / 2.0f * viewport.y; // flipped y-axis: glm::abs(world.y - 1.0f)
screen.z = -1.0f * (world.z + 1.0f) / 2.0f;
return screen;
}


static inline glm::vec3 screenspace_to_worldspace(
const glm::vec3& vec_screen, const glm::mat4& mvp, const glm::vec2& viewport) {

glm::vec3 screen;
screen.x = (vec_screen.x * 2.0f / viewport.x) - 1.0f;
screen.y = (vec_screen.y * 2.0f / viewport.y) - 1.0f;
screen.z = ((vec_screen.z * 2.0f * -1.0f) - 1.0f);
glm::vec4 world = {screen.x, screen.y, screen.z, 1.0f};
glm::mat4 mvp_inverse = glm::inverse(mvp);
world = mvp_inverse * world;
world = world / world.w;
glm::vec3 vec3d = glm::vec3(world.x, world.y, world.z);
return vec3d;
}


// ##################################################################### //
/*
* Utility class providing simple primitive rendering (using non legacy opengl).
*/
class RenderUtils {

public:

// STATIC functions -------------------------------------------------------

/**
* Load textures.
*/
static bool LoadTextureFromFile(std::shared_ptr<glowl::Texture2D>& out_texture_ptr, const std::wstring& filename) {
return megamol::core::view::RenderUtils::LoadTextureFromFile(
out_texture_ptr, megamol::core::utility::to_string(filename));
}

static bool LoadTextureFromFile(std::shared_ptr<glowl::Texture2D>& out_texture_ptr, const std::string& filename);

static bool LoadTextureFromData(
std::shared_ptr<glowl::Texture2D>& out_texture_ptr, int width, int height, float* data);

/**
* Create shader.
*/
static bool CreateShader(std::shared_ptr<glowl::GLSLProgram>& out_shader_ptr, const std::string& vertex_code,
const std::string& fragment_code);

// LOCAL functions -------------------------------------------------------

bool InitPrimitiveRendering(megamol::core::utility::ShaderSourceFactory& factory);

bool LoadTextureFromFile(std::wstring filename, GLuint& out_texture_id);
// Keeps the texture object in render utils for later access via texture id
bool LoadTextureFromFile(GLuint& out_texture_id, const std::wstring& filename, bool reload = false) {
return this->LoadTextureFromFile(out_texture_id, megamol::core::utility::to_string(filename), reload);
}
bool LoadTextureFromFile(GLuint& out_texture_id, const std::string& filename, bool reload = false);

void PushPointPrimitive(const glm::vec3& pos_center, float size, const glm::vec3& cam_view,
const glm::vec3& cam_pos, const glm::vec4& color, bool sort = false);
Expand Down Expand Up @@ -137,6 +198,13 @@ class RenderUtils {
this->smooth = s;
}

unsigned int GetTextureWidth(GLuint texture_id) const;
unsigned int GetTextureHeight(GLuint texture_id) const;

inline void DeleteAllTextures(void) {
this->textures.clear();
}

protected:
RenderUtils();

Expand All @@ -157,24 +225,22 @@ class RenderUtils {
DataType attributes;
} ShaderDataType;

typedef vislib::graphics::gl::OpenGLTexture2D TextureType;
typedef std::vector<std::shared_ptr<TextureType>> TexturesType;
typedef std::array<ShaderDataType, Primitives::PRIM_COUNT> QueuesType;
typedef std::array<vislib::graphics::gl::GLSLShader, Primitives::PRIM_COUNT> ShadersType;
typedef std::array<std::unique_ptr<glowl::BufferObject>, Buffers::BUFF_COUNT> BuffersType;

// VARIABLES ------------------------------------------------------- //

bool smooth;
bool init_once;
TexturesType textures;
GLuint vertex_array;
QueuesType queues;
ShadersType shaders;
BuffersType buffers;
std::vector<std::shared_ptr<glowl::Texture2D>> textures;
std::array<ShaderDataType, Primitives::PRIM_COUNT> queues;
std::array<std::shared_ptr<glowl::GLSLProgram>, Primitives::PRIM_COUNT> shaders;
std::array<std::shared_ptr<glowl::BufferObject>, Buffers::BUFF_COUNT> buffers;

// FUNCTIONS ------------------------------------------------------- //

bool createShader(std::shared_ptr<glowl::GLSLProgram>& out_shader_ptr,
megamol::core::utility::ShaderSourceFactory& shader_factory, const std::string& vertex_btf_snipprt,
const std::string& fragment_btf_snippet);

void pushQuad(Primitives primitive, GLuint texture_id, const glm::vec3& pos_bottom_left,
const glm::vec3& pos_upper_left, const glm::vec3& pos_upper_right, const glm::vec3& pos_bottom_right,
const glm::vec4& color, const glm::vec4& attributes);
Expand All @@ -183,11 +249,6 @@ class RenderUtils {

void sortPrimitiveQueue(Primitives primitive);

bool createShader(vislib::graphics::gl::GLSLShader& shader, const std::string* const vertex_code,
const std::string* const fragment_code);

const std::string getShaderCode(megamol::core::utility::ShaderSourceFactory& factory, std::string snippet_name);

size_t loadRawFile(std::wstring filename, BYTE** outData);

void clearQueue(Primitives primitive);
Expand Down
Loading

0 comments on commit 026fc70

Please sign in to comment.