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