Skip to content

Commit

Permalink
fixed incorrect element count set in glgeometrybuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Jan 23, 2025
1 parent 12ceecf commit 652b788
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions fyrox-graphics/src/gl/geometry_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::geometry_buffer::ElementsDescriptor;
use crate::{
buffer::{Buffer, BufferKind},
core::{array_as_u8_slice, math::TriangleDefinition},
error::FrameworkError,
geometry_buffer::{AttributeKind, GeometryBuffer, GeometryBufferDescriptor},
geometry_buffer::{
AttributeKind, ElementsDescriptor, GeometryBuffer, GeometryBufferDescriptor,
},
gl::{buffer::GlBuffer, server::GlGraphicsServer, ToGlConstant},
ElementKind,
};
Expand Down Expand Up @@ -63,11 +64,15 @@ impl GlGeometryBuffer {

let element_buffer = GlBuffer::new(server, 0, BufferKind::Index, desc.usage)?;

element_buffer.write_data(match desc.elements {
ElementsDescriptor::Triangles(triangles) => array_as_u8_slice(triangles),
ElementsDescriptor::Lines(lines) => array_as_u8_slice(lines),
ElementsDescriptor::Points(points) => array_as_u8_slice(points),
})?;
let (element_count, data) = match desc.elements {
ElementsDescriptor::Triangles(triangles) => {
(triangles.len(), array_as_u8_slice(triangles))
}
ElementsDescriptor::Lines(lines) => (lines.len(), array_as_u8_slice(lines)),
ElementsDescriptor::Points(points) => (points.len(), array_as_u8_slice(points)),
};

element_buffer.write_data(data)?;

let mut buffers = Vec::new();
for buffer in desc.buffers {
Expand Down Expand Up @@ -117,7 +122,7 @@ impl GlGeometryBuffer {
vertex_array_object: vao,
buffers,
element_buffer,
element_count: Cell::new(0),
element_count: Cell::new(element_count),
element_kind: desc.elements.element_kind(),
thread_mark: PhantomData,
})
Expand Down

0 comments on commit 652b788

Please sign in to comment.