Subversion Repositories Kolibri OS

Rev

Rev 5291 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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 <stdlib.h>
  12. #include <string.h>
  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.     rs_sound_play_adv(*hbuf, mode==SND_MODE_LOOP ? 1 : 0, mode==SND_MODE_LOOP ? 0 : -1, 1.0);
  137.    
  138. };
  139.  
  140. void rskos_snd_stop(SNDBUF *hbuf) {
  141.     rs_sound_stop(*hbuf);
  142. };
  143.  
  144. void rskos_snd_check_loop(SNDBUF *phbuf) {
  145.     //
  146. };
  147.  
  148.  
  149. #else
  150.  
  151.     #include "rs/rsplatform.h"
  152.  
  153.  
  154.     unsigned int rskos_get_time() {
  155.         return kol_system_time_get() * 10; // (1/0.01 sec) * 10 = (1/0.001 sec) = 1 ms
  156.     };
  157.  
  158.     void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer) {
  159.  
  160. //        unsigned char *scaled_buffer = malloc(w*k_scale*h*k_scale*3);
  161.         int i, j;
  162.        
  163.         for (i = 0; i < h*k_scale; i++) {
  164.             for (j = 0; j < w*k_scale; j++) {
  165.                 scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0];
  166.                 scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1];
  167.                 scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2];
  168.             };
  169.         };
  170.  
  171.         kol_paint_image(0, 0, w*k_scale, h*k_scale, scaled_buffer);
  172.        
  173. //        free(image_data);
  174.        
  175.  
  176.  
  177.     };
  178.    
  179.     void rskos_resize_window(int w, int h) {
  180.        
  181.         // !!!!!!!!! add define-fix here
  182.        
  183.         w = -1 + w + 10; // 2 x 5px border
  184.         h = -1 + kol_skin_height() + h + 5; // bottom 5px border
  185.        
  186.         asm volatile ("int $0x40"::"a"(67), "b"(-1), "c"(-1), "d"(w), "S"(h));
  187.        
  188.     };
  189.    
  190.     void rskos_get_screen_size(unsigned int  *pw, unsigned int  *ph) {
  191.         kol_screen_get_size(pw, ph);
  192.     };
  193.    
  194.     void rskos_exit() {
  195.         kol_exit();
  196.     };
  197.  
  198.     #define fmt PCM_1_16_16 // 1 channel, 16 bit per sample, 16 kHz
  199.  
  200.     void rskos_snd_create_buffer(SNDBUF *phbuf, signed short *buffer, unsigned int length_samples) {
  201.         unsigned int snd_format = fmt;
  202.         CreateBuffer(snd_format|PCM_STATIC, length_samples*2, phbuf);
  203.         int offset = 0;
  204.         SetBuffer(*phbuf, (void*)buffer, offset, length_samples*2);
  205.     };
  206.    
  207.     void rskos_snd_update_buffer(SNDBUF *phbuf, signed short *buffer, unsigned int length_samples) {
  208.         unsigned int snd_format = fmt;
  209. //        CreateBuffer(snd_format|PCM_STATIC, length, phbuf);
  210.         int offset = 0;
  211.         SetBuffer(*phbuf, (void*)buffer, offset, length_samples*2);
  212.     };
  213.  
  214.     void rskos_snd_play(SNDBUF *phbuf, unsigned int mode) {
  215.         SetBufferPos(*phbuf, 0);
  216.         PlayBuffer(*phbuf, 0); // SND_MODE_LOOP
  217.     };
  218.  
  219.     void rskos_snd_stop(SNDBUF *phbuf) {
  220.         StopBuffer(*phbuf);
  221.     };
  222.    
  223.     void rskos_snd_check_loop(SNDBUF *phbuf) {
  224.         int offset;
  225.         int length;
  226.        
  227.         GetBufferPos(*phbuf, &offset);
  228.         //GetBufferSize(*phbuf, &length);
  229.        
  230.         // kol_board_puti(offset);
  231.         //kol_board_putc('\n');
  232.        
  233.         if (offset <= 0) {
  234.             SetBufferPos(*phbuf, 0); //offset - length/2);
  235.             PlayBuffer(*phbuf, 0); // SND_MODE_LOOP
  236.         };
  237.        
  238.     };
  239.  
  240.  
  241.  
  242. #endif
  243.