matus-chochlik / oglplus

OGLplus is a collection of open-source, cross-platform libraries which implement an object-oriented facade over the OpenGL® (version 3 and higher) and also OpenAL® (version 1.1) and EGL (version 1.4) C-language APIs. It provides wrappers which automate resource and object management and make the use of these libraries in C++ safer and more convenient.
http://oglplus.org/
Boost Software License 1.0
491 stars 72 forks source link

How to set uniform array of Vectors properly? #83

Closed Schneegans closed 9 years ago

Schneegans commented 9 years ago

Hey there! I stumbled upon an issue I failed to solve:

Let's make an example. Assume I want to set a uniform array of vec3's (vec3 colors[4];). For that purpose I create a suitable uniform and set it's value from a std::vector:

std::vector<oglplus::Vector<float, 3>> my_colors = {...};
oglplus::Uniform<oglplus::Vector<float, 3>> my_uniform(...);
my_uniform.Set(my_colors);

If done this way, this leads to a call of glUniform3fv(0, 12, ...) which tries to set too many values (12 should only be 4). I guess this is due to line https://github.com/matus-chochlik/oglplus/blob/develop/include/oglplus/uniform.hpp#L183 It works properly when this line is only SetValues(n, temp); but I'm not sure about any side effects.

So my question is: Is this way of setting arrays not intended? If so, is there another way? Thank you very much for your awesome work!

matus-chochlik commented 9 years ago

Hi,

Thanks for catching this one. Your method of setting the array of vec3 is correct. There was a bug but in the other overload of SetValue(n, v). I've fixed it in bffc6a0e3e4fb701dfa6d3df90168724e3cd4794 please let me know it it works for You.

Schneegans commented 9 years ago

Works like a charm! Thank you very much! Just one small issue with current develop: GL_CONTEXT_RELEASE_BEHAVIOR and glGetGraphicsResetStatus (used by https://github.com/matus-chochlik/oglplus/blob/develop/include/oglplus/context/numeric_queries.hpp) are not defined on my system (Ubuntu 14.04 with glew 1.10 and nvidia 331.38).

Again thank you for the quick fix!

matus-chochlik commented 9 years ago

This seems like a problem in GLEW (they sometimes define GL_VERSION_X_Y even when they don't define all required symbols). Would adding #ifdef GL_CONTEXT_RELEASE_BEHAVIOR and/or #ifdef GL_RESET_NOTIFICATION_STRATEGY around the affected functions help?

Schneegans commented 9 years ago

Adding #ifdef GL_CONTEXT_RELEASE_BEHAVIOR around

static ContextReleaseBehavior ReleaseBehavior(void)

and

static oglplus::ResetNotificationStrategy   ResetNotificationStrategy(void)

helps.

matus-chochlik commented 9 years ago

Ok, I've updated the GL version detection in the build system, so that it checks if (nearly) all required symbols for a particular GL version are available. If some are missing as in your case it #undefs the GL_VERSION_X_Y macro. The #undef directive is placed in the $(build_dir)/include/oglplus/config/fix_gl_version.hpp file so if you include that (after glew.h but before oglplus' headers) then things should work fine.

HTH