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