Subversion Repositories Kolibri OS

Rev

Rev 4502 | Rev 4523 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4502 Serge 1
#include 
2
#include 
3
#include 
4
 
5
#include "render.h"
6
#include 
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
 
4517 Serge 41
#if 0
4502 Serge 42
    glUseProgram(render->blit_prog);
43
    glUniform1i(render->sampler, 0);
44
 
45
    glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices);
46
    glEnableVertexAttribArray(0);
47
 
4517 Serge 48
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords);
49
    glEnableVertexAttribArray(1);
50
 
51
#endif
52
 
4502 Serge 53
    glActiveTexture(GL_TEXTURE0);
54
    glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]);
55
    glTexParameteri(GL_TEXTURE_2D,
56
                  GL_TEXTURE_MIN_FILTER,
57
                  GL_NEAREST);
58
    glTexParameteri(GL_TEXTURE_2D,
59
                  GL_TEXTURE_MAG_FILTER,
60
                  GL_NEAREST);
61
 
62
    dst_xscale = 1.0/render->scr_width;
63
    dst_yscale = 1.0/render->scr_height;
64
 
65
    r = winx + render->dx + render->width;
66
    b = winy + render->dy + render->height;
67
 
68
    float t0, t1, t2, t5;
69
 
70
    vertices[0]     = t0 = 2*(winx+render->dx)*dst_xscale - 1.0;
71
    vertices[1 * 2] = t2 = 2*r*dst_xscale - 1.0;
72
 
73
    vertices[2 * 2] = t2;
74
    vertices[3 * 2] = t0;
75
 
76
    vertices[1]     = t1 = 2*(winy+render->dy)*dst_yscale - 1.0;
77
    vertices[2*2+1] = t5 = 2*b*dst_yscale - 1.0;
78
    vertices[1*2+1] = t1;
79
    vertices[3*2+1] = t5;
80
 
81
    texcoords[0]    = 0.0;
82
    texcoords[1]    = 0.0;
83
    texcoords[1*2]  = 1.0;
84
    texcoords[1*2+1]= 0.0;
85
    texcoords[2*2]  = 1.0;
86
    texcoords[2*2+1]= 1.0;
87
    texcoords[3*2]  = 0.0;
88
    texcoords[3*2+1]= 1.0;
89
 
90
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
91
 
4517 Serge 92
//    glDisableVertexAttribArray(0);
93
//    glDisableVertexAttribArray(1);
94
//    glDisable(GL_TEXTURE_2D);
95
//    glUseProgram(0);
4502 Serge 96
 
97
    render->back_buffer++;
98
    render->back_buffer&=1;
99
 
100
err1:
101
    eglMakeCurrent(render->dpy, draw, read, context);
102
}
103