Commit 6a177ab5 authored by Philip Trettner's avatar Philip Trettner

Assimp import works better now, Cube generator got some fixes, started rendering pipeline sublib

parent 3ad1e319
......@@ -16,6 +16,10 @@ target_link_libraries(glow-extras PUBLIC glow-extras-shader)
add_subdirectory(geometry)
target_link_libraries(glow-extras PUBLIC glow-extras-geometry)
# Rendering Pipeline
add_subdirectory(pipeline)
target_link_libraries(glow-extras PUBLIC glow-extras-pipeline)
# Timing
# requires 'aion'
if (TARGET aion)
......
......@@ -47,6 +47,7 @@ Currently supported sub-libs with their intent and dependencies.
* glow-extras-shader
* glow-extras-assimp
* glow-extras-timing
* glow-extras-pipeline
### glow-extras-camera
......@@ -82,3 +83,7 @@ Suggested submodule: https://www.graphics.rwth-aachen.de:9000/ptrettner/assimp-l
Suggested submodule: https://graphics.rwth-aachen.de:9000/ptrettner/aion
*TODO*: Aion timings and custom GPU timer
### glow-extras-pipeline
A pre-built Forward+ rendering pipeline with various configurable features.
#include "Importer.hh"
#include <glm/glm.hpp>
#include <glow/objects/VertexArray.hh>
#include <glow/objects/ArrayBuffer.hh>
#include <glow/objects/ElementArrayBuffer.hh>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
glow::SharedVertexArray glow::assimp::Importer::load(const std::string &filename)
static glm::vec3 aiCast(aiVector3D const& v)
{
return {v.x, v.y, v.z};
}
static glm::vec4 aiCast(aiColor4D const& v)
{
return {v.r, v.g, v.b, v.a};
}
glow::assimp::Importer::Importer()
{
}
glow::SharedVertexArray glow::assimp::Importer::load(const std::string& filename)
{
using namespace assimp;
......@@ -34,9 +51,127 @@ glow::SharedVertexArray glow::assimp::Importer::load(const std::string &filename
return nullptr;
}
if (!scene->HasMeshes())
{
error() << "File `" << filename << "' has no meshes.";
return nullptr;
}
std::vector<glm::vec3> positions;
std::vector<glm::vec3> normals;
std::vector<glm::vec3> tangents;
std::vector<std::vector<glm::vec2>> texCoords;
std::vector<std::vector<glm::vec4>> colors;
std::vector<uint32_t> indices;
auto baseIdx = 0u;
for (auto i = 0u; i < scene->mNumMeshes; ++i)
{
auto const& mesh = scene->mMeshes[i];
auto colorsCnt = mesh->GetNumColorChannels();
auto texCoordsCnt = mesh->GetNumUVChannels();
if (texCoords.empty())
texCoords.resize(texCoordsCnt);
else if (texCoords.size() != texCoordsCnt)
{
error() << "File `" << filename << "':";
error() << " contains inconsistent texture coordinate counts";
return nullptr;
}
if (colors.empty())
colors.resize(colorsCnt);
else if (colors.size() != colorsCnt)
{
error() << "File `" << filename << "':";
error() << " contains inconsistent vertex color counts";
return nullptr;
}
// add faces
auto fCnt = mesh->mNumFaces;
for (auto f = 0u; f < fCnt; ++f)
{
auto const& face = mesh->mFaces[f];
if (face.mNumIndices != 3)
{
error() << "File `" << filename << "':.";
error() << " non-3 faces not implemented/supported";
return nullptr;
}
for (auto fi = 0u; fi < face.mNumIndices; ++fi)
{
indices.push_back(baseIdx + face.mIndices[fi]);
}
}
// add vertices
auto vCnt = mesh->mNumVertices;
for (auto v = 0u; v < vCnt; ++v)
{
positions.push_back(aiCast(mesh->mVertices[v]));
if (mesh->HasNormals())
normals.push_back(aiCast(mesh->mNormals[v]));
if (mesh->HasTangentsAndBitangents())
tangents.push_back(aiCast(mesh->mTangents[v]));
for (auto t = 0u; t < texCoordsCnt; ++t)
texCoords[t].push_back((glm::vec2)aiCast(mesh->mTextureCoords[t][v]));
for (auto t = 0u; t < colorsCnt; ++t)
colors[t].push_back(aiCast(mesh->mColors[t][v]));
}
baseIdx = positions.size();
}
std::vector<SharedArrayBuffer> abs;
// TODO
if (!positions.empty())
{
auto ab = ArrayBuffer::create();
ab->defineAttribute<glm::vec3>("aPosition");
ab->bind().setData(positions);
abs.push_back(ab);
}
if (!normals.empty())
{
auto ab = ArrayBuffer::create();
ab->defineAttribute<glm::vec3>("aNormal");
ab->bind().setData(normals);
abs.push_back(ab);
}
if (!tangents.empty())
{
auto ab = ArrayBuffer::create();
ab->defineAttribute<glm::vec3>("aTangent");
ab->bind().setData(tangents);
abs.push_back(ab);
}
for (auto i = 0u; i < colors.size(); ++i)
{
auto ab = ArrayBuffer::create();
if (i == 0)
ab->defineAttribute<glm::vec4>("aColor");
else
ab->defineAttribute<glm::vec4>("aColor" + std::to_string(i + 1));
ab->bind().setData(colors[i]);
abs.push_back(ab);
}
for (auto i = 0u; i < texCoords.size(); ++i)
{
auto ab = ArrayBuffer::create();
if (i == 0)
ab->defineAttribute<glm::vec2>("aTexCoord");
else
ab->defineAttribute<glm::vec2>("aTexCoord" + std::to_string(i + 1));
ab->bind().setData(texCoords[i]);
abs.push_back(ab);
}
return VertexArray::create(abs, nullptr, GL_TRIANGLES);
auto eab = ElementArrayBuffer::create(indices);
return VertexArray::create(abs, eab, GL_TRIANGLES);
}
......@@ -19,8 +19,14 @@ namespace assimp
* vec3 aTangent;
* vec2 aTexCoord;
* vec2 aTexCoord2; (3, 4, ... depending on mesh)
* vec4 aColor;
* vec4 aColor2; (3, 4, ... depending on mesh)
*
* TODO: Support for point clouds and lines
* TODO: bones/animations
*
* Usage: auto va = assimp::Importer().load(filename);
* (if you want to customize flags, the Importer can be saved locally)
*
*/
class Importer final
......@@ -50,6 +56,8 @@ public:
GLOW_PROPERTY(GenerateUVCoords);
public:
Importer();
/// Loads a VA from a given filename
/// Supported file formats at time of writing this are:
///
......
......@@ -123,7 +123,7 @@ public:
ab->bind().setData(vertices);
eab->bind().setIndices(indices);
return VertexArray::create(ab, eab, GL_TRIANGLE_STRIP);
return VertexArray::create(ab, eab, GL_TRIANGLES);
}
public: // Predefined attributes
......
cmake_minimum_required(VERSION 3.0)
file(GLOB_RECURSE SOURCE_FILES "*.cc")
file(GLOB_RECURSE HEADER_FILES "*.hh")
add_library(glow-extras-pipeline ${GLOW_LINK_TYPE} ${SOURCE_FILES} ${HEADER_FILES})
target_include_directories(glow-extras-pipeline PUBLIC ./)
target_compile_options(glow-extras-pipeline PRIVATE -Wall -Werror -std=c++11)
target_link_libraries(glow-extras-pipeline PUBLIC glow glow-extras-camera)
target_link_libraries(glow-extras-pipeline PRIVATE glow-extras-geometry)
#pragma once
namespace glow {
namespace pipeline {
enum class RenderPass {
};
}
}
#pragma once
#include <functional>
#include "RenderPass.hh"
#include <glow/common/shared.hh>
namespace glow
{
namespace camera
{
GLOW_SHARED(class, FixedCamera);
}
namespace pipeline
{
/**
* A Forward+ Rendering Pipeline with post-processing support
*
* Basic usage:
* // creation
* TODO
*
* // rendering
* pipeline->updateShadows(...); // optional
* pipeline->render(myRenderFunc);
*
*/
class RenderingPipeline
{
public:
/**
* @brief executes the whole rendering pipeline
* @param renderFunc function to call for every renderpass. Use the provided camera and it's viewport.
*/
void render(std::function<void(RenderPass pass, camera::FixedCamera* camera)> const& renderFunc);
};
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment