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