uniform map
This commit is contained in:
parent
50180bb999
commit
68b7276fd2
|
@ -47,7 +47,7 @@
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"json-save": true,
|
"json-save": true,
|
||||||
"json-save-directory": "local/scans",
|
"json-save-directory": "local/scans",
|
||||||
"barcode": "",
|
"barcode": "014100085980",
|
||||||
"capture-device": "/dev/video0"
|
"capture-device": "/dev/video0"
|
||||||
},
|
},
|
||||||
"api":
|
"api":
|
||||||
|
|
|
@ -223,13 +223,13 @@ void Pudding::load_gl_context()
|
||||||
/* store uniform locations after linking */
|
/* store uniform locations after linking */
|
||||||
uniform["flat"]["texture"] = glGetUniformLocation(flat_program, "base_texture");
|
uniform["flat"]["texture"] = glGetUniformLocation(flat_program, "base_texture");
|
||||||
uniform["flat"]["time"] = glGetUniformLocation(flat_program, "time");
|
uniform["flat"]["time"] = glGetUniformLocation(flat_program, "time");
|
||||||
scroll_uniform_location = glGetUniformLocation(flat_program, "scroll");
|
uniform["flat"]["scroll"] = glGetUniformLocation(flat_program, "scroll");
|
||||||
uniform["flat"]["blend"] = glGetUniformLocation(flat_program, "blend_min_hsv");
|
uniform["flat"]["blend"] = glGetUniformLocation(flat_program, "blend_min_hsv");
|
||||||
mvp_uniform_location = glGetUniformLocation(mvp_program, "mvp");
|
uniform["mvp"]["mvp"] = glGetUniformLocation(mvp_program, "mvp");
|
||||||
time_uniform_location = glGetUniformLocation(mvp_program, "time");
|
uniform["mvp"]["time"] = glGetUniformLocation(mvp_program, "time");
|
||||||
effect_uniform_location = glGetUniformLocation(mvp_program, "effect");
|
uniform["mvp"]["effect"] = glGetUniformLocation(mvp_program, "effect");
|
||||||
uv_transformation_uniform_location = glGetUniformLocation(mvp_program, "uv_transformation");
|
uniform["mvp"]["uv transformation"] = glGetUniformLocation(mvp_program, "uv_transformation");
|
||||||
coordinate_bound_uniform_location = glGetUniformLocation(mvp_program, "coordinate_bound");
|
uniform["mvp"]["coordinate bound"] = glGetUniformLocation(mvp_program, "coordinate_bound");
|
||||||
uniform["mvp"]["pudding texture"] = glGetUniformLocation(mvp_program, "pudding_texture");
|
uniform["mvp"]["pudding texture"] = glGetUniformLocation(mvp_program, "pudding_texture");
|
||||||
sb::Log::gl_errors("after uniform locations");
|
sb::Log::gl_errors("after uniform locations");
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,10 @@ void Pudding::respond(SDL_Event& event)
|
||||||
}
|
}
|
||||||
else if (get_delegate().compare(event, "right"))
|
else if (get_delegate().compare(event, "right"))
|
||||||
{
|
{
|
||||||
get_current_item().increment_image_index();
|
if (items.size() > 0)
|
||||||
|
{
|
||||||
|
current_item().increment_image_index();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (get_delegate().compare(event, "down"))
|
else if (get_delegate().compare(event, "down"))
|
||||||
{
|
{
|
||||||
|
@ -291,7 +294,10 @@ void Pudding::respond(SDL_Event& event)
|
||||||
}
|
}
|
||||||
else if (get_delegate().compare(event, "left"))
|
else if (get_delegate().compare(event, "left"))
|
||||||
{
|
{
|
||||||
get_current_item().increment_image_index(-1);
|
if (items.size() > 0)
|
||||||
|
{
|
||||||
|
current_item().increment_image_index(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (get_delegate().compare(event, "toggle-camera"))
|
else if (get_delegate().compare(event, "toggle-camera"))
|
||||||
{
|
{
|
||||||
|
@ -313,7 +319,7 @@ void Pudding::respond(SDL_Event& event)
|
||||||
{
|
{
|
||||||
effect_id = ++effect_id % EFFECT_COUNT;
|
effect_id = ++effect_id % EFFECT_COUNT;
|
||||||
glUseProgram(mvp_program);
|
glUseProgram(mvp_program);
|
||||||
glUniform1i(effect_uniform_location, effect_id);
|
glUniform1i(uniform["mvp"]["effect"], effect_id);
|
||||||
}
|
}
|
||||||
else if (get_delegate().compare(event, "tile"))
|
else if (get_delegate().compare(event, "tile"))
|
||||||
{
|
{
|
||||||
|
@ -636,9 +642,19 @@ void Pudding::increment_item_index(int increment)
|
||||||
current_item_index = sb::mod(current_item_index + increment, static_cast<int>(items.size()));
|
current_item_index = sb::mod(current_item_index + increment, static_cast<int>(items.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Item& Pudding::get_current_item()
|
/* Return the item currently selected in the inventory */
|
||||||
|
Item& Pudding::current_item()
|
||||||
{
|
{
|
||||||
return items[current_item_index];
|
try
|
||||||
|
{
|
||||||
|
return items.at(current_item_index);
|
||||||
|
}
|
||||||
|
catch (const std::out_of_range& exception)
|
||||||
|
{
|
||||||
|
std::ostringstream message;
|
||||||
|
message << "Out of range exception: " << exception.what() << " (Attempting to retrieve an item from empty inventory)";
|
||||||
|
sb::Log::log(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns true if item display is toggled on and there is at least one item to display */
|
/* Returns true if item display is toggled on and there is at least one item to display */
|
||||||
|
@ -757,20 +773,20 @@ void Pudding::update()
|
||||||
tiles[current_tile_index].bind();
|
tiles[current_tile_index].bind();
|
||||||
/* set blend to modify white part of background, color passed is in HSV format */
|
/* set blend to modify white part of background, color passed is in HSV format */
|
||||||
glUniform3f(uniform["flat"]["blend"], 0.0f, 0.0f, 1.0f);
|
glUniform3f(uniform["flat"]["blend"], 0.0f, 0.0f, 1.0f);
|
||||||
glUniform1i(scroll_uniform_location, true);
|
glUniform1i(uniform["flat"]["scroll"], true);
|
||||||
/* draws rectangle vertices and rectangle texture using UV coords */
|
/* draws rectangle vertices and rectangle texture using UV coords */
|
||||||
glDrawArrays(GL_TRIANGLES, 0, rectangle_attributes["position"].count());
|
glDrawArrays(GL_TRIANGLES, 0, rectangle_attributes["position"].count());
|
||||||
glUniform1i(scroll_uniform_location, false);
|
glUniform1i(uniform["flat"]["scroll"], false);
|
||||||
/* draw pudding model using MVP shader */
|
/* draw pudding model using MVP shader */
|
||||||
glUseProgram(mvp_program);
|
glUseProgram(mvp_program);
|
||||||
glUniform1f(time_uniform_location, time_seconds);
|
glUniform1f(uniform["mvp"]["time"], time_seconds);
|
||||||
/* calculate the transformation matrix for displaying pudding in viewport */
|
/* calculate the transformation matrix for displaying pudding in viewport */
|
||||||
model = glm::rotate(model, weight(get_configuration()["pudding"]["rotation-speed"].get<float>()), Y_UNIT_NORMAL_3D);
|
model = glm::rotate(model, weight(get_configuration()["pudding"]["rotation-speed"].get<float>()), Y_UNIT_NORMAL_3D);
|
||||||
projection = glm::perspective(
|
projection = glm::perspective(
|
||||||
glm::radians(40.0f * 1 / viewport_box.aspect()), viewport_box.aspect(), 0.1f, 100.0f);
|
glm::radians(40.0f * 1 / viewport_box.aspect()), viewport_box.aspect(), 0.1f, 100.0f);
|
||||||
mvp = projection * VIEW_MATRIX * model;
|
mvp = projection * VIEW_MATRIX * model;
|
||||||
/* pass the mvp matrix to the shader */
|
/* pass the mvp matrix to the shader */
|
||||||
glUniformMatrix4fv(mvp_uniform_location, 1, GL_FALSE, &mvp[0][0]);
|
glUniformMatrix4fv(uniform["mvp"]["mvp"], 1, GL_FALSE, &mvp[0][0]);
|
||||||
/* disable rectangle attributes and enable pudding attributes */
|
/* disable rectangle attributes and enable pudding attributes */
|
||||||
glDisableVertexAttribArray(rectangle_attributes["position"]);
|
glDisableVertexAttribArray(rectangle_attributes["position"]);
|
||||||
glDisableVertexAttribArray(rectangle_attributes["color"]);
|
glDisableVertexAttribArray(rectangle_attributes["color"]);
|
||||||
|
@ -787,20 +803,20 @@ void Pudding::update()
|
||||||
glEnableVertexAttribArray(pudding_attributes["uv"]);
|
glEnableVertexAttribArray(pudding_attributes["uv"]);
|
||||||
glUniform1i(uniform["mvp"]["pudding texture"], 0);
|
glUniform1i(uniform["mvp"]["pudding texture"], 0);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
get_current_item().get_active_image_texture().bind();
|
current_item().get_active_image_texture().bind();
|
||||||
}
|
}
|
||||||
/* draw pudding model */
|
/* draw pudding model */
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
/* draw the sides of the pudding */
|
/* draw the sides of the pudding */
|
||||||
glDrawArrays(GL_TRIANGLES, 0, pudding_triangle_vertex_count);
|
glDrawArrays(GL_TRIANGLES, 0, pudding_triangle_vertex_count);
|
||||||
/* enable squircling and draw the top and bottom of pudding */
|
/* enable squircling and draw the top and bottom of pudding */
|
||||||
glUniform1i(uv_transformation_uniform_location, UV_SQUIRCLE);
|
glUniform1i(uniform["mvp"]["uv transformation"], UV_SQUIRCLE);
|
||||||
glUniform1f(coordinate_bound_uniform_location, get_configuration()["pudding"]["top-radius"]);
|
glUniform1f(uniform["mvp"]["coordinate bound"], get_configuration()["pudding"]["top-radius"]);
|
||||||
glDrawArrays(GL_TRIANGLE_FAN, pudding_triangle_vertex_count, pudding_fan_vertex_count);
|
glDrawArrays(GL_TRIANGLE_FAN, pudding_triangle_vertex_count, pudding_fan_vertex_count);
|
||||||
glUniform1f(coordinate_bound_uniform_location, get_configuration()["pudding"]["base-radius"]);
|
glUniform1f(uniform["mvp"]["coordinate bound"], get_configuration()["pudding"]["base-radius"]);
|
||||||
glDrawArrays(GL_TRIANGLE_FAN, pudding_triangle_vertex_count + pudding_fan_vertex_count, pudding_fan_vertex_count);
|
glDrawArrays(GL_TRIANGLE_FAN, pudding_triangle_vertex_count + pudding_fan_vertex_count, pudding_fan_vertex_count);
|
||||||
/* disable squircling for all other drawing */
|
/* disable squircling for all other drawing */
|
||||||
glUniform1i(uv_transformation_uniform_location, UV_NONE);
|
glUniform1i(uniform["mvp"]["uv transformation"], UV_NONE);
|
||||||
/* regular fill mode enabled for all other drawing */
|
/* regular fill mode enabled for all other drawing */
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
/* only do more drawing if items are downloaded or camera is enabled */
|
/* only do more drawing if items are downloaded or camera is enabled */
|
||||||
|
@ -832,7 +848,7 @@ void Pudding::update()
|
||||||
viewport_box.left(viewport_box.cx(), true);
|
viewport_box.left(viewport_box.cx(), true);
|
||||||
}
|
}
|
||||||
glViewport(viewport_box.left(), viewport_box.bottom(), viewport_box.width(), viewport_box.height());
|
glViewport(viewport_box.left(), viewport_box.bottom(), viewport_box.width(), viewport_box.height());
|
||||||
get_current_item().get_active_image_texture().bind();
|
current_item().get_active_image_texture().bind();
|
||||||
/* draws rectangle vertices and rectangle texture using UV coords */
|
/* draws rectangle vertices and rectangle texture using UV coords */
|
||||||
glDrawArrays(GL_TRIANGLES, 0, rectangle_attributes["position"].count());
|
glDrawArrays(GL_TRIANGLES, 0, rectangle_attributes["position"].count());
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,15 +82,9 @@ private:
|
||||||
cv::VideoCapture capture;
|
cv::VideoCapture capture;
|
||||||
zbar::ImageScanner image_scanner;
|
zbar::ImageScanner image_scanner;
|
||||||
std::map<std::string, std::map<std::string, GLuint>> uniform;
|
std::map<std::string, std::map<std::string, GLuint>> uniform;
|
||||||
GLuint flat_program, mvp_program, mvp_uniform_location, time_uniform_location, effect_uniform_location,
|
GLuint flat_program, mvp_program;
|
||||||
uv_transformation_uniform_location, coordinate_bound_uniform_location,
|
|
||||||
scroll_uniform_location;
|
|
||||||
glm::mat4 projection, model = glm::mat4(1.0f), mvp;
|
glm::mat4 projection, model = glm::mat4(1.0f), mvp;
|
||||||
std::map<std::string, sb::Attributes> rectangle_attributes, pudding_attributes = {
|
std::map<std::string, sb::Attributes> rectangle_attributes, pudding_attributes;
|
||||||
{"position", sb::Attributes()},
|
|
||||||
{"uv", sb::Attributes()},
|
|
||||||
{"color", sb::Attributes()}
|
|
||||||
};
|
|
||||||
bool show_item = false, reading_capture_frame = false;
|
bool show_item = false, reading_capture_frame = false;
|
||||||
SDL_GLContext capture_frame_thread_context = nullptr;
|
SDL_GLContext capture_frame_thread_context = nullptr;
|
||||||
std::vector<sb::Texture> tiles;
|
std::vector<sb::Texture> tiles;
|
||||||
|
@ -122,7 +116,7 @@ public:
|
||||||
void respond(SDL_Event&);
|
void respond(SDL_Event&);
|
||||||
void add_item(const std::string&);
|
void add_item(const std::string&);
|
||||||
void increment_item_index(int = 1);
|
void increment_item_index(int = 1);
|
||||||
Item& get_current_item();
|
Item& current_item();
|
||||||
void update();
|
void update();
|
||||||
virtual std::string class_name() const { return "Pudding"; }
|
virtual std::string class_name() const { return "Pudding"; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue