@@ -26,54 +26,58 @@ static mut LIST: Align16<[u32; 0x40000]> = Align16([0; 0x40000]);
26
26
/// # Parameters
27
27
///
28
28
/// - `allocator`: A reference to a `SimpleVramAllocator`.
29
- pub unsafe fn setup ( allocator : & mut psp:: vram_alloc:: SimpleVramAllocator ) {
30
- let fbp0 = allocator. alloc_texture_pixels ( BUF_WIDTH , SCREEN_HEIGHT , TexturePixelFormat :: Psm8888 ) . as_mut_ptr_from_zero ( ) ;
31
- let fbp1 = allocator. alloc_texture_pixels ( BUF_WIDTH , SCREEN_HEIGHT , TexturePixelFormat :: Psm8888 ) . as_mut_ptr_from_zero ( ) ;
32
-
33
- sys:: sceGumLoadIdentity ( ) ;
34
- sys:: sceGuInit ( ) ;
35
-
36
- sys:: sceGuStart ( GuContextType :: Direct , & mut LIST . 0 as * mut [ u32 ; 0x40000 ] as * mut _ ) ;
37
- sys:: sceGuDrawBuffer ( DisplayPixelFormat :: Psm8888 , fbp0 as _ , BUF_WIDTH as i32 ) ;
38
- sys:: sceGuDispBuffer ( SCREEN_WIDTH as i32 , SCREEN_HEIGHT as i32 , fbp1 as _ , BUF_WIDTH as i32 ) ;
39
- sys:: sceGuOffset ( 2048 - ( SCREEN_WIDTH / 2 ) , 2048 - ( SCREEN_HEIGHT / 2 ) ) ;
40
- sys:: sceGuViewport ( 2048 , 2048 , SCREEN_WIDTH as i32 , SCREEN_HEIGHT as i32 ) ;
41
- sys:: sceGuScissor ( 0 , 0 , SCREEN_WIDTH as i32 , SCREEN_HEIGHT as i32 ) ;
42
- sys:: sceGuEnable ( GuState :: ScissorTest ) ;
43
- sys:: sceGuEnable ( GuState :: Texture2D ) ;
44
-
45
- sys:: sceGuTexMode ( TexturePixelFormat :: Psm8888 , 0 , 0 , 0 ) ;
46
- sys:: sceGuTexFunc ( TextureEffect :: Modulate , TextureColorComponent :: Rgb ) ;
47
- sys:: sceGuTexWrap ( GuTexWrapMode :: Repeat , GuTexWrapMode :: Repeat ) ;
48
-
49
- sys:: sceGuEnable ( GuState :: Blend ) ;
50
- sys:: sceGuBlendFunc ( BlendOp :: Add , BlendFactor :: SrcAlpha , BlendFactor :: OneMinusSrcAlpha , 0 , 0 ) ;
51
- sys:: sceGuAlphaFunc ( AlphaFunc :: Greater , 0 , 0xff ) ;
52
-
53
- sys:: sceGumMatrixMode ( MatrixMode :: View ) ;
54
- sys:: sceGumLoadIdentity ( ) ;
55
-
56
- sys:: sceGumMatrixMode ( MatrixMode :: Projection ) ;
57
- sys:: sceGumLoadIdentity ( ) ;
58
- sys:: sceGumOrtho ( 0.0 , 480.0 , 272.0 , 0.0 , -30.0 , 30.0 ) ;
59
-
60
- sys:: sceDisplayWaitVblankStart ( ) ;
61
- sys:: sceGuFinish ( ) ;
62
- sys:: sceGuSync ( GuSyncMode :: Finish , GuSyncBehavior :: Wait ) ;
63
- sys:: sceGuDisplay ( true ) ;
29
+ pub fn setup ( allocator : & mut psp:: vram_alloc:: SimpleVramAllocator ) {
30
+ unsafe {
31
+ let fbp0 = allocator. alloc_texture_pixels ( BUF_WIDTH , SCREEN_HEIGHT , TexturePixelFormat :: Psm8888 ) . as_mut_ptr_from_zero ( ) ;
32
+ let fbp1 = allocator. alloc_texture_pixels ( BUF_WIDTH , SCREEN_HEIGHT , TexturePixelFormat :: Psm8888 ) . as_mut_ptr_from_zero ( ) ;
33
+
34
+ sys:: sceGumLoadIdentity ( ) ;
35
+ sys:: sceGuInit ( ) ;
36
+
37
+ sys:: sceGuStart ( GuContextType :: Direct , & mut LIST . 0 as * mut [ u32 ; 0x40000 ] as * mut _ ) ;
38
+ sys:: sceGuDrawBuffer ( DisplayPixelFormat :: Psm8888 , fbp0 as _ , BUF_WIDTH as i32 ) ;
39
+ sys:: sceGuDispBuffer ( SCREEN_WIDTH as i32 , SCREEN_HEIGHT as i32 , fbp1 as _ , BUF_WIDTH as i32 ) ;
40
+ sys:: sceGuOffset ( 2048 - ( SCREEN_WIDTH / 2 ) , 2048 - ( SCREEN_HEIGHT / 2 ) ) ;
41
+ sys:: sceGuViewport ( 2048 , 2048 , SCREEN_WIDTH as i32 , SCREEN_HEIGHT as i32 ) ;
42
+ sys:: sceGuScissor ( 0 , 0 , SCREEN_WIDTH as i32 , SCREEN_HEIGHT as i32 ) ;
43
+ sys:: sceGuEnable ( GuState :: ScissorTest ) ;
44
+ sys:: sceGuEnable ( GuState :: Texture2D ) ;
45
+
46
+ sys:: sceGuTexMode ( TexturePixelFormat :: Psm8888 , 0 , 0 , 0 ) ;
47
+ sys:: sceGuTexFunc ( TextureEffect :: Modulate , TextureColorComponent :: Rgb ) ;
48
+ sys:: sceGuTexWrap ( GuTexWrapMode :: Repeat , GuTexWrapMode :: Repeat ) ;
49
+
50
+ sys:: sceGuEnable ( GuState :: Blend ) ;
51
+ sys:: sceGuBlendFunc ( BlendOp :: Add , BlendFactor :: SrcAlpha , BlendFactor :: OneMinusSrcAlpha , 0 , 0 ) ;
52
+ sys:: sceGuAlphaFunc ( AlphaFunc :: Greater , 0 , 0xff ) ;
53
+
54
+ sys:: sceGumMatrixMode ( MatrixMode :: View ) ;
55
+ sys:: sceGumLoadIdentity ( ) ;
56
+
57
+ sys:: sceGumMatrixMode ( MatrixMode :: Projection ) ;
58
+ sys:: sceGumLoadIdentity ( ) ;
59
+ sys:: sceGumOrtho ( 0.0 , 480.0 , 272.0 , 0.0 , -30.0 , 30.0 ) ;
60
+
61
+ sys:: sceDisplayWaitVblankStart ( ) ;
62
+ sys:: sceGuFinish ( ) ;
63
+ sys:: sceGuSync ( GuSyncMode :: Finish , GuSyncBehavior :: Wait ) ;
64
+ sys:: sceGuDisplay ( true ) ;
65
+ }
64
66
}
65
67
66
68
/// Clear the screen a particular colour.
67
69
///
68
70
/// # Parameters
69
71
///
70
72
/// - `color`: The colour to clear with, in big-endian ABGR, little endian RGBA.
71
- pub unsafe fn clear_color ( color : u32 ) {
72
- sys:: sceGuStart ( GuContextType :: Direct , & mut LIST . 0 as * mut [ u32 ; 0x40000 ] as * mut _ ) ;
73
- sys:: sceGuClearColor ( color) ;
74
- sys:: sceGuClear ( ClearBuffer :: COLOR_BUFFER_BIT | ClearBuffer :: FAST_CLEAR_BIT ) ;
75
- sys:: sceGuFinish ( ) ;
76
- sys:: sceGuSync ( GuSyncMode :: Finish , GuSyncBehavior :: Wait ) ;
73
+ pub fn clear_color ( color : u32 ) {
74
+ unsafe {
75
+ sys:: sceGuStart ( GuContextType :: Direct , & mut LIST . 0 as * mut [ u32 ; 0x40000 ] as * mut _ ) ;
76
+ sys:: sceGuClearColor ( color) ;
77
+ sys:: sceGuClear ( ClearBuffer :: COLOR_BUFFER_BIT | ClearBuffer :: FAST_CLEAR_BIT ) ;
78
+ sys:: sceGuFinish ( ) ;
79
+ sys:: sceGuSync ( GuSyncMode :: Finish , GuSyncBehavior :: Wait ) ;
80
+ }
77
81
}
78
82
79
83
/// Draw vertices to the screen.
@@ -87,36 +91,38 @@ pub unsafe fn clear_color(color: u32) {
87
91
/// - `texture_height`: Height of texture, must be power of 2.
88
92
/// - `scale_x`: Horizontal scale factor.
89
93
/// - `scale_y`: Vertical scale factor.
90
- pub unsafe fn draw_vertices (
94
+ pub fn draw_vertices (
91
95
vertices : & [ Align4 < Vertex > ] ,
92
96
texture : & [ u8 ] ,
93
97
texture_width : u32 ,
94
98
texture_height : u32 ,
95
99
scale_x : f32 ,
96
100
scale_y : f32 ,
97
101
) {
98
- sys:: sceGuStart ( GuContextType :: Direct , LIST . 0 . as_mut_ptr ( ) as * mut _ ) ;
99
-
100
- sys:: sceGumMatrixMode ( MatrixMode :: Model ) ;
101
- sys:: sceGumLoadIdentity ( ) ;
102
- sys:: sceGumScale ( & ScePspFVector3 { x : scale_x, y : scale_y, z : 1.0 } ) ;
103
-
104
- // setup texture
105
- sys:: sceGuTexImage ( MipmapLevel :: None , texture_width as i32 , texture_height as i32 , texture_width as i32 , ( * texture) . as_ptr ( ) as _ ) ;
106
- sys:: sceGuTexScale ( 1.0 /texture_width as f32 , 1.0 /texture_height as f32 ) ;
107
-
108
- sys:: sceKernelDcacheWritebackInvalidateAll ( ) ;
109
-
110
- // draw
111
- sys:: sceGumDrawArray (
112
- GuPrimitive :: Sprites ,
113
- VertexType :: TEXTURE_32BITF | VertexType :: COLOR_8888 | VertexType :: VERTEX_32BITF | VertexType :: TRANSFORM_3D ,
114
- ( * vertices) . len ( ) as i32 ,
115
- ptr:: null_mut ( ) ,
116
- ( * vertices) . as_ptr ( ) as _ ,
117
- ) ;
118
- sys:: sceGuFinish ( ) ;
119
- sys:: sceGuSync ( GuSyncMode :: Finish , GuSyncBehavior :: Wait ) ;
102
+ unsafe {
103
+ sys:: sceGuStart ( GuContextType :: Direct , LIST . 0 . as_mut_ptr ( ) as * mut _ ) ;
104
+
105
+ sys:: sceGumMatrixMode ( MatrixMode :: Model ) ;
106
+ sys:: sceGumLoadIdentity ( ) ;
107
+ sys:: sceGumScale ( & ScePspFVector3 { x : scale_x, y : scale_y, z : 1.0 } ) ;
108
+
109
+ // setup texture
110
+ sys:: sceGuTexImage ( MipmapLevel :: None , texture_width as i32 , texture_height as i32 , texture_width as i32 , ( * texture) . as_ptr ( ) as _ ) ;
111
+ sys:: sceGuTexScale ( 1.0 /texture_width as f32 , 1.0 /texture_height as f32 ) ;
112
+
113
+ sys:: sceKernelDcacheWritebackInvalidateAll ( ) ;
114
+
115
+ // draw
116
+ sys:: sceGumDrawArray (
117
+ GuPrimitive :: Sprites ,
118
+ VertexType :: TEXTURE_32BITF | VertexType :: COLOR_8888 | VertexType :: VERTEX_32BITF | VertexType :: TRANSFORM_3D ,
119
+ ( * vertices) . len ( ) as i32 ,
120
+ ptr:: null_mut ( ) ,
121
+ ( * vertices) . as_ptr ( ) as _ ,
122
+ ) ;
123
+ sys:: sceGuFinish ( ) ;
124
+ sys:: sceGuSync ( GuSyncMode :: Finish , GuSyncBehavior :: Wait ) ;
125
+ }
120
126
}
121
127
122
128
/// Draws text at a given point on the screen in a given colour.
@@ -127,14 +133,18 @@ pub unsafe fn draw_vertices(
127
133
/// - `y`: vertical position
128
134
/// - `color`: Colour of text, in big-endian ABGR, little-endian RGBA.
129
135
/// - `text`: ASCII text as an &str.
130
- pub unsafe fn draw_text_at ( x : i32 , y : i32 , color : u32 , text : & str ) {
131
- sys:: sceGuDebugPrint ( x, y, color, ( text. to_string ( ) + "\0 " ) . as_bytes ( ) . as_ptr ( ) ) ;
132
- sys:: sceGuDebugFlush ( ) ;
136
+ pub fn draw_text_at ( x : i32 , y : i32 , color : u32 , text : & str ) {
137
+ unsafe {
138
+ sys:: sceGuDebugPrint ( x, y, color, ( text. to_string ( ) + "\0 " ) . as_bytes ( ) . as_ptr ( ) ) ;
139
+ sys:: sceGuDebugFlush ( ) ;
140
+ }
133
141
}
134
142
135
143
/// Finishes drawing by waiting for VBlank and swapping the Draw and Display buffer
136
144
/// pointers.
137
- pub unsafe fn finish_frame ( ) {
138
- sys:: sceDisplayWaitVblankStart ( ) ;
139
- sys:: sceGuSwapBuffers ( ) ;
145
+ pub fn finish_frame ( ) {
146
+ unsafe {
147
+ sys:: sceDisplayWaitVblankStart ( ) ;
148
+ sys:: sceGuSwapBuffers ( ) ;
149
+ }
140
150
}
0 commit comments