Subversion Repositories Kolibri OS

Rev

Rev 4517 | 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_blit(struct render *render, enum px_buffer buffer)
  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->tc_src;
  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.     if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context))
  34.     {
  35.         printf("failed to make window current");
  36.         goto err1;
  37.     };
  38.  
  39.     glUseProgram(render->blit_prog);
  40.     glUniform1i(render->sampler, 0);
  41.  
  42.     glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices);
  43.     glEnableVertexAttribArray(0);
  44.  
  45.     glActiveTexture(GL_TEXTURE0);
  46.     glBindTexture(GL_TEXTURE_2D, render->tx_buffers[buffer]);
  47.     glTexParameteri(GL_TEXTURE_2D,
  48.                   GL_TEXTURE_MIN_FILTER,
  49.                   GL_NEAREST);
  50.     glTexParameteri(GL_TEXTURE_2D,
  51.                   GL_TEXTURE_MAG_FILTER,
  52.                   GL_NEAREST);
  53.  
  54.     glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->tc_src);
  55.     glEnableVertexAttribArray(1);
  56.  
  57.     dst_xscale = 1.0/render->scr_width;
  58.     dst_yscale = 1.0/render->scr_height;
  59.  
  60.     r = winx + render->dx + render->width;
  61.     b = winy + render->dy + render->height;
  62.  
  63.     float t0, t1, t2, t5;
  64.  
  65.     vertices[0]     = t0 = 2*(winx+render->dx)*dst_xscale - 1.0;
  66.     vertices[1 * 2] = t2 = 2*r*dst_xscale - 1.0;
  67.  
  68.     vertices[2 * 2] = t2;
  69.     vertices[3 * 2] = t0;
  70.  
  71.     vertices[1]     = t1 = 2*(winy+render->dy)*dst_yscale - 1.0;
  72.     vertices[2*2+1] = t5 = 2*b*dst_yscale - 1.0;
  73.     vertices[1*2+1] = t1;
  74.     vertices[3*2+1] = t5;
  75.  
  76.     texcoords[0]    = 0.0;
  77.     texcoords[1]    = 0.0;
  78.     texcoords[1*2]  = 1.0;
  79.     texcoords[1*2+1]= 0.0;
  80.     texcoords[2*2]  = 1.0;
  81.     texcoords[2*2+1]= 1.0;
  82.     texcoords[3*2]  = 0.0;
  83.     texcoords[3*2+1]= 1.0;
  84.  
  85.     glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  86.  
  87.     glDisableVertexAttribArray(0);
  88.     glDisableVertexAttribArray(1);
  89.     glDisable(GL_TEXTURE_2D);
  90.     glUseProgram(0);
  91.  
  92. err1:
  93.     eglMakeCurrent(render->dpy, draw, read, context);
  94. }
  95.  
  96.