Commit 7c36b6c6 authored by Guillaume Seguin's avatar Guillaume Seguin

Rework and cleanup gcview indexing

parent 0914dd1f
...@@ -316,7 +316,7 @@ class GcodeModel(Model): ...@@ -316,7 +316,7 @@ class GcodeModel(Model):
self.max_layers = len(self.layer_stops) - 1 self.max_layers = len(self.layer_stops) - 1
self.num_layers_to_draw = self.max_layers + 1 self.num_layers_to_draw = self.max_layers + 1
self.printed_until = -1 self.printed_until = 0
self.only_current = False self.only_current = False
self.initialized = False self.initialized = False
self.loaded = True self.loaded = True
...@@ -397,6 +397,14 @@ class GcodeModel(Model): ...@@ -397,6 +397,14 @@ class GcodeModel(Model):
self.travel_buffer.unbind() self.travel_buffer.unbind()
def _draw_elements(self, start, end, draw_type = GL_LINES):
glDrawRangeElements(draw_type,
self.count_print_vertices[start - 1],
self.count_print_vertices[end] - 1,
self.count_print_indices[end] - self.count_print_indices[start - 1],
GL_UNSIGNED_INT,
sizeof(GLuint) * self.count_print_indices[start - 1])
def _display_movements(self, has_vbo): def _display_movements(self, has_vbo):
self.vertex_buffer.bind() self.vertex_buffer.bind()
if has_vbo: if has_vbo:
...@@ -412,11 +420,12 @@ class GcodeModel(Model): ...@@ -412,11 +420,12 @@ class GcodeModel(Model):
self.index_buffer.bind() self.index_buffer.bind()
start = 0 start = 1
if self.num_layers_to_draw <= self.max_layers: layer_selected = self.num_layers_to_draw <= self.max_layers
if layer_selected:
end_prev_layer = self.layer_stops[self.num_layers_to_draw - 1] end_prev_layer = self.layer_stops[self.num_layers_to_draw - 1]
else: else:
end_prev_layer = -1 end_prev_layer = 0
end = self.layer_stops[min(self.num_layers_to_draw, self.max_layers)] end = self.layer_stops[min(self.num_layers_to_draw, self.max_layers)]
glDisableClientState(GL_COLOR_ARRAY) glDisableClientState(GL_COLOR_ARRAY)
...@@ -426,37 +435,22 @@ class GcodeModel(Model): ...@@ -426,37 +435,22 @@ class GcodeModel(Model):
# Draw printed stuff until end or end_prev_layer # Draw printed stuff until end or end_prev_layer
cur_end = min(self.printed_until, end) cur_end = min(self.printed_until, end)
if not self.only_current: if not self.only_current:
if 0 <= end_prev_layer <= cur_end: if 1 <= end_prev_layer <= cur_end:
glDrawRangeElements(GL_LINES, self._draw_elements(1, end_prev_layer)
0, elif cur_end >= 1:
self.count_print_vertices[end_prev_layer], self._draw_elements(1, cur_end)
self.count_print_indices[end_prev_layer],
GL_UNSIGNED_INT,
0)
elif cur_end >= 0:
glDrawRangeElements(GL_LINES,
0,
self.count_print_vertices[cur_end],
self.count_print_indices[cur_end],
GL_UNSIGNED_INT,
0)
glEnableClientState(GL_COLOR_ARRAY) glEnableClientState(GL_COLOR_ARRAY)
# Draw nonprinted stuff until end_prev_layer # Draw nonprinted stuff until end_prev_layer
start = max(cur_end, 0) start = max(cur_end, 1)
if end_prev_layer >= start: if end_prev_layer >= start:
if not self.only_current: if not self.only_current:
glDrawRangeElements(GL_LINES, self._draw_elements(start, end_prev_layer)
self.count_print_vertices[start],
self.count_print_vertices[end_prev_layer],
self.count_print_indices[end_prev_layer] - self.count_print_indices[start],
GL_UNSIGNED_INT,
sizeof(GLuint) * self.count_print_indices[start])
cur_end = end_prev_layer cur_end = end_prev_layer
# Draw current layer # Draw current layer
if end_prev_layer >= 0: if layer_selected:
glDisableClientState(GL_COLOR_ARRAY) glDisableClientState(GL_COLOR_ARRAY)
# Backup & increase line width # Backup & increase line width
...@@ -467,22 +461,12 @@ class GcodeModel(Model): ...@@ -467,22 +461,12 @@ class GcodeModel(Model):
glColor4f(*self.color_current_printed) glColor4f(*self.color_current_printed)
if cur_end > end_prev_layer: if cur_end > end_prev_layer:
glDrawRangeElements(GL_LINES, self._draw_elements(end_prev_layer + 1, cur_end)
self.count_print_vertices[end_prev_layer + 1],
self.count_print_vertices[cur_end],
self.count_print_indices[cur_end] - self.count_print_indices[end_prev_layer] + 1,
GL_UNSIGNED_INT,
sizeof(GLuint) * self.count_print_indices[end_prev_layer + 1])
glColor4f(*self.color_current) glColor4f(*self.color_current)
if end > cur_end: if end > cur_end:
glDrawRangeElements(GL_LINES, self._draw_elements(cur_end + 1, end)
self.count_print_vertices[cur_end],
self.count_print_vertices[end],
self.count_print_indices[end] - self.count_print_indices[cur_end] + 1,
GL_UNSIGNED_INT,
sizeof(GLuint) * self.count_print_indices[cur_end])
# Restore line width # Restore line width
glLineWidth(orig_linewidth) glLineWidth(orig_linewidth)
...@@ -490,14 +474,9 @@ class GcodeModel(Model): ...@@ -490,14 +474,9 @@ class GcodeModel(Model):
glEnableClientState(GL_COLOR_ARRAY) glEnableClientState(GL_COLOR_ARRAY)
# Draw non printed stuff until end (if not ending at a given layer) # Draw non printed stuff until end (if not ending at a given layer)
start = max(self.printed_until, 0) start = max(self.printed_until, 1)
if end_prev_layer < 0 and end > 0 and not self.only_current: if not layer_selected and end >= start:
glDrawRangeElements(GL_LINES, self._draw_elements(start, end)
self.count_print_vertices[start],
self.count_print_vertices[end],
self.count_print_indices[end] - self.count_print_indices[start] + 1,
GL_UNSIGNED_INT,
sizeof(GLuint) * self.count_print_indices[start])
self.vertex_buffer.unbind() self.vertex_buffer.unbind()
self.vertex_color_buffer.unbind() self.vertex_color_buffer.unbind()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment