Skip to content

Commit

Permalink
fix the primitive restart bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ineveraskedforthis committed Jan 22, 2025
1 parent a03d5df commit abebc50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Binary file modified assets/prov_border.dds
Binary file not shown.
11 changes: 8 additions & 3 deletions assets/shaders/glsl/textured_line_b_v.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ default: break;
void main() {
vec4 central_pos = calc_gl_position(vertex_position);
vec2 corner_shift = vec2(0.f, 0.f);
float true_width = width;

if((texture_coord > 0.5f) || (texture_coord < -0.5f) ) {
if (texture_coord < 0.01f) {
true_width = 0.00001f;
}

//if((texture_coord > 0.5f) || (texture_coord < -0.5f) ) {
vec2 bpt = central_pos.xy;
vec2 apt = calc_gl_position(prev_point).xy;
vec2 cpt = calc_gl_position(next_point).xy;
Expand All @@ -122,11 +127,11 @@ void main() {
vec2 bnorm = vec2(-bdir.y, bdir.x);
vec2 corner_normal = normalize(anorm + bnorm);

corner_shift = corner_normal * zoom * width / (1.0f + max(-0.5f, dot(anorm, bnorm)));
corner_shift = corner_normal * zoom * true_width / (1.0f + max(-0.5f, dot(anorm, bnorm)));

// transform result back to screen + depth coordinates
corner_shift.x /= aspect_ratio;
}
//}

gl_Position = central_pos + vec4(corner_shift.x, corner_shift.y, 0.0f, 0.0f);

Expand Down
4 changes: 4 additions & 0 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ void display_data::create_meshes() {
map_indices.push_back(uint16_t(bottom_row_start + 1 + x));
map_indices.push_back(uint16_t(top_row_start + 1 + x));
}
// primitive restart marker
map_indices.push_back(std::numeric_limits<uint16_t>::max());
}

Expand Down Expand Up @@ -603,6 +604,9 @@ void display_data::render(sys::state& state, glm::vec2 screen_size, glm::vec2 of
fragment_subroutines = 2; // get_land_political_far/get_water_political()
glUniform1ui(shader_uniforms[shader_terrain][uniform_subroutines_index_2], fragment_subroutines);
}

glEnable(GL_PRIMITIVE_RESTART);
glPrimitiveRestartIndex(std::numeric_limits<uint16_t>::max());
glBindVertexArray(vao_array[vo_land]);
glDrawElements(GL_TRIANGLE_STRIP, GLsizei(map_indices.size() - 1), GL_UNSIGNED_SHORT, map_indices.data());

Expand Down

0 comments on commit abebc50

Please sign in to comment.