Rev 5235 | Rev 5260 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5235 | alpine | 1 | #include "rskos.h" |
2 | |||
3 | #ifndef RS_KOS |
||
4 | |||
5 | #include "rs/rstexture.h" |
||
6 | #include "rs/rsgl.h" |
||
7 | #include "rs/rsshader.h" |
||
8 | |||
9 | #include "rs/rsaudio.h" |
||
10 | |||
11 | #include |
||
12 | #include |
||
13 | |||
14 | //unsigned char* rskos_malloc(unsigned int bytes_count) { |
||
15 | // return malloc(bytes_count); |
||
16 | //}; |
||
17 | // |
||
18 | //void rskos_free(unsigned char* pointer) { |
||
19 | // free(pointer); |
||
20 | //}; |
||
21 | // |
||
22 | //void rskos_memset(unsigned char* pointer, unsigned char value, unsigned int bytes_count) { |
||
23 | // memset(pointer, value, bytes_count); |
||
24 | //}; |
||
25 | // |
||
26 | //void rskos_memcpy(unsigned char* dest, unsigned char* src, unsigned int bytes_count) { |
||
27 | // memcpy(dest, src, bytes_count); |
||
28 | //}; |
||
29 | |||
30 | |||
31 | |||
32 | unsigned int rskos_get_time() { |
||
33 | |||
34 | return rs_app.app_time; |
||
35 | |||
36 | }; |
||
37 | |||
5239 | alpine | 38 | void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer, int image_format) { |
39 | |||
40 | int bpp = image_format == RSKOS_BGR ? 3 : 4; |
||
5235 | alpine | 41 | |
5239 | alpine | 42 | // int i, j; |
43 | // |
||
44 | // for (i = 0; i < h*k_scale; i++) { |
||
45 | // for (j = 0; j < w*k_scale; j++) { |
||
46 | // scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0]; |
||
47 | // scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1]; |
||
48 | // scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2]; |
||
49 | // }; |
||
50 | // }; |
||
5235 | alpine | 51 | |
52 | |||
53 | |||
54 | |||
55 | |||
56 | |||
57 | |||
58 | glViewport(0, 0, rs_app.width, rs_app.height); |
||
59 | glClearColor( 0.2596078431, 0.2815686275, 0.3929411765, 1.0 ); // #98d0ed |
||
60 | //glClearColor( 0.0, 0.4, 0.1 + 0.5*0.001*(rs_get_time()%1024) , 1.0 ); |
||
61 | |||
62 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // <-- FBO |
||
63 | |||
64 | |||
65 | |||
66 | |||
67 | |||
68 | |||
5239 | alpine | 69 | //rs_tx_t tex = rs_tx_create_from_data(w*k_scale, h*k_scale, 3, 0, 1, scaled_buffer); |
70 | rs_tx_t tex = rs_tx_create_from_data(w, h, bpp, 0, 1, data); |
||
5235 | alpine | 71 | |
72 | glBindTexture(GL_TEXTURE_2D, tex); |
||
73 | |||
74 | rs_sh_use(DefaultShader); |
||
75 | |||
76 | rs_mx_identity_modelview(); |
||
77 | rs_mx_ortho_proj(); |
||
78 | |||
79 | glUniformMatrix4fv( DefaultShader[RS_SH_PROJ_ID], 1, GL_FALSE, rs_reg.mx_proj ); |
||
80 | glUniformMatrix4fv( DefaultShader[RS_SH_MODELVIEW_ID], 1, GL_FALSE, rs_reg.mx_modelview ); |
||
81 | |||
82 | glrsDrawRect(x, y, x+w*k_scale, y+h*k_scale, DefaultShader[RS_SH_POS_ID], DefaultShader[RS_SH_UV_ID]); |
||
83 | |||
84 | rs_tx_destroy(&tex); |
||
85 | |||
86 | |||
87 | |||
88 | |||
89 | rsDoSwapBuffers(); |
||
90 | |||
91 | }; |
||
92 | |||
93 | |||
94 | void rskos_resize_window(int w, int h) { |
||
95 | // |
||
96 | }; |
||
97 | |||
98 | void rskos_get_screen_size(unsigned int *pw, unsigned int *ph) { |
||
99 | *pw = rs_app.width + 50; |
||
100 | *ph = rs_app.height + 50; |
||
101 | }; |
||
102 | |||
103 | void rskos_exit() { |
||
104 | rsAppExit(); |
||
105 | }; |
||
106 | |||
107 | //void rskos_snd_init() { |
||
108 | // // |
||
109 | // |
||
110 | // rs_audio |
||
111 | // |
||
112 | //}; |
||
113 | |||
114 | void rskos_snd_create_buffer(SNDBUF *hbuf, signed short *buffer, unsigned int length) { |
||
115 | // |
||
116 | |||
117 | rs_sound_t *snd = malloc( sizeof(rs_sound_t) ); |
||
118 | rs_sound_create_from_data(snd, length*2, (unsigned char*) buffer); |
||
119 | |||
120 | *hbuf = snd; |
||
121 | |||
122 | }; |
||
123 | |||
124 | void rskos_snd_update_buffer(SNDBUF *hbuf, signed short *buffer, unsigned int length) { |
||
125 | |||
126 | rs_sound_destroy(*hbuf); |
||
127 | rskos_snd_create_buffer(hbuf, buffer, length); |
||
128 | |||
129 | }; |
||
130 | |||
131 | void rskos_snd_play(SNDBUF *hbuf, unsigned int mode) { |
||
132 | |||
133 | rs_sound_play(*hbuf); |
||
134 | |||
135 | }; |
||
136 | |||
137 | void rskos_snd_stop(SNDBUF *hbuf) { |
||
138 | rs_sound_stop(*hbuf); |
||
139 | }; |
||
140 | |||
141 | |||
142 | #else |
||
143 | |||
144 | #include "rs/rsplatform.h" |
||
145 | |||
146 | |||
147 | unsigned int rskos_get_time() { |
||
148 | return 1; |
||
149 | }; |
||
150 | |||
5239 | alpine | 151 | void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer, int image_format) { |
5235 | alpine | 152 | |
153 | // unsigned char *scaled_buffer = malloc(w*k_scale*h*k_scale*3); |
||
5239 | alpine | 154 | |
155 | |||
156 | // if (scaled_buffer != NULL) { |
||
157 | |||
158 | int i, j; |
||
159 | |||
160 | for (i = 0; i < h*k_scale; i++) { |
||
161 | for (j = 0; j < w*k_scale; j++) { |
||
162 | scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0]; |
||
163 | scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1]; |
||
164 | scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2]; |
||
165 | }; |
||
5235 | alpine | 166 | }; |
167 | |||
5239 | alpine | 168 | kol_paint_image(0, 0, w*k_scale, h*k_scale, scaled_buffer); |
169 | // } |
||
170 | // else { |
||
171 | // //kol_paint_image_pal(0, 0, w, h, data, &image_format) |
||
172 | // h/=4; |
||
173 | // asm volatile ("int $0x40"::"a"(65), "b"(data), "c"(w*65536+h), "d"(0*65536+0), "D"(0), "S"(24) ); |
||
174 | //// asm volatile ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(data)); |
||
175 | // }; |
||
176 | // |
||
177 | //// free(image_data); |
||
5235 | alpine | 178 | |
179 | |||
180 | |||
181 | }; |
||
182 | |||
183 | void rskos_resize_window(int w, int h) { |
||
184 | |||
185 | // !!!!!!!!! add define-fix here |
||
186 | |||
187 | w = -1 + w + 10; // 2 x 5px border |
||
188 | h = -1 + kol_skin_height() + h + 5; // bottom 5px border |
||
189 | |||
190 | asm volatile ("int $0x40"::"a"(67), "b"(-1), "c"(-1), "d"(w), "S"(h)); |
||
191 | |||
192 | }; |
||
193 | |||
194 | void rskos_get_screen_size(unsigned int *pw, unsigned int *ph) { |
||
195 | kol_screen_get_size(pw, ph); |
||
196 | }; |
||
197 | |||
198 | void rskos_exit() { |
||
199 | kol_exit(); |
||
200 | }; |
||
201 | |||
202 | #define fmt PCM_1_16_16 // 1 channel, 16 bit per sample, 16 kHz |
||
203 | |||
204 | void rskos_snd_create_buffer(SNDBUF *phbuf, signed short *buffer, unsigned int length_samples) { |
||
205 | unsigned int snd_format = fmt; |
||
206 | CreateBuffer(snd_format|PCM_STATIC, length_samples*2, phbuf); |
||
207 | int offset = 0; |
||
208 | SetBuffer(*phbuf, (void*)buffer, offset, length_samples*2); |
||
209 | }; |
||
210 | |||
211 | void rskos_snd_update_buffer(SNDBUF *phbuf, signed short *buffer, unsigned int length_samples) { |
||
212 | unsigned int snd_format = fmt; |
||
213 | // CreateBuffer(snd_format|PCM_STATIC, length, phbuf); |
||
214 | int offset = 0; |
||
215 | SetBuffer(*phbuf, (void*)buffer, offset, length_samples*2); |
||
216 | }; |
||
217 | |||
218 | void rskos_snd_play(SNDBUF *phbuf, unsigned int mode) { |
||
219 | SetBufferPos(*phbuf, 0); |
||
220 | PlayBuffer(*phbuf, 0); |
||
221 | }; |
||
222 | |||
223 | void rskos_snd_stop(SNDBUF *phbuf) { |
||
224 | StopBuffer(*phbuf); |
||
225 | }; |
||
226 | |||
227 | |||
228 | |||
229 | #endif>>-->>> |