1 /*  RetroArch - A frontend for libretro.
2  *  Copyright (C) 2014-2017 - Ali Bouahl
3  *
4  *  RetroArch is free software: you can redistribute it and/or modify it under the terms
5  *  of the GNU General Public License as published by the Free Software Found-
6  *  ation, either version 3 of the License, or (at your option) any later version.
7  *
8  *  RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10  *  PURPOSE.  See the GNU General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License along with RetroArch.
13  *  If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef CTR_COMMON_H__
17 #define CTR_COMMON_H__
18 
19 #include <3ds.h>
20 #include <retro_inline.h>
21 
22 #define COLOR_ABGR(r, g, b, a) (((unsigned)(a) << 24) | ((b) << 16) | ((g) << 8) | ((r) << 0))
23 
24 #define CTR_TOP_FRAMEBUFFER_WIDTH   400
25 #define CTR_TOP_FRAMEBUFFER_HEIGHT  240
26 
27 #ifdef USE_CTRULIB_2
28 extern u8* gfxTopLeftFramebuffers[2];
29 extern u8* gfxTopRightFramebuffers[2];
30 extern u8* gfxBottomFramebuffers[2];
31 #endif
32 
33 extern PrintConsole* ctrConsole;
34 
35 extern const u8 ctr_sprite_shbin[];
36 extern const u32 ctr_sprite_shbin_size;
37 
38 typedef struct
39 {
40    float v;
41    float u;
42    float y;
43    float x;
44 } ctr_scale_vector_t;
45 
46 typedef struct
47 {
48    s16 x0, y0, x1, y1;
49    s16 u0, v0, u1, v1;
50 } ctr_vertex_t;
51 
52 typedef enum
53 {
54 	CTR_VIDEO_MODE_3D = 0,
55 	CTR_VIDEO_MODE_2D,
56 	CTR_VIDEO_MODE_2D_400X240,
57 	CTR_VIDEO_MODE_2D_800X240,
58 	CTR_VIDEO_MODE_LAST
59 } ctr_video_mode_enum;
60 
61 typedef struct ctr_video
62 {
63    struct
64    {
65       struct
66       {
67          void* left;
68          void* right;
69       }top;
70    }drawbuffers;
71    void* depthbuffer;
72 
73    struct
74    {
75       uint32_t* display_list;
76       int display_list_size;
77       void* texture_linear;
78       void* texture_swizzled;
79       int texture_width;
80       int texture_height;
81       ctr_scale_vector_t scale_vector;
82       ctr_vertex_t* frame_coords;
83    }menu;
84 
85    uint32_t* display_list;
86    int display_list_size;
87    void* texture_linear;
88    void* texture_swizzled;
89    int texture_width;
90    int texture_height;
91 
92    ctr_scale_vector_t scale_vector;
93    ctr_vertex_t* frame_coords;
94 
95    DVLB_s*         dvlb;
96    shaderProgram_s shader;
97 
98    video_viewport_t vp;
99 
100    bool rgb32;
101    bool vsync;
102    bool smooth;
103    bool menu_texture_enable;
104    bool menu_texture_frame_enable;
105    unsigned rotation;
106    bool keep_aspect;
107    bool should_resize;
108    bool msg_rendering_enabled;
109    bool supports_parallax_disable;
110    bool enable_3d;
111 
112 #ifdef HAVE_OVERLAY
113    struct ctr_overlay_data *overlay;
114    unsigned overlays;
115    bool overlay_enabled;
116    bool overlay_full_screen;
117 #endif
118 
119    void* empty_framebuffer;
120 
121    aptHookCookie lcd_aptHook;
122    ctr_video_mode_enum video_mode;
123    int current_buffer_top;
124 
125    bool p3d_event_pending;
126    bool ppf_event_pending;
127    volatile bool vsync_event_pending;
128 
129    struct
130    {
131       ctr_vertex_t* buffer;
132       ctr_vertex_t* current;
133       int size;
134    }vertex_cache;
135 
136 } ctr_video_t;
137 
138 typedef struct ctr_texture
139 {
140    int width;
141    int height;
142    int active_width;
143    int active_height;
144 
145    enum texture_filter_type type;
146    void* data;
147 } ctr_texture_t;
148 
149 #ifdef HAVE_OVERLAY
150 struct ctr_overlay_data
151 {
152    ctr_texture_t texture;
153    ctr_vertex_t* frame_coords;
154    ctr_scale_vector_t scale_vector;
155    float alpha_mod;
156 };
157 #endif
158 
ctr_set_scale_vector(ctr_scale_vector_t * vec,int viewport_width,int viewport_height,int texture_width,int texture_height)159 static INLINE void ctr_set_scale_vector(ctr_scale_vector_t* vec,
160       int viewport_width, int viewport_height,
161       int texture_width, int texture_height)
162 {
163    vec->x = -2.0 / viewport_width;
164    vec->y = -2.0 / viewport_height;
165    vec->u =  1.0 / texture_width;
166    vec->v = -1.0 / texture_height;
167 }
168 
169 #endif // CTR_COMMON_H__
170