@@ -1578,16 +1578,25 @@ impl<T: RenderTarget> Canvas<T> {
1578
1578
& mut self ,
1579
1579
texture : & Texture ,
1580
1580
vertices : & [ Vertex ] ,
1581
- indices : & [ u32 ] ,
1581
+ indices : Option < & [ u32 ] > ,
1582
1582
) -> Result < ( ) , String > {
1583
+ // API expects i32, however the underlying SDL_RenderGeometryRaw call casts to u32
1584
+ let indices_ptr: * const c_int = match indices {
1585
+ Some ( i) => i. as_ptr ( ) as * const c_int ,
1586
+ None => std:: ptr:: null ( ) ,
1587
+ } ;
1588
+ let indices_count: c_int = match indices {
1589
+ Some ( i) => i. len ( ) as c_int ,
1590
+ None => 0 ,
1591
+ } ;
1583
1592
let result = unsafe {
1584
1593
sys:: SDL_RenderGeometry (
1585
1594
self . context . raw ,
1586
1595
texture. raw ,
1587
1596
Vertex :: raw_slice ( vertices) ,
1588
1597
vertices. len ( ) as c_int ,
1589
- indices . as_ptr ( ) as * const i32 ,
1590
- indices . len ( ) as c_int ,
1598
+ indices_ptr ,
1599
+ indices_count ,
1591
1600
)
1592
1601
} ;
1593
1602
@@ -1598,9 +1607,9 @@ impl<T: RenderTarget> Canvas<T> {
1598
1607
}
1599
1608
}
1600
1609
1601
- /// Render a list of triangles, optionally using a texture and indices into the vertex arrays .
1610
+ /// Render a list of triangles, using separate arrays for position, color and UV .
1602
1611
#[ doc( alias = "SDL_RenderGeometryRaw" ) ]
1603
- pub fn geometry_raw < I : VertexIndex > (
1612
+ pub fn geometry_split < I : VertexIndex > (
1604
1613
& mut self ,
1605
1614
texture : & Texture ,
1606
1615
xy : & [ f32 ] ,
@@ -1610,8 +1619,20 @@ impl<T: RenderTarget> Canvas<T> {
1610
1619
uv : & [ f32 ] ,
1611
1620
uv_stride : i32 ,
1612
1621
num_vertices : i32 ,
1613
- indices : & [ I ] ,
1622
+ indices : Option < & [ I ] > ,
1614
1623
) -> Result < ( ) , String > {
1624
+ let indices_ptr: * const c_void = match indices {
1625
+ Some ( i) => i. as_ptr ( ) as * const c_void ,
1626
+ None => std:: ptr:: null ( ) ,
1627
+ } ;
1628
+ let indices_count: c_int = match indices {
1629
+ Some ( i) => i. len ( ) as c_int ,
1630
+ None => 0 ,
1631
+ } ;
1632
+ let indices_size: c_int = match indices {
1633
+ Some ( _) => std:: mem:: size_of :: < I > ( ) as c_int ,
1634
+ None => 0 ,
1635
+ } ;
1615
1636
let result = unsafe {
1616
1637
sys:: SDL_RenderGeometryRaw (
1617
1638
self . context . raw ,
@@ -1623,9 +1644,58 @@ impl<T: RenderTarget> Canvas<T> {
1623
1644
uv. as_ptr ( ) ,
1624
1645
uv_stride as c_int ,
1625
1646
num_vertices as c_int ,
1626
- indices. as_ptr ( ) as * const c_void ,
1627
- indices. len ( ) as c_int ,
1628
- std:: mem:: size_of :: < I > ( ) as i32 ,
1647
+ indices_ptr,
1648
+ indices_count,
1649
+ indices_size,
1650
+ )
1651
+ } ;
1652
+
1653
+ if result != 0 {
1654
+ Err ( get_error ( ) )
1655
+ } else {
1656
+ Ok ( ( ) )
1657
+ }
1658
+ }
1659
+
1660
+ /// Render a list of triangles, optionally using a texture and indices into the vertex arrays.
1661
+ /// It is recommended that you use the "memoffset" crate to determine the offsets of fields in your struct.
1662
+ #[ doc( alias = "SDL_RenderGeometryRaw" ) ]
1663
+ pub fn geometry_struct < V , I : VertexIndex > (
1664
+ & mut self ,
1665
+ texture : & Texture ,
1666
+ vertices : & [ V ] ,
1667
+ xy_offset : usize ,
1668
+ color_offset : usize ,
1669
+ uv_offset : usize ,
1670
+ indices : Option < & [ I ] > ,
1671
+ ) -> Result < ( ) , String > {
1672
+ let stride = std:: mem:: size_of :: < V > ( ) as c_int ;
1673
+ let indices_ptr: * const c_void = match indices {
1674
+ Some ( i) => i. as_ptr ( ) as * const c_void ,
1675
+ None => std:: ptr:: null ( ) ,
1676
+ } ;
1677
+ let indices_count: c_int = match indices {
1678
+ Some ( i) => i. len ( ) as c_int ,
1679
+ None => 0 ,
1680
+ } ;
1681
+ let indices_size: c_int = match indices {
1682
+ Some ( _) => std:: mem:: size_of :: < I > ( ) as c_int ,
1683
+ None => 0 ,
1684
+ } ;
1685
+ let result = unsafe {
1686
+ sys:: SDL_RenderGeometryRaw (
1687
+ self . context . raw ,
1688
+ texture. raw ,
1689
+ ( vertices. as_ptr ( ) as * const u8 ) . add ( xy_offset) as * const f32 ,
1690
+ stride,
1691
+ ( vertices. as_ptr ( ) as * const u8 ) . add ( color_offset) as * const sys:: SDL_Color ,
1692
+ stride,
1693
+ ( vertices. as_ptr ( ) as * const u8 ) . add ( uv_offset) as * const f32 ,
1694
+ stride,
1695
+ vertices. len ( ) as c_int ,
1696
+ indices_ptr,
1697
+ indices_count,
1698
+ indices_size,
1629
1699
)
1630
1700
} ;
1631
1701
0 commit comments