Commit c11c70aa authored by Simon Boyé's avatar Simon Boyé

Vitelotte: Better OpenGL / shader handling + move srgb to gl_utils.

parent 0e3601ac
// Generated by shader2cpp.
// 2015-01-02T22:31:38.866645
// 2015-01-09T13:54:33.104329
#ifndef PATATE_VITELOTTE_UTILS_SHADER_H
#define PATATE_VITELOTTE_UTILS_SHADER_H
namespace Vitelotte
......@@ -478,3 +482,4 @@ static const char* vert_common_glsl =
}
}
#endif PATATE_VITELOTTE_UTILS_SHADER_H
......@@ -6,16 +6,13 @@
#include "../../common/gl_utils/shader.h"
//#include "shaders.hpp"
#include "../Core/femUtils.h"
#include "shaders.hpp"
namespace Vitelotte {
inline Eigen::Vector4f linearToSrgb(const Eigen::Vector4f& linear);
inline Eigen::Vector4f srgbToLinear(const Eigen::Vector4f& srgb);
class VGMeshGL2RendererShader
{
public:
......
......@@ -5,28 +5,6 @@ namespace Vitelotte
{
//Eigen::Vector4f linearToSrgb(const Eigen::Vector4f& linear)
//{
// Eigen::Vector4f srgb = linear;
// for(int i=0; i<3; ++i)
// srgb(i) = linear(i) > 0.0031308?
// 1.055 * std::pow(linear(i), 1/2.4):
// 12.92 * linear(i);
// return srgb;
//}
//Eigen::Vector4f srgbToLinear(const Eigen::Vector4f& srgb)
//{
// Eigen::Vector4f linear = srgb;
// for(int i=0; i<3; ++i)
// linear(i) = linear(i) > 0.04045?
// std::pow((linear(i)+0.055) / 1.055, 2.4):
// linear(i) / 12.92;
// return linear;
//}
VGMeshRendererGL2DefaultShader::VGMeshRendererGL2DefaultShader()
: m_viewMatrix(Eigen::Matrix4f::Identity()),
m_singularTriangles(false),
......@@ -436,7 +414,7 @@ VGMeshGL2Renderer<_Mesh>::nodeValue(Node node) const
if(m_pMesh->isValid(node) && m_pMesh->isConstraint(node))
{
if(m_renderSrgb)
return srgbToLinear(m_pMesh->nodeValue(node));
return PatateCommon::srgbToLinear(m_pMesh->nodeValue(node));
else
return m_pMesh->nodeValue(node);
}
......
......@@ -5,17 +5,15 @@
#include <Eigen/Dense>
#include "../../common/gl_utils/shader.h"
#include "../../common/gl_utils/color.h"
#include "../Core/femUtils.h"
#include "shaders.hpp"
namespace Vitelotte {
inline Eigen::Vector4f linearToSrgb(const Eigen::Vector4f& linear);
inline Eigen::Vector4f srgbToLinear(const Eigen::Vector4f& srgb);
class VGMeshRendererShader
{
public:
......
......@@ -5,28 +5,6 @@ namespace Vitelotte
{
Eigen::Vector4f linearToSrgb(const Eigen::Vector4f& linear)
{
Eigen::Vector4f srgb = linear;
for(int i=0; i<3; ++i)
srgb(i) = linear(i) > 0.0031308?
1.055 * std::pow(linear(i), 1/2.4):
12.92 * linear(i);
return srgb;
}
Eigen::Vector4f srgbToLinear(const Eigen::Vector4f& srgb)
{
Eigen::Vector4f linear = srgb;
for(int i=0; i<3; ++i)
linear(i) = linear(i) > 0.04045?
std::pow((linear(i)+0.055) / 1.055, 2.4):
linear(i) / 12.92;
return linear;
}
VGMeshRendererDefaultShader::VGMeshRendererDefaultShader()
: m_viewMatrix(Eigen::Matrix4f::Identity()),
m_singularTriangles(false),
......@@ -409,7 +387,7 @@ inline typename VGMeshRenderer<_Mesh>::NodeValue
VGMeshRenderer<_Mesh>::nodeValue(Node node) const
{
if(m_pMesh->isValid(node) && m_pMesh->isConstraint(node))
return srgbToLinear(m_pMesh->nodeValue(node));
return PatateCommon::srgbToLinear(m_pMesh->nodeValue(node));
return NodeValue(0, 0, 0, 1); // FIXME: Make this class work for Chan != 4
}
......
#ifndef _PATATE_COMMON_GL_UTILS_COLOR_
#define _PATATE_COMMON_GL_UTILS_COLOR_
#include "Eigen/Dense"
namespace PatateCommon
{
inline Eigen::Vector4f linearToSrgb(const Eigen::Vector4f& linear)
{
Eigen::Vector4f srgb = linear;
for(int i=0; i<3; ++i)
srgb(i) = linear(i) > 0.0031308?
1.055 * std::pow(linear(i), 1/2.4):
12.92 * linear(i);
return srgb;
}
inline Eigen::Vector4f srgbToLinear(const Eigen::Vector4f& srgb)
{
Eigen::Vector4f linear = srgb;
for(int i=0; i<3; ++i)
linear(i) = linear(i) > 0.04045?
std::pow((linear(i)+0.055) / 1.055, 2.4):
linear(i) / 12.92;
return linear;
}
}
#endif
......@@ -7,6 +7,7 @@
#include <string.h>
#ifndef PATATE_ASSERT_NO_GL_ERROR
#define PATATE_ASSERT_NO_GL_ERROR() \
{ \
GLenum Error = glGetError(); \
......@@ -16,6 +17,7 @@
exit(0); \
} \
}
#endif
#define PATATE_FIELD_OFFSET(_struct, _field) &(static_cast<_struct*>(0)->_field)
......
#!/bin/sh
./bin/shader2cpp -n Vitelotte::shader -o Patate/Vitelotte/Utils/shaders.hpp Patate/Vitelotte/Shaders/*
./bin/shader2cpp \
-n Vitelotte::shader \
-g PATATE_VITELOTTE_UTILS_SHADER_H \
-o Patate/Vitelotte/Utils/shaders.hpp \
Patate/Vitelotte/Shaders/*
......@@ -10,6 +10,8 @@ from datetime import datetime
argparser = ArgumentParser(description='Convert a set of shaders into cpp source code')
argparser.add_argument('-e', '--extern', default=False, action='store_true',
help="Declare variables with external linkage.")
argparser.add_argument('-g', '--include-guard', default='',
help="Protect the file against multiple inclusion.")
argparser.add_argument('-o', '--output', default='-',
help="Write the output to the file output, or stdout if omitted or output is '-'.")
argparser.add_argument('-n', '--namespace', default='',
......@@ -26,6 +28,12 @@ print("// {}".format(datetime.utcnow().isoformat()), file=out)
print(file=out)
print(file=out)
if options.include_guard:
print("#ifndef", options.include_guard, file=out)
print("#define", options.include_guard, file=out)
print(file=out)
print(file=out)
if namespaces:
for ns in namespaces:
if ns != '':
......@@ -52,5 +60,7 @@ if namespaces:
print("}", file=out)
print(file=out)
if options.include_guard:
print("#endif", options.include_guard, file=out)
out.close()
......@@ -361,7 +361,7 @@ Eigen::Vector4f VGNodeRenderer::convColor(const Eigen::Vector4f& color) const
{
if(m_linearizeSrgb)
{
return Vitelotte::srgbToLinear(color);
return PatateCommon::srgbToLinear(color);
}
return color;
}
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