Skip to content

changed minimal opengl version to 3.1 #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/protonect/src/flextGL.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ int flextInit(GLFWwindow* window, OpenGLBindings *bindings)

/* --- Check for minimal version and profile --- */

if (major * 10 + minor < 33) {
fprintf(stderr, "Error: OpenGL version 3.3 not supported.\n");
if (major * 10 + minor < 31) {
fprintf(stderr, "Error: OpenGL version 3.1 not supported.\n");
fprintf(stderr, " Your version is %d.%d.\n", major, minor);
fprintf(stderr, " Try updating your graphics driver.\n");
return GL_FALSE;
Expand Down Expand Up @@ -306,7 +306,7 @@ void flextLoadOpenGLFunctions(OpenGLBindings *bindings)
bindings->glUniformBlockBinding = (PFNGLUNIFORMBLOCKBINDING_PROC*)glfwGetProcAddress("glUniformBlockBinding");

/* GL_VERSION_3_2 */

/*
bindings->glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEX_PROC*)glfwGetProcAddress("glDrawElementsBaseVertex");
bindings->glDrawRangeElementsBaseVertex = (PFNGLDRAWRANGEELEMENTSBASEVERTEX_PROC*)glfwGetProcAddress("glDrawRangeElementsBaseVertex");
bindings->glDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEX_PROC*)glfwGetProcAddress("glDrawElementsInstancedBaseVertex");
Expand All @@ -326,9 +326,9 @@ void flextLoadOpenGLFunctions(OpenGLBindings *bindings)
bindings->glTexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLE_PROC*)glfwGetProcAddress("glTexImage3DMultisample");
bindings->glGetMultisamplefv = (PFNGLGETMULTISAMPLEFV_PROC*)glfwGetProcAddress("glGetMultisamplefv");
bindings->glSampleMaski = (PFNGLSAMPLEMASKI_PROC*)glfwGetProcAddress("glSampleMaski");

*/
/* GL_VERSION_3_3 */

/*
bindings->glBindFragDataLocationIndexed = (PFNGLBINDFRAGDATALOCATIONINDEXED_PROC*)glfwGetProcAddress("glBindFragDataLocationIndexed");
bindings->glGetFragDataIndex = (PFNGLGETFRAGDATAINDEX_PROC*)glfwGetProcAddress("glGetFragDataIndex");
bindings->glGenSamplers = (PFNGLGENSAMPLERS_PROC*)glfwGetProcAddress("glGenSamplers");
Expand Down Expand Up @@ -357,7 +357,7 @@ void flextLoadOpenGLFunctions(OpenGLBindings *bindings)
bindings->glVertexAttribP3uiv = (PFNGLVERTEXATTRIBP3UIV_PROC*)glfwGetProcAddress("glVertexAttribP3uiv");
bindings->glVertexAttribP4ui = (PFNGLVERTEXATTRIBP4UI_PROC*)glfwGetProcAddress("glVertexAttribP4ui");
bindings->glVertexAttribP4uiv = (PFNGLVERTEXATTRIBP4UIV_PROC*)glfwGetProcAddress("glVertexAttribP4uiv");

*/
}

/* ----------------------- Extension flag definitions ---------------------- */
Expand Down
23 changes: 12 additions & 11 deletions examples/protonect/src/flextGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ typedef struct __GLsync *GLsync;
#define GL_INVALID_INDEX 0xFFFFFFFFu

/* GL_VERSION_3_2 */

/*
#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
#define GL_LINES_ADJACENCY 0x000A
Expand Down Expand Up @@ -906,9 +906,9 @@ typedef struct __GLsync *GLsync;
#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E
#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F
#define GL_MAX_INTEGER_SAMPLES 0x9110

*/
/* GL_VERSION_3_3 */

/*
#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE
#define GL_SRC1_COLOR 0x88F9
#define GL_ONE_MINUS_SRC1_COLOR 0x88FA
Expand All @@ -925,7 +925,7 @@ typedef struct __GLsync *GLsync;
#define GL_TIME_ELAPSED 0x88BF
#define GL_TIMESTAMP 0x8E28
#define GL_INT_2_10_10_10_REV 0x8D9F

*/
/* --------------------------- FUNCTION PROTOTYPES --------------------------- */


Expand Down Expand Up @@ -1258,7 +1258,7 @@ typedef void (APIENTRY PFNGLGETACTIVEUNIFORMBLOCKNAME_PROC (GLuint program, GLui
typedef void (APIENTRY PFNGLUNIFORMBLOCKBINDING_PROC (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding));

/* GL_VERSION_3_2 */
/*
typedef void (APIENTRY PFNGLDRAWELEMENTSBASEVERTEX_PROC (GLenum mode, GLsizei count, GLenum type, const void * indices, GLint basevertex));
typedef void (APIENTRY PFNGLDRAWRANGEELEMENTSBASEVERTEX_PROC (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void * indices, GLint basevertex));
typedef void (APIENTRY PFNGLDRAWELEMENTSINSTANCEDBASEVERTEX_PROC (GLenum mode, GLsizei count, GLenum type, const void * indices, GLsizei instancecount, GLint basevertex));
Expand All @@ -1278,9 +1278,9 @@ typedef void (APIENTRY PFNGLTEXIMAGE2DMULTISAMPLE_PROC (GLenum target, GLsizei s
typedef void (APIENTRY PFNGLTEXIMAGE3DMULTISAMPLE_PROC (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations));
typedef void (APIENTRY PFNGLGETMULTISAMPLEFV_PROC (GLenum pname, GLuint index, GLfloat * val));
typedef void (APIENTRY PFNGLSAMPLEMASKI_PROC (GLuint maskNumber, GLbitfield mask));
*/
/* GL_VERSION_3_3 */
/*
typedef void (APIENTRY PFNGLBINDFRAGDATALOCATIONINDEXED_PROC (GLuint program, GLuint colorNumber, GLuint index, const GLchar * name));
typedef GLint (APIENTRY PFNGLGETFRAGDATAINDEX_PROC (GLuint program, const GLchar * name));
typedef void (APIENTRY PFNGLGENSAMPLERS_PROC (GLsizei count, GLuint * samplers));
Expand Down Expand Up @@ -1309,7 +1309,7 @@ typedef void (APIENTRY PFNGLVERTEXATTRIBP3UI_PROC (GLuint index, GLenum type, GL
typedef void (APIENTRY PFNGLVERTEXATTRIBP3UIV_PROC (GLuint index, GLenum type, GLboolean normalized, const GLuint * value));
typedef void (APIENTRY PFNGLVERTEXATTRIBP4UI_PROC (GLuint index, GLenum type, GLboolean normalized, GLuint value));
typedef void (APIENTRY PFNGLVERTEXATTRIBP4UIV_PROC (GLuint index, GLenum type, GLboolean normalized, const GLuint * value));
*/
struct OpenGLBindings
{

Expand Down Expand Up @@ -1574,7 +1574,7 @@ struct OpenGLBindings
PFNGLUNIFORMBLOCKBINDING_PROC* glUniformBlockBinding;

/* GL_VERSION_3_2 */

/*
PFNGLDRAWELEMENTSBASEVERTEX_PROC* glDrawElementsBaseVertex;
PFNGLDRAWRANGEELEMENTSBASEVERTEX_PROC* glDrawRangeElementsBaseVertex;
PFNGLDRAWELEMENTSINSTANCEDBASEVERTEX_PROC* glDrawElementsInstancedBaseVertex;
Expand All @@ -1594,9 +1594,9 @@ struct OpenGLBindings
PFNGLTEXIMAGE3DMULTISAMPLE_PROC* glTexImage3DMultisample;
PFNGLGETMULTISAMPLEFV_PROC* glGetMultisamplefv;
PFNGLSAMPLEMASKI_PROC* glSampleMaski;
*/
/* GL_VERSION_3_3 */

/*
PFNGLBINDFRAGDATALOCATIONINDEXED_PROC* glBindFragDataLocationIndexed;
PFNGLGETFRAGDATAINDEX_PROC* glGetFragDataIndex;
PFNGLGENSAMPLERS_PROC* glGenSamplers;
Expand Down Expand Up @@ -1625,6 +1625,7 @@ struct OpenGLBindings
PFNGLVERTEXATTRIBP3UIV_PROC* glVertexAttribP3uiv;
PFNGLVERTEXATTRIBP4UI_PROC* glVertexAttribP4ui;
PFNGLVERTEXATTRIBP4UIV_PROC* glVertexAttribP4uiv;
*/
};

typedef struct OpenGLBindings OpenGLBindings;
Expand Down
44 changes: 36 additions & 8 deletions examples/protonect/src/opengl_depth_packet_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

#include <iostream>
#include <fstream>

#include <string>
#include <map>

#include <stdint.h>

Expand Down Expand Up @@ -117,6 +118,8 @@ bool loadBufferFromFile(const std::string& filename, unsigned char *buffer, size

struct ShaderProgram : public WithOpenGLBindings
{
typedef std::map<std::string, int> FragDataMap;
FragDataMap frag_data_map_;
GLuint program, vertex_shader, fragment_shader;

char error_buffer[2048];
Expand Down Expand Up @@ -144,6 +147,11 @@ struct ShaderProgram : public WithOpenGLBindings
gl()->glShaderSource(fragment_shader, 1, &src_, &length_);
}

void bindFragDataLocation(const std::string &name, int output)
{
frag_data_map_[name] = output;
}

void build()
{
GLint status;
Expand Down Expand Up @@ -174,6 +182,11 @@ struct ShaderProgram : public WithOpenGLBindings
gl()->glAttachShader(program, vertex_shader);
gl()->glAttachShader(program, fragment_shader);

for(FragDataMap::iterator it = frag_data_map_.begin(); it != frag_data_map_.end(); ++it)
{
gl()->glBindFragDataLocation(program, it->second, it->first.c_str());
}

gl()->glLinkProgram(program);

gl()->glGetProgramiv(program, GL_LINK_STATUS, &status);
Expand Down Expand Up @@ -471,7 +484,7 @@ struct OpenGLDepthPacketProcessorImpl : public WithOpenGLBindings
OpenGLBindings *b = new OpenGLBindings();
if (flextInit(opengl_context_ptr, b) == 0)
{
std::cerr << "[OpenGLDepthPacketProcessor] Failed to initialize flextGL.";
std::cerr << "[OpenGLDepthPacketProcessor] Failed to initialize flextGL!"<<std::endl;
exit(-1);
}
gl(b);
Expand Down Expand Up @@ -499,24 +512,39 @@ struct OpenGLDepthPacketProcessorImpl : public WithOpenGLBindings

stage1.setVertexShader(loadShaderSource(shader_folder + "default.vs"));
stage1.setFragmentShader(loadShaderSource(shader_folder + "stage1.fs"));
stage1.bindFragDataLocation("Debug", 0);
stage1.bindFragDataLocation("A", 1);
stage1.bindFragDataLocation("B", 2);
stage1.bindFragDataLocation("Norm", 3);
stage1.bindFragDataLocation("Infrared", 4);
stage1.build();

filter1.setVertexShader(loadShaderSource(shader_folder + "default.vs"));
filter1.setFragmentShader(loadShaderSource(shader_folder + "filter1.fs"));
filter1.bindFragDataLocation("Debug", 0);
filter1.bindFragDataLocation("FilterA", 1);
filter1.bindFragDataLocation("FilterB", 2);
filter1.bindFragDataLocation("MaxEdgeTest", 3);
filter1.build();

stage2.setVertexShader(loadShaderSource(shader_folder + "default.vs"));
stage2.setFragmentShader(loadShaderSource(shader_folder + "stage2.fs"));
stage2.bindFragDataLocation("Debug", 0);
stage2.bindFragDataLocation("Depth", 1);
stage2.bindFragDataLocation("DepthAndIrSum", 2);
stage2.build();

filter2.setVertexShader(loadShaderSource(shader_folder + "default.vs"));
filter2.setFragmentShader(loadShaderSource(shader_folder + "filter2.fs"));
filter2.bindFragDataLocation("Debug", 0);
filter2.bindFragDataLocation("FilterDepth", 1);
filter2.build();

if(do_debug)
{
debug.setVertexShader(loadShaderSource(shader_folder + "default.vs"));
debug.setFragmentShader(loadShaderSource(shader_folder + "debug.fs"));
debug.bindFragDataLocation("Debug", 0);
debug.build();
}

Expand Down Expand Up @@ -575,11 +603,11 @@ struct OpenGLDepthPacketProcessorImpl : public WithOpenGLBindings
gl()->glBindBuffer(GL_ARRAY_BUFFER, square_vbo);
gl()->glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

GLint position_attr = stage1.getAttributeLocation("Position");
GLint position_attr = stage1.getAttributeLocation("InputPosition");
gl()->glVertexAttribPointer(position_attr, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)0);
gl()->glEnableVertexAttribArray(position_attr);

GLint texcoord_attr = stage1.getAttributeLocation("TexCoord");
GLint texcoord_attr = stage1.getAttributeLocation("InputTexCoord");
gl()->glVertexAttribPointer(texcoord_attr, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(2 * sizeof(float)));
gl()->glEnableVertexAttribArray(texcoord_attr);
}
Expand Down Expand Up @@ -774,25 +802,25 @@ OpenGLDepthPacketProcessor::OpenGLDepthPacketProcessor(void *parent_opengl_conte
// init glfw - if already initialized nothing happens
if (glfwInit() == GL_FALSE)
{
std::cerr << "[OpenGLDepthPacketProcessor] Failed to initialize GLFW.";
std::cerr << "[OpenGLDepthPacketProcessor] Failed to initialize GLFW." << std::endl;
exit(-1);
}

// setup context
glfwDefaultWindowHints();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
glfwWindowHint(GLFW_VISIBLE, debug ? GL_TRUE : GL_FALSE);

GLFWwindow* window = glfwCreateWindow(1024, 848, "OpenGLDepthPacketProcessor", 0, parent_window);

if (window == NULL)
{
std::cerr << "[OpenGLDepthPacketProcessor] Failed to create opengl window.";
std::cerr << "[OpenGLDepthPacketProcessor] Failed to create opengl window." << std::endl;
exit(-1);
}

Expand Down
10 changes: 4 additions & 6 deletions examples/protonect/src/shader/debug.fs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#version 330
#version 140

uniform sampler2DRect Data;

in VertexData {
vec2 TexCoord;
} FragmentIn;
in vec2 TexCoord;

layout(location = 0) out vec4 Color;
out vec4 Color;

void main(void)
{
ivec2 uv = ivec2(FragmentIn.TexCoord.x, FragmentIn.TexCoord.y);
ivec2 uv = ivec2(TexCoord.x, TexCoord.y);

Color = texelFetch(Data, uv);
}
14 changes: 6 additions & 8 deletions examples/protonect/src/shader/default.vs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#version 330
#version 140

in vec2 Position;
in vec2 TexCoord;
in vec2 InputPosition;
in vec2 InputTexCoord;

out VertexData {
vec2 TexCoord;
} VertexOut;
out vec2 TexCoord;

void main(void)
{
gl_Position = vec4(Position, 0.0, 1.0);
VertexOut.TexCoord = TexCoord;
gl_Position = vec4(InputPosition, 0.0, 1.0);
TexCoord = InputTexCoord;
}
16 changes: 7 additions & 9 deletions examples/protonect/src/shader/filter1.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 330
#version 140

struct Parameters
{
Expand Down Expand Up @@ -40,14 +40,12 @@ uniform sampler2DRect Norm;

uniform Parameters Params;

in VertexData {
vec2 TexCoord;
} FragmentIn;
in vec2 TexCoord;

layout(location = 0) out vec4 Debug;
layout(location = 1) out vec3 FilterA;
layout(location = 2) out vec3 FilterB;
layout(location = 3) out uint MaxEdgeTest;
/*layout(location = 0)*/ out vec4 Debug;
/*layout(location = 1)*/ out vec3 FilterA;
/*layout(location = 2)*/ out vec3 FilterB;
/*layout(location = 3)*/ out uint MaxEdgeTest;

void applyBilateralFilter(ivec2 uv)
{
Expand Down Expand Up @@ -115,7 +113,7 @@ void applyBilateralFilter(ivec2 uv)

void main(void)
{
ivec2 uv = ivec2(FragmentIn.TexCoord.x, FragmentIn.TexCoord.y);
ivec2 uv = ivec2(TexCoord.x, TexCoord.y);

applyBilateralFilter(uv);

Expand Down
12 changes: 5 additions & 7 deletions examples/protonect/src/shader/filter2.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 330
#version 140

struct Parameters
{
Expand Down Expand Up @@ -39,12 +39,10 @@ uniform usampler2DRect MaxEdgeTest;

uniform Parameters Params;

in VertexData {
vec2 TexCoord;
} FragmentIn;
in vec2 TexCoord;

layout(location = 0) out vec4 Debug;
layout(location = 1) out float FilterDepth;
/*layout(location = 0)*/ out vec4 Debug;
/*layout(location = 1)*/ out float FilterDepth;

void applyEdgeAwareFilter(ivec2 uv)
{
Expand Down Expand Up @@ -126,7 +124,7 @@ void applyEdgeAwareFilter(ivec2 uv)

void main(void)
{
ivec2 uv = ivec2(FragmentIn.TexCoord.x, FragmentIn.TexCoord.y);
ivec2 uv = ivec2(TexCoord.x, TexCoord.y);

applyEdgeAwareFilter(uv);

Expand Down
Loading