diff --git a/data/images/tiles.strf b/data/images/tiles.strf index 2c92e3fe5a..4ec4ac5eb1 100644 --- a/data/images/tiles.strf +++ b/data/images/tiles.strf @@ -2416,6 +2416,7 @@ (id 75) (images "tiles/water/deprecated/water.png") (water #t) + (shaded #t) (deprecated #t) ) @@ -2427,6 +2428,7 @@ "tiles/water/deprecated/waves-2.png" ) (water #t) + (shaded #t) (fps 10) (deprecated #t) ) @@ -2957,11 +2959,11 @@ 175 176 177 178 ) (attributes - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 ) (images "tiles/waterfall/trans-0.png" @@ -2985,10 +2987,11 @@ "tiles/waterfall/foam-3.png" ) (attributes - 512 0 512 - 512 512 512 + 516 0 516 + 516 516 516 ) (water #t) + (shaded #t) (fps 10) ) @@ -2996,6 +2999,7 @@ (id 200) (images "tiles/water/deprecated/water-trans.png") (water #t) + (shaded #t) (deprecated #t) ) @@ -3007,6 +3011,7 @@ "tiles/water/deprecated/waves-trans-2.png" ) (water #t) + (shaded #t) (fps 10) (deprecated #t) ) @@ -3047,11 +3052,11 @@ 275 276 277 278 ) (attributes - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 - 512 512 512 512 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 + 516 516 516 516 ) (images "tiles/waterfall/deprecated/waterfall-0.png" @@ -4896,25 +4901,17 @@ 2019 2140 2141 2142 ) (attributes - 512 512 512 512 + 516 516 516 516 ) (images - (surface (diffuse-texture (file "tiles/water/antarctic-1.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-2.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-3.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-4.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-5.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-6.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-7.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) - (surface (diffuse-texture (file "tiles/water/antarctic-8.png")) - (displacement-texture (file "tiles/water/antarctic-displacement.png"))) + "tiles/water/antarctic-1.png" + "tiles/water/antarctic-2.png" + "tiles/water/antarctic-3.png" + "tiles/water/antarctic-4.png" + "tiles/water/antarctic-5.png" + "tiles/water/antarctic-6.png" + "tiles/water/antarctic-7.png" + "tiles/water/antarctic-8.png" ) (fps 16) ) @@ -4924,6 +4921,7 @@ (images "tiles/water/antarctic.png") (water #t) + (shaded #t) ) (tiles diff --git a/data/shader/shader330.frag b/data/shader/shader330.frag index 291be7547c..819d2dc178 100644 --- a/data/shader/shader330.frag +++ b/data/shader/shader330.frag @@ -12,17 +12,26 @@ uniform bool is_displacement; in vec4 diffuse_var; in vec2 texcoord_var; +flat in uint attrs_var; out vec4 fragColor; +const uint TATTR_SOLID = 0x0001u; +const uint TATTR_UNISOLID = 0x0002u; +const uint TATTR_SHADED = 0x0004u; +const uint TATTR_SLOPE = 0x0010u; +const uint TATTR_FIF = 0x0100u; +const uint TATTR_ICE = 0x0100u; +const uint TATTR_WATER = 0x0200u; +const uint TATTR_HURTS = 0x0400u; +const uint TATTR_FIRE = 0x0800u; +const uint TATTR_WALLJUMP = 0x1000u; + void main(void) { - if (backbuffer == 0.0 || !is_displacement) - { - vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); - fragColor = color; - } - else if (is_displacement) + vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); + + if (is_displacement) { vec4 pixel = texture(displacement_texture, texcoord_var.st + (displacement_animate * game_time)); vec2 displacement = (pixel.rg - vec2(0.5, 0.5)) * 255; @@ -32,8 +41,27 @@ void main(void) uv = vec2(uv.x, 1.0 - uv.y); vec4 back_color = texture(framebuffer_texture, uv); - vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); - fragColor = vec4(mix(color.rgb, back_color.rgb, alpha), color.a); + vec4 newcolor = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time)); + color = vec4(mix(newcolor.rgb, back_color.rgb, alpha), newcolor.a); + } + + if ((attrs_var & TATTR_SHADED) == TATTR_SHADED && + (attrs_var & TATTR_WATER) == TATTR_WATER && + (attrs_var & TATTR_FIRE) != TATTR_FIRE) // Water (not lava) + { + vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy; + uv.x = uv.x + 0.0006 * (sin(game_time + uv.y * (80)) + cos(game_time + uv.y * 30)); + uv.y = 1.0 - uv.y + 0.003 * (cos(game_time + uv.y * 140)); + vec4 back_color = texture(framebuffer_texture, uv); + + if (backbuffer == 0.0) + fragColor = color; + else + fragColor = vec4(max(color.rgb, back_color.rgb), 1.0); + } + else if (backbuffer == 0.0 || !is_displacement) + { + fragColor = color; } } diff --git a/data/shader/shader330.vert b/data/shader/shader330.vert index 8a0c413c84..a46fc3a3a8 100644 --- a/data/shader/shader330.vert +++ b/data/shader/shader330.vert @@ -3,9 +3,11 @@ in vec2 texcoord; in vec2 position; in vec4 diffuse; +in uint attrs; out vec2 texcoord_var; out vec4 diffuse_var; +flat out uint attrs_var; uniform mat3 modelviewprojection; @@ -13,6 +15,7 @@ void main(void) { texcoord_var = texcoord; diffuse_var = diffuse; + attrs_var = attrs; gl_Position = vec4(vec3(position, 1) * modelviewprojection, 1.0); } diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 6a82c21486..ed6b544792 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -164,11 +164,12 @@ BadGuy::draw(DrawingContext& context) Vector draw_offset = context.get_time_offset() * m_physic.get_velocity(); Vector draw_pos = get_pos() + draw_offset; + int layer = m_in_water ? -1 : m_layer; if (m_state == STATE_INIT || m_state == STATE_INACTIVE) { if (Editor::is_active()) { - m_sprite->draw(context.color(), draw_pos, m_layer, m_flip); + m_sprite->draw(context.color(), draw_pos, layer, m_flip); } } else @@ -177,30 +178,30 @@ BadGuy::draw(DrawingContext& context) { context.push_transform(); context.set_flip(context.get_flip() ^ VERTICAL_FLIP); - m_sprite->draw(context.color(), draw_pos, m_layer, m_flip); + m_sprite->draw(context.color(), draw_pos, layer, m_flip); context.pop_transform(); } else { if (m_unfreeze_timer.started() && m_unfreeze_timer.get_timeleft() <= 1.f) { - m_sprite->draw(context.color(), draw_pos + Vector(graphicsRandom.randf(-3, 3), 0.f), m_layer - 1, m_flip); + m_sprite->draw(context.color(), draw_pos + Vector(graphicsRandom.randf(-3, 3), 0.f), layer - 1, m_flip); if (is_portable()) - m_freezesprite->draw(context.color(), draw_pos + Vector(graphicsRandom.randf(-3, 3), 0.f), m_layer); + m_freezesprite->draw(context.color(), draw_pos + Vector(graphicsRandom.randf(-3, 3), 0.f), layer); } else { if (m_frozen && is_portable()) { - m_freezesprite->draw(context.color(), draw_pos, m_layer); + m_freezesprite->draw(context.color(), draw_pos, layer); } if (m_state != STATE_BURNING || m_firesprite->get_current_frame() < 5) - m_sprite->draw(context.color(), draw_pos, m_layer - (m_frozen ? 1 : 0), m_flip); + m_sprite->draw(context.color(), draw_pos, layer - (m_frozen ? 1 : 0), m_flip); } if (m_state == STATE_BURNING) { - m_firesprite->draw(context.color(), draw_pos, m_layer); + m_firesprite->draw(context.color(), draw_pos, layer); } if (m_glowing) diff --git a/src/object/player.cpp b/src/object/player.cpp index 91f05c0b3c..8a95aa0e45 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -2286,7 +2286,7 @@ Player::draw(DrawingContext& context) else if (m_dying) m_sprite->draw(context.color(), draw_pos, Sector::get().get_foremost_opaque_layer() + 1); else - m_sprite->draw(context.color(), draw_pos, LAYER_OBJECTS + 1); + m_sprite->draw(context.color(), draw_pos, m_no_water ? LAYER_OBJECTS + 1 : -1); //TODO: Replace recoloring with proper costumes Color power_color = (get_bonus() == BONUS_FIRE ? Color(1.f, 0.7f, 0.5f) : diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index 0b9f8d067e..8ee2297030 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -555,7 +555,8 @@ TileMap::draw(DrawingContext& context) std::unordered_map, - std::vector>> batches; + std::vector, + std::vector>> batches; for (pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) { for (pos.y = start.y, ty = t_draw_rect.top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) { @@ -584,6 +585,7 @@ TileMap::draw(DrawingContext& context) std::get<1>(batches[surface]).emplace_back(pos, Sizef(static_cast(surface->get_width()), static_cast(surface->get_height()))); + std::get<2>(batches[surface]).emplace_back(tile.get_attributes()); } } } @@ -597,6 +599,7 @@ TileMap::draw(DrawingContext& context) canvas.draw_surface_batch(surface, std::move(std::get<0>(it.second)), std::move(std::get<1>(it.second)), + std::move(std::get<2>(it.second)), m_current_tint, m_z_pos); } } diff --git a/src/supertux/tile.hpp b/src/supertux/tile.hpp index 24af9992af..d177f7450c 100644 --- a/src/supertux/tile.hpp +++ b/src/supertux/tile.hpp @@ -40,19 +40,13 @@ class Tile final SOLID = 0x0001, /** uni-directional solid tile */ UNISOLID = 0x0002, - /** a brick that can be destroyed by jumping under it */ - BRICK = 0x0004, //Marked for removal, DO NOT USE! - /** the level should be finished when touching a goaltile. - * if data is 0 then the endsequence should be triggered, if data is 1 - * then we can finish the level instantly. - */ - GOAL = 0x0008, //Marked for removal, DO NOT USE! + /** Is affected by shader */ + SHADED = 0x0004, + /* 0x0008 reserved */ /** slope tile */ SLOPE = 0x0010, - /** Bonusbox, content is stored in \a data */ - FULLBOX = 0x0020, //Marked for removal, DO NOT USE! - /** Tile is a coin */ - COIN = 0x0040, //Marked for removal, DO NOT USE! + /* 0x0020 reserved */ + /* 0x0040 reserved */ /* interesting flags (the following are passed to gameobjects) */ FIRST_INTERESTING_FLAG = 0x0100, @@ -66,7 +60,7 @@ class Tile final /** for lava: WATER, HURTS, FIRE */ FIRE = 0x0800, /** a walljumping trigger tile */ - WALLJUMP = 0x1000 + WALLJUMP = 0x1000, }; /** worldmap flags */ diff --git a/src/supertux/tile_set_parser.cpp b/src/supertux/tile_set_parser.cpp index 0eb92d2c70..f0eafbd834 100644 --- a/src/supertux/tile_set_parser.cpp +++ b/src/supertux/tile_set_parser.cpp @@ -239,8 +239,8 @@ TileSetParser::parse_tile(const ReaderMapping& reader) attributes |= Tile::SOLID; if (reader.get("unisolid", value) && value) attributes |= Tile::UNISOLID | Tile::SOLID; - if (reader.get("brick", value) && value) - attributes |= Tile::BRICK; + if (reader.get("shaded", value) && value) + attributes |= Tile::SHADED; if (reader.get("ice", value) && value) attributes |= Tile::ICE; if (reader.get("water", value) && value) @@ -251,12 +251,6 @@ TileSetParser::parse_tile(const ReaderMapping& reader) attributes |= Tile::FIRE; if (reader.get("walljump", value) && value) attributes |= Tile::WALLJUMP; - if (reader.get("fullbox", value) && value) - attributes |= Tile::FULLBOX; - if (reader.get("coin", value) && value) - attributes |= Tile::COIN; - if (reader.get("goal", value) && value) - attributes |= Tile::GOAL; uint32_t data = 0; diff --git a/src/video/canvas.cpp b/src/video/canvas.cpp index 103bdbfb5c..a6c5b78634 100644 --- a/src/video/canvas.cpp +++ b/src/video/canvas.cpp @@ -137,6 +137,7 @@ Canvas::draw_surface(const SurfacePtr& surface, request->dstrects.emplace_back(Rectf(apply_translate(position) * scale(), Sizef(static_cast(surface->get_width()) * scale(), static_cast(surface->get_height()) * scale()))); + request->attrs.emplace_back(0); request->angles.emplace_back(angle); request->texture = surface->get_texture().get(); request->displacement_texture = surface->get_displacement_texture().get(); @@ -175,6 +176,7 @@ Canvas::draw_surface_part(const SurfacePtr& surface, const Rectf& srcrect, const request->srcrects.emplace_back(srcrect); request->dstrects.emplace_back(apply_translate(dstrect.p1())*scale(), dstrect.get_size()*scale()); request->angles.emplace_back(0.0f); + request->attrs.emplace_back(0); request->texture = surface->get_texture().get(); request->displacement_texture = surface->get_displacement_texture().get(); request->color = style.get_color(); @@ -188,11 +190,28 @@ Canvas::draw_surface_batch(const SurfacePtr& surface, std::vector dstrects, const Color& color, int layer) +{ + draw_surface_batch(surface, + std::move(srcrects), + std::move(dstrects), + std::vector(srcrects.size(), 0.0f), + std::vector(srcrects.size(), 0.0f), + color, layer); +} + +void +Canvas::draw_surface_batch(const SurfacePtr& surface, + std::vector srcrects, + std::vector dstrects, + std::vector attrs, + const Color& color, + int layer) { const size_t len = srcrects.size(); draw_surface_batch(surface, std::move(srcrects), std::move(dstrects), + std::move(attrs), std::vector(len, 0.0f), color, layer); } @@ -204,6 +223,24 @@ Canvas::draw_surface_batch(const SurfacePtr& surface, std::vector angles, const Color& color, int layer) +{ + const size_t len = srcrects.size(); + draw_surface_batch(surface, + std::move(srcrects), + std::move(dstrects), + std::vector(len, 0), + std::move(angles), + color, layer); +} + +void +Canvas::draw_surface_batch(const SurfacePtr& surface, + std::vector srcrects, + std::vector dstrects, + std::vector attrs, + std::vector angles, + const Color& color, + int layer) { if (!surface) return; @@ -215,6 +252,7 @@ Canvas::draw_surface_batch(const SurfacePtr& surface, request->srcrects = std::move(srcrects); request->dstrects = std::move(dstrects); + request->attrs = std::move(attrs); request->angles = std::move(angles); for (auto& dstrect : request->dstrects) diff --git a/src/video/canvas.hpp b/src/video/canvas.hpp index 0e33019d57..49468add51 100644 --- a/src/video/canvas.hpp +++ b/src/video/canvas.hpp @@ -66,6 +66,19 @@ class Canvas final std::vector angles, const Color& color, int layer); + void draw_surface_batch(const SurfacePtr& surface, + std::vector srcrects, + std::vector dstrects, + std::vector attrs, + const Color& color, + int layer); + void draw_surface_batch(const SurfacePtr& surface, + std::vector srcrects, + std::vector dstrects, + std::vector attrs, + std::vector angles, + const Color& color, + int layer); Rectf draw_text(const FontPtr& font, const std::string& text, const Vector& position, FontAlignment alignment, int layer, const Color& color = Color(1.0,1.0,1.0)); /** Draw text to the center of the screen */ diff --git a/src/video/drawing_request.hpp b/src/video/drawing_request.hpp index a34aaafa26..4b27bf3b6b 100644 --- a/src/video/drawing_request.hpp +++ b/src/video/drawing_request.hpp @@ -64,6 +64,7 @@ struct TextureRequest : public DrawingRequest displacement_texture(), srcrects(), dstrects(), + attrs(), angles(), color(1.0f, 1.0f, 1.0f) {} @@ -74,6 +75,7 @@ struct TextureRequest : public DrawingRequest const Texture* displacement_texture; std::vector srcrects; std::vector dstrects; + std::vector attrs; std::vector angles; Color color; diff --git a/src/video/gl/gl20_context.cpp b/src/video/gl/gl20_context.cpp index 11e24c795f..6e2334a1ac 100644 --- a/src/video/gl/gl20_context.cpp +++ b/src/video/gl/gl20_context.cpp @@ -113,6 +113,12 @@ GL20Context::set_texcoord(float u, float v) assert_gl(); } + +void +GL20Context::set_attrs(const uint32_t* data, size_t size) +{ +} + void GL20Context::set_colors(const float* data, size_t size) { diff --git a/src/video/gl/gl20_context.hpp b/src/video/gl/gl20_context.hpp index d1d7b0909a..1caf364ea5 100644 --- a/src/video/gl/gl20_context.hpp +++ b/src/video/gl/gl20_context.hpp @@ -41,6 +41,8 @@ class GL20Context final : public GLContext virtual void set_colors(const float* data, size_t size) override; virtual void set_color(const Color& color) override; + + virtual void set_attrs(const uint32_t* data, size_t size) override; virtual void bind_texture(const Texture& texture, const Texture* displacement_texture) override; virtual void bind_no_texture() override; diff --git a/src/video/gl/gl33core_context.cpp b/src/video/gl/gl33core_context.cpp index 928c917f00..e0060527be 100644 --- a/src/video/gl/gl33core_context.cpp +++ b/src/video/gl/gl33core_context.cpp @@ -176,6 +176,12 @@ GL33CoreContext::set_color(const Color& color) m_vertex_arrays->set_color(color); } +void +GL33CoreContext::set_attrs(const uint32_t* data, size_t size) +{ + m_vertex_arrays->set_attrs(data, size); +} + void GL33CoreContext::bind_texture(const Texture& texture, const Texture* displacement_texture) { diff --git a/src/video/gl/gl33core_context.hpp b/src/video/gl/gl33core_context.hpp index 529cca8cf1..24040d9e4f 100644 --- a/src/video/gl/gl33core_context.hpp +++ b/src/video/gl/gl33core_context.hpp @@ -43,6 +43,8 @@ class GL33CoreContext final : public GLContext virtual void set_texcoords(const float* data, size_t size) override; virtual void set_texcoord(float u, float v) override; + + virtual void set_attrs(const uint32_t* data, size_t size) override; virtual void set_colors(const float* data, size_t size) override; virtual void set_color(const Color& color) override; diff --git a/src/video/gl/gl_context.hpp b/src/video/gl/gl_context.hpp index c55bf56ba3..4c500b9d07 100644 --- a/src/video/gl/gl_context.hpp +++ b/src/video/gl/gl_context.hpp @@ -46,6 +46,8 @@ class GLContext virtual void set_colors(const float* data, size_t size) = 0; virtual void set_color(const Color& color) = 0; + + virtual void set_attrs(const uint32_t* data, size_t size) = 0; virtual void bind_texture(const Texture& texture, const Texture* displacement_texture) = 0; virtual void bind_no_texture() = 0; diff --git a/src/video/gl/gl_painter.cpp b/src/video/gl/gl_painter.cpp index 382606c3cd..b90a773dbb 100644 --- a/src/video/gl/gl_painter.cpp +++ b/src/video/gl/gl_painter.cpp @@ -17,6 +17,7 @@ #include "video/gl/gl_painter.hpp" #include +#include #include #include "math/util.hpp" @@ -63,7 +64,8 @@ GLPainter::GLPainter(GLVideoSystem& video_system, GLRenderer& renderer) : m_video_system(video_system), m_renderer(renderer), m_vertices(), - m_uvs() + m_uvs(), + m_attrs() { } @@ -76,12 +78,15 @@ GLPainter::draw_texture(const TextureRequest& request) assert(request.srcrects.size() == request.dstrects.size()); assert(request.srcrects.size() == request.angles.size()); + assert(request.attrs.size() == request.attrs.size()); m_vertices.reserve(request.srcrects.size() * 12); m_uvs.reserve(request.srcrects.size() * 12); + m_attrs.reserve(request.attrs.size() * 12); m_vertices.clear(); m_uvs.clear(); + m_attrs.clear(); for (size_t i = 0; i < request.srcrects.size(); ++i) { @@ -94,6 +99,9 @@ GLPainter::draw_texture(const TextureRequest& request) float uv_top = request.srcrects[i].get_top() / static_cast(texture.get_texture_height()); float uv_right = request.srcrects[i].get_right() / static_cast(texture.get_texture_width()); float uv_bottom = request.srcrects[i].get_bottom() / static_cast(texture.get_texture_height()); + + if (request.attrs.size() > i) + m_attrs.insert(m_attrs.end(), 6, request.attrs[i]); if (request.flip & HORIZONTAL_FLIP) std::swap(uv_left, uv_right); @@ -170,6 +178,7 @@ GLPainter::draw_texture(const TextureRequest& request) context.bind_texture(texture, request.displacement_texture); context.set_texcoords(m_uvs.data(), sizeof(float) * m_uvs.size()); context.set_positions(m_vertices.data(), sizeof(float) * m_vertices.size()); + context.set_attrs(m_attrs.data(), sizeof(uint32_t) * m_attrs.size()); context.set_color(Color(request.color.red, request.color.green, request.color.blue, diff --git a/src/video/gl/gl_painter.hpp b/src/video/gl/gl_painter.hpp index 3d8117698d..6d33fb6ee9 100644 --- a/src/video/gl/gl_painter.hpp +++ b/src/video/gl/gl_painter.hpp @@ -49,6 +49,7 @@ class GLPainter final : public Painter private: std::vector m_vertices; std::vector m_uvs; + std::vector m_attrs; private: GLPainter(const GLPainter&) = delete; diff --git a/src/video/gl/gl_program.cpp b/src/video/gl/gl_program.cpp index 39ab329b25..8c00a63885 100644 --- a/src/video/gl/gl_program.cpp +++ b/src/video/gl/gl_program.cpp @@ -37,7 +37,8 @@ GLProgram::GLProgram() : m_position_location(-1), m_texcoord_location(-1), m_diffuse_location(-1), - m_is_displacement_location(-1) + m_is_displacement_location(-1), + m_attrs_location(-1) { assert_gl(); @@ -77,6 +78,7 @@ GLProgram::GLProgram() : m_position_location = glGetAttribLocation(m_program, "position"); m_texcoord_location = glGetAttribLocation(m_program, "texcoord"); m_diffuse_location = glGetAttribLocation(m_program, "diffuse"); + m_attrs_location = glGetAttribLocation(m_program, "attrs"); assert_gl(); } diff --git a/src/video/gl/gl_program.hpp b/src/video/gl/gl_program.hpp index 7fb16163cd..73cfd8761c 100644 --- a/src/video/gl/gl_program.hpp +++ b/src/video/gl/gl_program.hpp @@ -46,6 +46,7 @@ class GLProgram final inline GLint get_texcoord_location() const { return check_valid(m_texcoord_location, "texcoord"); } inline GLint get_diffuse_location() const { return check_valid(m_diffuse_location, "diffuse"); } inline GLint get_is_displacement_location() const { return check_valid(m_is_displacement_location, "is_displacement"); } + inline GLint get_attrs_location() const { return check_valid(m_attrs_location, "attrs"); } private: bool get_link_status() const; @@ -72,6 +73,7 @@ class GLProgram final GLint m_texcoord_location; GLint m_diffuse_location; GLint m_is_displacement_location; + GLint m_attrs_location; private: GLProgram(const GLProgram&) = delete; diff --git a/src/video/gl/gl_vertex_arrays.cpp b/src/video/gl/gl_vertex_arrays.cpp index e48eb12a8c..7016358257 100644 --- a/src/video/gl/gl_vertex_arrays.cpp +++ b/src/video/gl/gl_vertex_arrays.cpp @@ -27,6 +27,7 @@ GLVertexArrays::GLVertexArrays(GL33CoreContext& context) : m_vao(), m_positions_buffer(), m_texcoords_buffer(), + m_attrs_buffer(), m_color_buffer() { assert_gl(); @@ -34,6 +35,7 @@ GLVertexArrays::GLVertexArrays(GL33CoreContext& context) : glGenVertexArrays(1, &m_vao); glGenBuffers(1, &m_positions_buffer); glGenBuffers(1, &m_texcoords_buffer); + glGenBuffers(1, &m_attrs_buffer); glGenBuffers(1, &m_color_buffer); assert_gl(); @@ -43,6 +45,7 @@ GLVertexArrays::~GLVertexArrays() { glDeleteBuffers(1, &m_positions_buffer); glDeleteBuffers(1, &m_texcoords_buffer); + glDeleteBuffers(1, &m_attrs_buffer); glDeleteBuffers(1, &m_color_buffer); glDeleteVertexArrays(1, &m_vao); } @@ -87,6 +90,21 @@ GLVertexArrays::set_texcoords(const float* data, size_t size) assert_gl(); } +void +GLVertexArrays::set_attrs(const uint32_t* data, size_t size) +{ + assert_gl(); + + glBindBuffer(GL_ARRAY_BUFFER, m_attrs_buffer); + glBufferData(GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW); + + int loc = m_context.get_program().get_attrs_location(); + glVertexAttribIPointer(loc, 1, GL_UNSIGNED_INT, sizeof(uint32_t), nullptr); + glEnableVertexAttribArray(loc); + + assert_gl(); +} + void GLVertexArrays::set_texcoord(float u, float v) { diff --git a/src/video/gl/gl_vertex_arrays.hpp b/src/video/gl/gl_vertex_arrays.hpp index a3508239d2..2a6fc6ba48 100644 --- a/src/video/gl/gl_vertex_arrays.hpp +++ b/src/video/gl/gl_vertex_arrays.hpp @@ -32,6 +32,8 @@ class GLVertexArrays final void bind(); void set_positions(const float* data, size_t size); + + void set_attrs(const uint32_t* data, size_t size); /** size is in bytes */ void set_texcoords(const float* data, size_t size); @@ -46,6 +48,7 @@ class GLVertexArrays final GLuint m_positions_buffer; GLuint m_texcoords_buffer; GLuint m_color_buffer; + GLuint m_attrs_buffer; private: GLVertexArrays(const GLVertexArrays&) = delete;