Subversion Repositories Kolibri OS

Rev

Rev 4517 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "render.h"
  6. #include <kos32sys.h>
  7.  
  8. void render_swap_and_blit(struct render *render)
  9. {
  10.     char proc_info[1024];
  11.  
  12.     EGLContext context;
  13.     EGLSurface draw, read;
  14.     int winx, winy;
  15.  
  16.     float dst_xscale, dst_yscale;
  17.     float *vertices  = render->vertices;
  18.     float *texcoords = render->texcoords;
  19.     int r, b;
  20.  
  21.     if(render == NULL)
  22.         return;
  23.  
  24.     get_proc_info(proc_info);
  25.  
  26.     winx = *(uint32_t*)(proc_info+34);
  27.     winy = *(uint32_t*)(proc_info+38);
  28.  
  29.     context = eglGetCurrentContext();
  30.     draw = eglGetCurrentSurface(EGL_DRAW);
  31.     read = eglGetCurrentSurface(EGL_READ);
  32.  
  33.     eglSwapBuffers(render->dpy,draw);
  34.  
  35.     if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context))
  36.     {
  37.         printf("failed to make window current");
  38.         goto err1;
  39.     };
  40.  
  41.     glUseProgram(render->blit_prog);
  42.     glUniform1i(render->sampler, 0);
  43.  
  44.     glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices);
  45.     glEnableVertexAttribArray(0);
  46.  
  47.     glActiveTexture(GL_TEXTURE0);
  48.     glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]);
  49.     glTexParameteri(GL_TEXTURE_2D,
  50.                   GL_TEXTURE_MIN_FILTER,
  51.                   GL_NEAREST);
  52.     glTexParameteri(GL_TEXTURE_2D,
  53.                   GL_TEXTURE_MAG_FILTER,
  54.                   GL_NEAREST);
  55.  
  56.     glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords);
  57.     glEnableVertexAttribArray(1);
  58.  
  59.     dst_xscale = 1.0/render->scr_width;
  60.     dst_yscale = 1.0/render->scr_height;
  61.  
  62.     r = winx + render->dx + render->width;
  63.     b = winy + render->dy + render->height;
  64.  
  65.     float t0, t1, t2, t5;
  66.  
  67.     vertices[0]     = t0 = 2*(winx+render->dx)*dst_xscale - 1.0;
  68.     vertices[1 * 2] = t2 = 2*r*dst_xscale - 1.0;
  69.  
  70.     vertices[2 * 2] = t2;
  71.     vertices[3 * 2] = t0;
  72.  
  73.     vertices[1]     = t1 = 2*(winy+render->dy)*dst_yscale - 1.0;
  74.     vertices[2*2+1] = t5 = 2*b*dst_yscale - 1.0;
  75.     vertices[1*2+1] = t1;
  76.     vertices[3*2+1] = t5;
  77.  
  78.     texcoords[0]    = 0.0;
  79.     texcoords[1]    = 0.0;
  80.     texcoords[1*2]  = 1.0;
  81.     texcoords[1*2+1]= 0.0;
  82.     texcoords[2*2]  = 1.0;
  83.     texcoords[2*2+1]= 1.0;
  84.     texcoords[3*2]  = 0.0;
  85.     texcoords[3*2+1]= 1.0;
  86.  
  87.     glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  88.  
  89.     glDisableVertexAttribArray(0);
  90.     glDisableVertexAttribArray(1);
  91.     glDisable(GL_TEXTURE_2D);
  92.     glUseProgram(0);
  93.  
  94.     render->back_buffer++;
  95.     render->back_buffer&=1;
  96.  
  97. err1:
  98.     eglMakeCurrent(render->dpy, draw, read, context);
  99. }
  100.  
  101.