1 #ifndef VITA2D_H
2 #define VITA2D_H
3 
4 #include <psp2/gxm.h>
5 #include <psp2/types.h>
6 #include <psp2/kernel/sysmem.h>
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #define RGBA8(r,g,b,a) ((((a)&0xFF)<<24) | (((b)&0xFF)<<16) | (((g)&0xFF)<<8) | (((r)&0xFF)<<0))
13 
14 typedef enum
15 {
16 	VITA2D_VIDEO_MODE_960x544 = 0,
17 	VITA2D_VIDEO_MODE_1280x720
18 } vita2d_video_mode;
19 
20 typedef struct vita2d_video_mode_data {
21 	int width;
22    int height;
23    int stride;
24 } vita2d_video_mode_data;
25 
26 typedef struct vita2d_clear_vertex {
27 	float x;
28 	float y;
29 } vita2d_clear_vertex;
30 
31 typedef struct vita2d_color_vertex {
32 	float x;
33 	float y;
34 	float z;
35 	unsigned int color;
36 } vita2d_color_vertex;
37 
38 typedef struct vita2d_texture_vertex {
39 	float x;
40 	float y;
41 	float z;
42 	float u;
43 	float v;
44 } vita2d_texture_vertex;
45 
46 typedef struct vita2d_texture_tint_vertex {
47 	float x;
48 	float y;
49 	float z;
50 	float u;
51 	float v;
52 	float r;
53 	float g;
54 	float b;
55 	float a;
56 } vita2d_texture_tint_vertex;
57 
58 typedef struct vita2d_texture {
59 	SceGxmTexture gxm_tex;
60 	SceUID data_UID;
61 	SceUID palette_UID;
62 	SceGxmRenderTarget *gxm_rtgt;
63 	SceGxmColorSurface gxm_sfc;
64 	SceGxmDepthStencilSurface gxm_sfd;
65 	SceUID depth_UID;
66 } vita2d_texture;
67 
68 typedef struct vita2d_font vita2d_font;
69 typedef struct vita2d_pgf vita2d_pgf;
70 
71 int vita2d_init();
72 int vita2d_init_advanced(unsigned int temp_pool_size);
73 int vita2d_init_advanced_with_msaa(unsigned int temp_pool_size, SceGxmMultisampleMode msaa, vita2d_video_mode video_mode);
74 void vita2d_wait_rendering_done();
75 int vita2d_fini();
76 
77 void vita2d_clear_screen();
78 void vita2d_swap_buffers();
79 
80 void vita2d_start_drawing();
81 void vita2d_start_drawing_advanced(vita2d_texture *target, unsigned int flags);
82 void vita2d_end_drawing();
83 
84 int vita2d_common_dialog_update();
85 
86 void vita2d_set_clear_color(unsigned int color);
87 unsigned int vita2d_get_clear_color();
88 
89 vita2d_video_mode_data vita2d_get_video_mode_data();
90 
91 void vita2d_set_vblank_wait(int enable);
92 void *vita2d_get_current_fb();
93 SceGxmContext *vita2d_get_context();
94 SceGxmShaderPatcher *vita2d_get_shader_patcher();
95 const uint16_t *vita2d_get_linear_indices();
96 
97 void vita2d_set_region_clip(SceGxmRegionClipMode mode, unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max);
98 void vita2d_enable_clipping();
99 void vita2d_disable_clipping();
100 int vita2d_get_clipping_enabled();
101 void vita2d_set_clip_rectangle(int x_min, int y_min, int x_max, int y_max);
102 void vita2d_get_clip_rectangle(int *x_min, int *y_min, int *x_max, int *y_max);
103 void vita2d_set_blend_mode_add(int enable);
104 void vita2d_set_viewport(int x, int y, int width, int height);
105 
106 void *vita2d_pool_malloc(unsigned int size);
107 void *vita2d_pool_memalign(unsigned int size, unsigned int alignment);
108 unsigned int vita2d_pool_free_space();
109 void vita2d_pool_reset();
110 
111 void vita2d_draw_pixel(float x, float y, unsigned int color);
112 void vita2d_draw_line(float x0, float y0, float x1, float y1, unsigned int color);
113 void vita2d_draw_rectangle(float x, float y, float w, float h, unsigned int color);
114 void vita2d_draw_fill_circle(float x, float y, float radius, unsigned int color);
115 void vita2d_draw_array(SceGxmPrimitiveType mode, const vita2d_color_vertex *vertices, size_t count);
116 
117 void vita2d_texture_set_alloc_memblock_type(SceKernelMemBlockType type);
118 SceKernelMemBlockType vita2d_texture_get_alloc_memblock_type();
119 vita2d_texture *vita2d_create_empty_texture(unsigned int w, unsigned int h);
120 vita2d_texture *vita2d_create_empty_texture_format(unsigned int w, unsigned int h, SceGxmTextureFormat format);
121 vita2d_texture *vita2d_create_empty_texture_rendertarget(unsigned int w, unsigned int h, SceGxmTextureFormat format);
122 
123 void vita2d_free_texture(vita2d_texture *texture);
124 
125 unsigned int vita2d_texture_get_width(const vita2d_texture *texture);
126 unsigned int vita2d_texture_get_height(const vita2d_texture *texture);
127 unsigned int vita2d_texture_get_stride(const vita2d_texture *texture);
128 SceGxmTextureFormat vita2d_texture_get_format(const vita2d_texture *texture);
129 void *vita2d_texture_get_datap(const vita2d_texture *texture);
130 void *vita2d_texture_get_palette(const vita2d_texture *texture);
131 SceGxmTextureFilter vita2d_texture_get_min_filter(const vita2d_texture *texture);
132 SceGxmTextureFilter vita2d_texture_get_mag_filter(const vita2d_texture *texture);
133 void vita2d_texture_set_filters(vita2d_texture *texture, SceGxmTextureFilter min_filter, SceGxmTextureFilter mag_filter);
134 
135 void vita2d_draw_texture(const vita2d_texture *texture, float x, float y);
136 void vita2d_draw_texture_rotate(const vita2d_texture *texture, float x, float y, float rad);
137 void vita2d_draw_texture_rotate_hotspot(const vita2d_texture *texture, float x, float y, float rad, float center_x, float center_y);
138 void vita2d_draw_texture_scale(const vita2d_texture *texture, float x, float y, float x_scale, float y_scale);
139 void vita2d_draw_texture_part(const vita2d_texture *texture, float x, float y, float tex_x, float tex_y, float tex_w, float tex_h);
140 void vita2d_draw_texture_part_scale(const vita2d_texture *texture, float x, float y, float tex_x, float tex_y, float tex_w, float tex_h, float x_scale, float y_scale);
141 void vita2d_draw_texture_scale_rotate_hotspot(const vita2d_texture *texture, float x, float y, float x_scale, float y_scale, float rad, float center_x, float center_y);
142 void vita2d_draw_texture_scale_rotate(const vita2d_texture *texture, float x, float y, float x_scale, float y_scale, float rad);
143 void vita2d_draw_texture_part_scale_rotate(const vita2d_texture *texture, float x, float y, float tex_x, float tex_y, float tex_w, float tex_h, float x_scale, float y_scale, float rad);
144 
145 void vita2d_draw_texture_tint(const vita2d_texture *texture, float x, float y, unsigned int color);
146 void vita2d_draw_texture_tint_rotate(const vita2d_texture *texture, float x, float y, float rad, unsigned int color);
147 void vita2d_draw_texture_tint_rotate_hotspot(const vita2d_texture *texture, float x, float y, float rad, float center_x, float center_y, unsigned int color);
148 void vita2d_draw_texture_tint_scale(const vita2d_texture *texture, float x, float y, float x_scale, float y_scale, const float *color);
149 void vita2d_draw_texture_tint_part(const vita2d_texture *texture, float x, float y, float tex_x, float tex_y, float tex_w, float tex_h, unsigned int color);
150 void vita2d_draw_texture_tint_part_scale(const vita2d_texture *texture, float x, float y, float tex_x, float tex_y, float tex_w, float tex_h, float x_scale, float y_scale, unsigned int color);
151 void vita2d_draw_texture_tint_scale_rotate_hotspot(const vita2d_texture *texture, float x, float y, float x_scale, float y_scale, float rad, float center_x, float center_y, unsigned int color);
152 void vita2d_draw_texture_tint_scale_rotate(const vita2d_texture *texture, float x, float y, float x_scale, float y_scale, float rad, unsigned int color);
153 void vita2d_draw_texture_part_tint_scale_rotate(const vita2d_texture *texture, float x, float y, float tex_x, float tex_y, float tex_w, float tex_h, float x_scale, float y_scale, float rad, unsigned int color);
154 void vita2d_draw_array_textured(const vita2d_texture *texture, SceGxmPrimitiveType mode, const vita2d_texture_vertex *vertices, size_t count, unsigned int color);
155 void vita2d_draw_array_textured_mat(const vita2d_texture *texture, const vita2d_texture_tint_vertex *vertices, size_t count, float *mat);
156 
157 /** ADVANCED **/
158 void vita2d_texture_set_wvp(float x, float y, float width, float height);
159 void vita2d_texture_set_program();
160 void vita2d_texture_set_tint_program();
161 void vita2d_texture_set_tint_color_uniform(unsigned int color);
162 void vita2d_draw_texture_part_generic(const vita2d_texture *texture, SceGxmPrimitiveType type, vita2d_texture_vertex *vertices, unsigned int num_vertices);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif
169