Initial commit
This commit is contained in:
commit
686dcaf351
68 changed files with 6230 additions and 0 deletions
282
include/KHR/khrplatform.h
Normal file
282
include/KHR/khrplatform.h
Normal file
|
@ -0,0 +1,282 @@
|
|||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef _WIN64
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
57
include/REDRUM.h
Normal file
57
include/REDRUM.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
// This file is part of libigl, a simple c++ geometry processing library.
|
||||
//
|
||||
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
// obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#ifndef IGL_REDRUM_H
|
||||
#define IGL_REDRUM_H
|
||||
|
||||
// Q: These should probably be inside the igl namespace. What's the correct
|
||||
// way to do that?
|
||||
// A: I guess the right way is to not use a macro but a proper function with
|
||||
// streams as input and output.
|
||||
|
||||
// ANSI color codes for formatting iostream style output
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
// Bold Red, etc.
|
||||
#define NORUM(X) X
|
||||
#define BOLD(X) X
|
||||
#define REDRUM(X) X
|
||||
#define GREENRUM(X) X
|
||||
#define YELLOWRUM(X) X
|
||||
#define BLUERUM(X) X
|
||||
#define MAGENTARUM(X) X
|
||||
#define CYANRUM(X) X
|
||||
// Regular Red, etc.
|
||||
#define REDGIN(X) X
|
||||
#define GREENGIN(X) X
|
||||
#define YELLOWGIN(X) X
|
||||
#define BLUEGIN(X) X
|
||||
#define MAGENTAGIN(X) X
|
||||
#define CYANGIN(X) X
|
||||
|
||||
#else
|
||||
|
||||
// Bold Red, etc.
|
||||
#define NORUM(X) ""<<X<<""
|
||||
#define REDRUM(X) "\e[1m\e[31m"<<X<<"\e[m"
|
||||
#define GREENRUM(X) "\e[1m\e[32m"<<X<<"\e[m"
|
||||
#define YELLOWRUM(X) "\e[1m\e[33m"<<X<<"\e[m"
|
||||
#define BLUERUM(X) "\e[1m\e[34m"<<X<<"\e[m"
|
||||
#define MAGENTARUM(X) "\e[1m\e[35m"<<X<<"\e[m"
|
||||
#define CYANRUM(X) "\e[1m\e[36m"<<X<<"\e[m"
|
||||
// Regular Red, etc.
|
||||
#define REDGIN(X) "\e[31m"<<X<<"\e[m"
|
||||
#define GREENGIN(X) "\e[32m"<<X<<"\e[m"
|
||||
#define YELLOWGIN(X) "\e[33m"<<X<<"\e[m"
|
||||
#define BLUEGIN(X) "\e[34m"<<X<<"\e[m"
|
||||
#define MAGENTAGIN(X) "\e[35m"<<X<<"\e[m"
|
||||
#define CYANGIN(X) "\e[36m"<<X<<"\e[m"
|
||||
#define BOLD(X) "\e[1m"<<X<<"\e[m"
|
||||
#endif
|
||||
|
||||
#endif
|
18
include/STR.h
Normal file
18
include/STR.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
// This file is part of libigl, a simple c++ geometry processing library.
|
||||
//
|
||||
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
// obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#ifndef IGL_STR_H
|
||||
#define IGL_STR_H
|
||||
// http://stackoverflow.com/a/2433143/148668
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
// Suppose you have a function:
|
||||
// void func(std::string c);
|
||||
// Then you can write:
|
||||
// func(STR("foo"<<1<<"bar"));
|
||||
#define STR(X) static_cast<std::ostringstream&>(std::ostringstream().flush() << X).str()
|
||||
#endif
|
153
include/create_shader_program_from_files.h
Normal file
153
include/create_shader_program_from_files.h
Normal file
|
@ -0,0 +1,153 @@
|
|||
#ifndef CREATE_SHADER_PROGRAM_FROM_FILES_H
|
||||
#define CREATE_SHADER_PROGRAM_FROM_FILES_H
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Create a GLSL shader program given a list of paths containing shader code for
|
||||
// each shader in the vertex-tessellation-fragment shader pipeline. Prints error
|
||||
// messages on failure.
|
||||
//
|
||||
// Inputs:
|
||||
// vertex_shader_paths ordered list of paths to files containing glsl vertex
|
||||
// shader code.
|
||||
// tess_control_shader_paths ordered list of paths to files containing glsl
|
||||
// tessellation control shader code.
|
||||
// tess_evaluation_shader_paths ordered list of paths to files containing glsl
|
||||
// tessellation evaluation shader code.
|
||||
// fragment_shader_paths ordered list of paths to files containing glsl fragment
|
||||
// shader code.
|
||||
// Outputs:
|
||||
// id identifier of compiled shader program
|
||||
// Returns true iff success
|
||||
inline bool create_shader_program_from_files(
|
||||
const std::vector<std::string> & vertex_shader_paths,
|
||||
const std::vector<std::string> & tess_control_shader_paths,
|
||||
const std::vector<std::string> & tess_evaluation_shader_paths,
|
||||
const std::vector<std::string> & fragment_shader_paths,
|
||||
GLuint & id);
|
||||
|
||||
// Implementation
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "REDRUM.h"
|
||||
#include "STR.h"
|
||||
#include "print_shader_info_log.h"
|
||||
#include "print_program_info_log.h"
|
||||
|
||||
inline bool create_shader_program_from_files(
|
||||
const std::vector<std::string> & vertex_shader_paths,
|
||||
const std::vector<std::string> & tess_control_shader_paths,
|
||||
const std::vector<std::string> & tess_evaluation_shader_paths,
|
||||
const std::vector<std::string> & fragment_shader_paths,
|
||||
GLuint & id)
|
||||
{
|
||||
const auto create_compile_attach = [](
|
||||
const std::vector<std::string> & paths,
|
||||
const GLenum type,
|
||||
const GLuint prog_id,
|
||||
GLuint & s) -> bool
|
||||
{
|
||||
const std::string type_str =
|
||||
(type == GL_VERTEX_SHADER ? STR(BOLD("vertex shader")) :
|
||||
(type == GL_FRAGMENT_SHADER ? STR(BOLD("fragment shader")) :
|
||||
(type == GL_TESS_CONTROL_SHADER ? STR(BOLD("tessellation control shader")) :
|
||||
(type == GL_TESS_EVALUATION_SHADER ? STR(BOLD("tessellation evaluation shader")) :
|
||||
"unknown shader"))));
|
||||
int total_length = 0;
|
||||
std::vector<std::string> strs;
|
||||
{
|
||||
for(int p = 0;p<paths.size();p++)
|
||||
{
|
||||
const auto & path = paths[p];
|
||||
std::ifstream t(path);
|
||||
if(t.fail())
|
||||
{
|
||||
std::cerr<<REDRUM("ERROR")<<": failed to open "<<path<<std::endl;
|
||||
return false;
|
||||
}
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
if(p!=0)
|
||||
{
|
||||
strs.push_back(STR(std::endl<<"#line 1 "<<p<<std::endl));
|
||||
}
|
||||
strs.push_back(buffer.str());
|
||||
total_length += static_cast<int>(buffer.str().length());
|
||||
}
|
||||
}
|
||||
std::vector<const char *> cstrs;
|
||||
for(const auto & str : strs)
|
||||
{
|
||||
cstrs.emplace_back(str.c_str());
|
||||
}
|
||||
if(total_length == 0)
|
||||
{
|
||||
std::cerr<<YELLOWRUM("WARNING")<<": "<<type_str<<" is empty..."<<std::endl;;
|
||||
s = 0;
|
||||
return false;
|
||||
}
|
||||
s = glCreateShader(type);
|
||||
if(s == 0)
|
||||
{
|
||||
std::cerr<<"failed to create "<<type_str<<std::endl;
|
||||
return false;
|
||||
}
|
||||
{
|
||||
glShaderSource(s,(GLsizei)cstrs.size(),&cstrs[0],NULL);
|
||||
}
|
||||
glCompileShader(s);
|
||||
print_shader_info_log(type_str,s,paths);
|
||||
if(!glIsShader(s))
|
||||
{
|
||||
std::cerr<<type_str<<" failed to compile."<<std::endl;
|
||||
return false;
|
||||
}
|
||||
glAttachShader(prog_id,s);
|
||||
return true;
|
||||
};
|
||||
|
||||
// create program
|
||||
id = glCreateProgram();
|
||||
if(id == 0)
|
||||
{
|
||||
std::cerr<<REDRUM("ERROR")<<": could not create shader program."<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// create shaders
|
||||
GLuint v=0,tc=0,te=0,f=0;
|
||||
|
||||
create_compile_attach(vertex_shader_paths,GL_VERTEX_SHADER,id,v);
|
||||
create_compile_attach(tess_control_shader_paths,GL_TESS_CONTROL_SHADER,id,tc);
|
||||
create_compile_attach(tess_evaluation_shader_paths,GL_TESS_EVALUATION_SHADER,id,te);
|
||||
create_compile_attach(fragment_shader_paths,GL_FRAGMENT_SHADER,id,f);
|
||||
|
||||
// Link program
|
||||
glLinkProgram(id);
|
||||
const auto & detach = [&id](const GLuint shader)
|
||||
{
|
||||
if(shader)
|
||||
{
|
||||
glDetachShader(id,shader);
|
||||
glDeleteShader(shader);
|
||||
}
|
||||
};
|
||||
detach(f);
|
||||
detach(v);
|
||||
|
||||
// print log if any
|
||||
print_program_info_log(id);
|
||||
GLint status;
|
||||
glGetProgramiv(id,GL_LINK_STATUS,&status);
|
||||
if(status != GL_TRUE)
|
||||
{
|
||||
std::cerr<<REDRUM("ERROR")<<": Failed to link shader program"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout<<GREENRUM("shader compilation successful.")<<std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
14
include/get_seconds.h
Normal file
14
include/get_seconds.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef GET_SECONDS_H
|
||||
#define GET_SECONDS_H
|
||||
// Return current epoch time in seconds
|
||||
double get_seconds();
|
||||
|
||||
// Implementation
|
||||
#include <chrono>
|
||||
double get_seconds()
|
||||
{
|
||||
return
|
||||
std::chrono::duration<double>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
#endif
|
2401
include/glad/glad.h
Normal file
2401
include/glad/glad.h
Normal file
File diff suppressed because it is too large
Load diff
63
include/icosahedron.h
Normal file
63
include/icosahedron.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
#ifndef ICOSAHEDRON_H
|
||||
#define ICOSAHEDRON_H
|
||||
#include <Eigen/Core>
|
||||
|
||||
// Construct a triangle mesh of an icosahedron.
|
||||
//
|
||||
// Outputs:
|
||||
// V 12 by 3 list of 3D mesh vertex positions
|
||||
// F 20 by 3 list of triangle indices into V
|
||||
template <
|
||||
typename DerivedV,
|
||||
typename DerivedF
|
||||
>
|
||||
inline void icosahedron(
|
||||
Eigen::PlainObjectBase<DerivedV> & V,
|
||||
Eigen::PlainObjectBase<DerivedF> & F);
|
||||
|
||||
// Implementation
|
||||
|
||||
template <
|
||||
typename DerivedV,
|
||||
typename DerivedF
|
||||
>
|
||||
inline void icosahedron(
|
||||
Eigen::PlainObjectBase<DerivedV> & V,
|
||||
Eigen::PlainObjectBase<DerivedF> & F)
|
||||
{
|
||||
V = (DerivedV(12,3) <<
|
||||
0,0,1,
|
||||
0.72360679774997894,-0.52573111211913359,0.44721359549995793,
|
||||
0.72360679774997894,0.52573111211913359,0.44721359549995793,
|
||||
-0.27639320225002095,0.85065080835203999,0.44721359549995793,
|
||||
-0.89442719099991586,1.0953573965284052e-16,0.44721359549995793,
|
||||
-0.27639320225002112,-0.85065080835203988,0.44721359549995793,
|
||||
0.89442719099991586,0,-0.44721359549995793,
|
||||
0.27639320225002106,0.85065080835203988,-0.44721359549995793,
|
||||
-0.72360679774997883,0.5257311121191337,-0.44721359549995793,
|
||||
-0.72360679774997894,-0.52573111211913348,-0.44721359549995793,
|
||||
0.27639320225002084,-0.85065080835203999,-0.44721359549995793,
|
||||
0,0,-1).finished();
|
||||
F = (DerivedF(20,3)<<
|
||||
0,1,2,
|
||||
0,2,3,
|
||||
0,3,4,
|
||||
0,4,5,
|
||||
0,5,1,
|
||||
1,6,2,
|
||||
2,7,3,
|
||||
3,8,4,
|
||||
4,9,5,
|
||||
5,10,1,
|
||||
6,7,2,
|
||||
7,8,3,
|
||||
8,9,4,
|
||||
9,10,5,
|
||||
10,6,1,
|
||||
6,11,7,
|
||||
7,11,8,
|
||||
8,11,9,
|
||||
9,11,10,
|
||||
10,11,6).finished();
|
||||
}
|
||||
#endif
|
64
include/last_modification_time.h
Normal file
64
include/last_modification_time.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#ifndef LAST_MODIFICATION_TIME_H
|
||||
#define LAST_MODIFICATION_TIME_H
|
||||
#include <string>
|
||||
// Inputs:
|
||||
// path path to file in question
|
||||
// Returns the last time this file has been modified in seconds.
|
||||
double last_modification_time(const std::string & path);
|
||||
|
||||
// Implementation
|
||||
|
||||
#if WIN32
|
||||
|
||||
// Shot in the dark... I don't even know if this compiles
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <cassert>
|
||||
|
||||
double last_modification_time(const std::string & path)
|
||||
{
|
||||
// https://www.rosettacode.org/wiki/File_modification_time#Windows
|
||||
FILETIME modtime;
|
||||
//SYSTEMTIME st;
|
||||
HANDLE fh;
|
||||
std::wstring w_path = std::wstring(path.begin(), path.end());
|
||||
fh = CreateFileW(w_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES,
|
||||
0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if(fh == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(GetFileTime(fh, NULL, NULL, &modtime) == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
CloseHandle(fh);
|
||||
// https://stackoverflow.com/a/19709740/148668
|
||||
__int64* val = (__int64*) &modtime;
|
||||
return static_cast<double>(*val) / 10000000.0 - 11644473600.0;
|
||||
}
|
||||
#else
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <ctime>
|
||||
#include <fcntl.h>
|
||||
|
||||
double last_modification_time(const std::string & path)
|
||||
{
|
||||
struct stat s;
|
||||
struct timespec t = {0,0};
|
||||
if (stat(path.c_str(), &s) < 0) { return -1; }
|
||||
#ifdef __APPLE__
|
||||
t = s.st_mtimespec;
|
||||
#else // Linux?
|
||||
t = s.st_mtim;
|
||||
#endif
|
||||
return double(t.tv_sec) + double(t.tv_nsec)*1e-9;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
38
include/load_shader.h
Normal file
38
include/load_shader.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
// This file is part of libigl, a simple c++ geometry processing library.
|
||||
//
|
||||
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
// obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#ifndef IGL_OPENGL_LOAD_SHADER_H
|
||||
#define IGL_OPENGL_LOAD_SHADER_H
|
||||
#include "../igl_inline.h"
|
||||
#include "gl.h"
|
||||
#include <string>
|
||||
|
||||
namespace igl
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// Creates and compiles a shader from a given string
|
||||
//
|
||||
// Inputs:
|
||||
// src string containing GLSL shader code
|
||||
// type GLSL type of shader, one of:
|
||||
// GL_VERTEX_SHADER
|
||||
// GL_FRAGMENT_SHADER
|
||||
// GL_GEOMETRY_SHADER
|
||||
// Returns index id of the newly created shader, 0 on error
|
||||
//
|
||||
// Will immediately return 0 if src is empty.
|
||||
IGL_INLINE GLuint load_shader(
|
||||
const std::string & src,const GLenum type);
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation
|
||||
|
||||
|
||||
#endif
|
||||
|
40
include/mesh_to_vao.h
Normal file
40
include/mesh_to_vao.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef MESH_TO_VAO_H
|
||||
#define MESH_TO_VAO_H
|
||||
#include <Eigen/Core>
|
||||
|
||||
// Send a triangle mesh to the GPU using a vertex array object.
|
||||
//
|
||||
// Inputs:
|
||||
// V #V by 3 list of 3D mesh vertex positions
|
||||
// F #F by 3 list of triangle indices into V
|
||||
// Outputs:
|
||||
// VAO identifier of compiled vertex array object.
|
||||
inline void mesh_to_vao(
|
||||
const Eigen::Matrix< float,Eigen::Dynamic,3,Eigen::RowMajor> & V,
|
||||
const Eigen::Matrix<GLuint,Eigen::Dynamic,3,Eigen::RowMajor> & F,
|
||||
GLuint & VAO);
|
||||
|
||||
// Implementation
|
||||
|
||||
inline void mesh_to_vao(
|
||||
const Eigen::Matrix< float,Eigen::Dynamic,3,Eigen::RowMajor> & V,
|
||||
const Eigen::Matrix<GLuint,Eigen::Dynamic,3,Eigen::RowMajor> & F,
|
||||
GLuint & VAO)
|
||||
{
|
||||
// Generate and attach buffers to vertex array
|
||||
glGenVertexArrays(1, &VAO);
|
||||
GLuint VBO, EBO;
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenBuffers(1, &EBO);
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*V.size(), V.data(), GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*F.size(), F.data(), GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
#endif
|
269
include/path_glsl_files.h
Normal file
269
include/path_glsl_files.h
Normal file
|
@ -0,0 +1,269 @@
|
|||
#ifndef PATH_GLSL_FILES_H
|
||||
#define PATH_GLSL_FILES_H
|
||||
|
||||
static void setShaderPaths(int task,
|
||||
std::vector<std::string>& all_paths,
|
||||
std::vector<std::string>& vertex_shader_paths,
|
||||
std::vector<std::string>& tess_control_shader_paths,
|
||||
std::vector<std::string>& tess_evaluation_shader_paths,
|
||||
std::vector<std::string>& fragment_shader_paths) {
|
||||
|
||||
if (task == 0) {
|
||||
vertex_shader_paths = {
|
||||
"/glsl/pass-through.vs"
|
||||
};
|
||||
|
||||
tess_control_shader_paths = {
|
||||
"/glsl/pass-through.tcs"
|
||||
};
|
||||
tess_evaluation_shader_paths = {
|
||||
"/glsl/interpolate.glsl",
|
||||
"/glsl/pass-through.tes"
|
||||
};
|
||||
fragment_shader_paths = {
|
||||
"/glsl/pass-through.fs"
|
||||
};
|
||||
}
|
||||
else if (task == 1) {
|
||||
vertex_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/src/1_model_view_projection.vs",
|
||||
};
|
||||
|
||||
tess_control_shader_paths = {
|
||||
"/glsl/pass-through.tcs",
|
||||
};
|
||||
tess_evaluation_shader_paths = {
|
||||
"/glsl/interpolate.glsl",
|
||||
"/glsl/pass-through.tes",
|
||||
};
|
||||
fragment_shader_paths = {
|
||||
"/src/1_blue_and_gray.fs",
|
||||
};
|
||||
}
|
||||
else if (task == 2) {
|
||||
vertex_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/src/1_model_view_projection.vs",
|
||||
};
|
||||
|
||||
tess_control_shader_paths = {
|
||||
"/src/2_tessellate_5.tcs",
|
||||
};
|
||||
tess_evaluation_shader_paths = {
|
||||
"/glsl/interpolate.glsl",
|
||||
"/glsl/pass-through.tes",
|
||||
};
|
||||
fragment_shader_paths = {
|
||||
"/src/1_blue_and_gray.fs",
|
||||
};
|
||||
}
|
||||
else if (task == 3) {
|
||||
vertex_shader_paths = {
|
||||
"/glsl/pass-through.vs"
|
||||
};
|
||||
|
||||
tess_control_shader_paths = {
|
||||
"/src/2_tessellate_5.tcs",
|
||||
};
|
||||
tess_evaluation_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/glsl/interpolate.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/src/3_snap_to_sphere.tes",
|
||||
};
|
||||
fragment_shader_paths = {
|
||||
"/src/1_blue_and_gray.fs",
|
||||
};
|
||||
}
|
||||
else if (task == 4) {
|
||||
vertex_shader_paths = {
|
||||
"/glsl/pass-through.vs"
|
||||
};
|
||||
|
||||
tess_control_shader_paths = {
|
||||
"/src/2_tessellate_5.tcs",
|
||||
};
|
||||
tess_evaluation_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/glsl/interpolate.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/src/3_snap_to_sphere.tes",
|
||||
};
|
||||
fragment_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/4_blinn_phong.glsl",
|
||||
"/src/4_lit.fs",
|
||||
};
|
||||
}
|
||||
else if (task == 5) {
|
||||
vertex_shader_paths = {
|
||||
"/glsl/pass-through.vs"
|
||||
};
|
||||
|
||||
tess_control_shader_paths = {
|
||||
"/src/2_tessellate_5.tcs",
|
||||
};
|
||||
tess_evaluation_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/glsl/interpolate.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/src/3_snap_to_sphere.tes",
|
||||
};
|
||||
fragment_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/glsl/random2.glsl",
|
||||
"/src/5_random_direction.glsl",
|
||||
"/src/5_smooth_step.glsl",
|
||||
"/src/5_perlin_noise.glsl",
|
||||
"/src/4_blinn_phong.glsl",
|
||||
"/src/5_procedural_color.fs",
|
||||
};
|
||||
}
|
||||
else if (task == 6) {
|
||||
vertex_shader_paths = {
|
||||
"/glsl/pass-through.vs"
|
||||
};
|
||||
|
||||
tess_control_shader_paths = {
|
||||
"/src/2_tessellate_5.tcs",
|
||||
};
|
||||
tess_evaluation_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/glsl/interpolate.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/src/3_snap_to_sphere.tes",
|
||||
};
|
||||
fragment_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/glsl/interpolate.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/glsl/random2.glsl",
|
||||
"/src/5_random_direction.glsl",
|
||||
"/src/5_smooth_step.glsl",
|
||||
"/src/5_perlin_noise.glsl",
|
||||
"/src/4_blinn_phong.glsl",
|
||||
"/glsl/smooth_heaviside.glsl",
|
||||
"/glsl/bump_height.glsl",
|
||||
"/src/6_bump_position.glsl",
|
||||
"/src/6_tangent.glsl",
|
||||
"/src/6_bump.fs",
|
||||
};
|
||||
}
|
||||
else if (task == 7) {
|
||||
vertex_shader_paths = {
|
||||
"/glsl/pass-through.vs"
|
||||
};
|
||||
|
||||
tess_control_shader_paths = {
|
||||
"/src/2_tessellate_5.tcs",
|
||||
};
|
||||
tess_evaluation_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/glsl/interpolate.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/src/3_snap_to_sphere.tes",
|
||||
};
|
||||
fragment_shader_paths = {
|
||||
"/glsl/PI.glsl",
|
||||
"/src/1_identity.glsl",
|
||||
"/src/1_uniform_scale.glsl",
|
||||
"/src/1_translate.glsl",
|
||||
"/src/1_rotate_about_y.glsl",
|
||||
"/glsl/interpolate.glsl",
|
||||
"/src/1_model.glsl",
|
||||
"/glsl/random2.glsl",
|
||||
"/src/5_random_direction.glsl",
|
||||
"/src/5_smooth_step.glsl",
|
||||
"/src/5_perlin_noise.glsl",
|
||||
"/src/4_blinn_phong.glsl",
|
||||
"/glsl/smooth_heaviside.glsl",
|
||||
"/glsl/bump_height.glsl",
|
||||
"/src/6_bump_position.glsl",
|
||||
"/src/6_tangent.glsl",
|
||||
"/src/7_planet.fs",
|
||||
};
|
||||
}
|
||||
|
||||
// Print to command line
|
||||
std::cout << "==== Used glsl files: ====" << std::endl;
|
||||
std::cout << " vertex:" << std::endl;
|
||||
for (auto& s : vertex_shader_paths) {
|
||||
std::cout << " " << s << std::endl;
|
||||
}
|
||||
std::cout << " tessellation control:" << std::endl;
|
||||
for (auto& s : tess_control_shader_paths) {
|
||||
std::cout << " " << s << std::endl;
|
||||
}
|
||||
std::cout << " tessellation evaluation:" << std::endl;
|
||||
for (auto& s : tess_evaluation_shader_paths) {
|
||||
std::cout << " " << s << std::endl;
|
||||
}
|
||||
std::cout << " fragment:" << std::endl;
|
||||
for (auto& s : fragment_shader_paths) {
|
||||
std::cout << " " << s << std::endl;
|
||||
}
|
||||
std::cout << "==========================" << std::endl;
|
||||
|
||||
// Add cmakelists_dir (from main.cpp)
|
||||
for (std::string& s : vertex_shader_paths) {
|
||||
s = cmakelists_dir + s;
|
||||
}
|
||||
for (std::string& s : tess_control_shader_paths) {
|
||||
s = cmakelists_dir + s;
|
||||
}
|
||||
for (std::string& s : tess_evaluation_shader_paths) {
|
||||
s = cmakelists_dir + s;
|
||||
}
|
||||
for (std::string& s : fragment_shader_paths) {
|
||||
s = cmakelists_dir + s;
|
||||
}
|
||||
|
||||
// Add "/glsl/version410.glsl" to the beginning of each vector
|
||||
vertex_shader_paths.insert(vertex_shader_paths.begin(), cmakelists_dir + "/glsl/version410.glsl");
|
||||
tess_control_shader_paths.insert(tess_control_shader_paths.begin(), cmakelists_dir + "/glsl/version410.glsl");
|
||||
tess_evaluation_shader_paths.insert(tess_evaluation_shader_paths.begin(), cmakelists_dir + "/glsl/version410.glsl");
|
||||
fragment_shader_paths.insert(fragment_shader_paths.begin(), cmakelists_dir + "/glsl/version410.glsl");
|
||||
|
||||
// Concatenate into one vector
|
||||
all_paths.insert(all_paths.end(), vertex_shader_paths.begin(), vertex_shader_paths.end());
|
||||
all_paths.insert(all_paths.end(), tess_control_shader_paths.begin(), tess_control_shader_paths.end());
|
||||
all_paths.insert(all_paths.end(), tess_evaluation_shader_paths.begin(), tess_evaluation_shader_paths.end());
|
||||
all_paths.insert(all_paths.end(), fragment_shader_paths.begin(), fragment_shader_paths.end());
|
||||
}
|
||||
|
||||
#endif
|
21
include/print_opengl_info.h
Normal file
21
include/print_opengl_info.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef PRINT_OPENGL_INFO_H
|
||||
#define PRINT_OPENGL_INFO_H
|
||||
|
||||
// Use glfw to print information about the current opengl context
|
||||
// Should be called after glfwMakeContextCurrent(...)
|
||||
void print_opengl_info(GLFWwindow * window);
|
||||
|
||||
// Implementation
|
||||
#include <cstdio>
|
||||
void print_opengl_info(GLFWwindow * window)
|
||||
{
|
||||
int major, minor, rev;
|
||||
major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
|
||||
minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
|
||||
rev = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
|
||||
printf("OpenGL version recieved: %d.%d.%d\n", major, minor, rev);
|
||||
printf("Supported OpenGL is %s\n", (const char*)glGetString(GL_VERSION));
|
||||
printf("Supported GLSL is %s\n", (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
}
|
||||
|
||||
#endif
|
36
include/print_program_info_log.h
Normal file
36
include/print_program_info_log.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef PRINT_PROGRAM_INFO_LOG_H
|
||||
#define PRINT_PROGRAM_INFO_LOG_H
|
||||
|
||||
#include <string>
|
||||
|
||||
// Print information about a given glsl shader program.
|
||||
//
|
||||
// Inputs:
|
||||
// obj id of object we're querying
|
||||
// Returns true if printed anything.
|
||||
bool print_program_info_log(const GLuint obj);
|
||||
|
||||
// Implementation
|
||||
#include "REDRUM.h"
|
||||
#include "STR.h"
|
||||
|
||||
bool print_program_info_log(const GLuint obj)
|
||||
{
|
||||
GLint infologLength = 0;
|
||||
GLint charsWritten = 0;
|
||||
|
||||
glGetProgramiv(obj, GL_INFO_LOG_LENGTH,&infologLength);
|
||||
|
||||
if (infologLength > 0)
|
||||
{
|
||||
char * infoLog = new char[infologLength];
|
||||
glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog);
|
||||
std::string log(infoLog);
|
||||
std::cerr<<log<<std::endl;
|
||||
delete[] infoLog;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
51
include/print_shader_info_log.h
Normal file
51
include/print_shader_info_log.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#ifndef PRINT_SHADER_INFO_LOG_H
|
||||
#define PRINT_SHADER_INFO_LOG_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Print information (e.g., compilation errors and warnings) about a give glsl
|
||||
// shader.
|
||||
//
|
||||
// Inputs:
|
||||
// type_str string identifying which kind of shader we're asking about (just
|
||||
// a prefix to print)
|
||||
// obj id of object we're querying
|
||||
// paths list of file paths containing corresponding shader source code
|
||||
// (assumings `#line ...` directive has been inserted between files).
|
||||
// Returns true if printed anything.
|
||||
bool print_shader_info_log(
|
||||
const std::string & type_str,
|
||||
const GLuint obj,
|
||||
const std::vector<std::string> & paths);
|
||||
|
||||
// Implementation
|
||||
#include "REDRUM.h"
|
||||
#include "STR.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool print_shader_info_log(
|
||||
const std::string & type_str,
|
||||
const GLuint obj,
|
||||
const std::vector<std::string> & paths)
|
||||
{
|
||||
GLint infologLength = 0;
|
||||
GLint charsWritten = 0;
|
||||
|
||||
glGetShaderiv(obj, GL_INFO_LOG_LENGTH,&infologLength);
|
||||
|
||||
if (infologLength > 0)
|
||||
{
|
||||
char * infoLog = new char[infologLength];
|
||||
std::cerr<<REDRUM("ERROR")<<": failed to compile "<<type_str<<std::endl;
|
||||
glGetShaderInfoLog(obj, infologLength, &charsWritten, infoLog);
|
||||
std::string log(infoLog);
|
||||
std::cerr<<log<<std::endl;
|
||||
delete[] infoLog;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
94
include/report_gl_error.h
Normal file
94
include/report_gl_error.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
// This file is part of libigl, a simple c++ geometry processing library.
|
||||
//
|
||||
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
// obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#ifndef IGL_OPENGL_REPORT_GL_ERROR_H
|
||||
#define IGL_OPENGL_REPORT_GL_ERROR_H
|
||||
#define IGL_INLINE inline
|
||||
|
||||
// Hack to allow both opengl/ and opengl2 to use this (we shouldn't allow this)
|
||||
#ifndef __gl_h_
|
||||
# include "gl.h"
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
namespace igl
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// Print last OpenGL error to stderr prefixed by specified id string
|
||||
// Inputs:
|
||||
// id string to appear before any error msgs
|
||||
// Returns result of glGetError()
|
||||
IGL_INLINE GLenum report_gl_error(const std::string id);
|
||||
// No prefix
|
||||
IGL_INLINE GLenum report_gl_error();
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation
|
||||
|
||||
// This file is part of libigl, a simple c++ geometry processing library.
|
||||
//
|
||||
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
// obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#include "report_gl_error.h"
|
||||
#include <cstdio>
|
||||
|
||||
IGL_INLINE GLenum igl::opengl::report_gl_error(const std::string id)
|
||||
{
|
||||
// http://stackoverflow.com/q/28485180/148668
|
||||
|
||||
// gluErrorString was deprecated
|
||||
const auto gluErrorString = [](GLenum errorCode)->const char *
|
||||
{
|
||||
switch(errorCode)
|
||||
{
|
||||
default:
|
||||
return "unknown error code";
|
||||
case GL_NO_ERROR:
|
||||
return "no error";
|
||||
case GL_INVALID_ENUM:
|
||||
return "invalid enumerant";
|
||||
case GL_INVALID_VALUE:
|
||||
return "invalid value";
|
||||
case GL_INVALID_OPERATION:
|
||||
return "invalid operation";
|
||||
#ifndef GL_VERSION_3_0
|
||||
case GL_STACK_OVERFLOW:
|
||||
return "stack overflow";
|
||||
case GL_STACK_UNDERFLOW:
|
||||
return "stack underflow";
|
||||
case GL_TABLE_TOO_LARGE:
|
||||
return "table too large";
|
||||
#endif
|
||||
case GL_OUT_OF_MEMORY:
|
||||
return "out of memory";
|
||||
#ifdef GL_EXT_framebuffer_object
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
|
||||
return "invalid framebuffer operation";
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
GLenum err = glGetError();
|
||||
if(GL_NO_ERROR != err)
|
||||
{
|
||||
fprintf(stderr,"GL_ERROR: %s%s\n",id.c_str(),gluErrorString(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
IGL_INLINE GLenum igl::opengl::report_gl_error()
|
||||
{
|
||||
return igl::opengl::report_gl_error(std::string(""));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Reference in a new issue