Rev 4517 | Rev 4525 | 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" |
||
4523 | Serge | 6 | #include |
4502 | Serge | 7 | #include |
8 | |||
4523 | Serge | 9 | static int drm_ioctl(int fd, unsigned long request, void *arg) |
10 | { |
||
11 | ioctl_t io; |
||
12 | |||
13 | io.handle = fd; |
||
14 | io.io_code = request; |
||
15 | io.input = arg; |
||
16 | io.inp_size = 64; |
||
17 | io.output = NULL; |
||
18 | io.out_size = 0; |
||
19 | |||
20 | return call_service(&io); |
||
21 | } |
||
22 | |||
4502 | Serge | 23 | void render_swap_and_blit(struct render *render) |
24 | { |
||
25 | char proc_info[1024]; |
||
4523 | Serge | 26 | struct drm_i915_mask_update update; |
4502 | Serge | 27 | |
28 | EGLContext context; |
||
29 | EGLSurface draw, read; |
||
4523 | Serge | 30 | int winx, winy, winw, winh; |
4502 | Serge | 31 | |
4523 | Serge | 32 | float xscale, yscale; |
4502 | Serge | 33 | float *vertices = render->vertices; |
4523 | Serge | 34 | float *texcoords = render->tc_src; |
4502 | Serge | 35 | int r, b; |
36 | |||
37 | if(render == NULL) |
||
38 | return; |
||
39 | |||
40 | get_proc_info(proc_info); |
||
41 | |||
42 | winx = *(uint32_t*)(proc_info+34); |
||
43 | winy = *(uint32_t*)(proc_info+38); |
||
4523 | Serge | 44 | winw = *(uint32_t*)(proc_info+42)+1; |
45 | winh = *(uint32_t*)(proc_info+46)+1; |
||
4502 | Serge | 46 | |
47 | context = eglGetCurrentContext(); |
||
48 | draw = eglGetCurrentSurface(EGL_DRAW); |
||
49 | read = eglGetCurrentSurface(EGL_READ); |
||
50 | |||
51 | eglSwapBuffers(render->dpy,draw); |
||
52 | |||
53 | if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context)) |
||
54 | { |
||
55 | printf("failed to make window current"); |
||
56 | goto err1; |
||
57 | }; |
||
58 | |||
4517 | Serge | 59 | #if 0 |
4502 | Serge | 60 | glUseProgram(render->blit_prog); |
61 | glUniform1i(render->sampler, 0); |
||
62 | |||
63 | glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices); |
||
64 | glEnableVertexAttribArray(0); |
||
65 | |||
4517 | Serge | 66 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords); |
67 | glEnableVertexAttribArray(1); |
||
68 | |||
69 | #endif |
||
70 | |||
4523 | Serge | 71 | update.handle = render->mask_handle; |
72 | update.bo_map = (int)render->mask_buffer; |
||
73 | drm_ioctl(render->fd, SRV_MASK_UPDATE, &update); |
||
74 | |||
4502 | Serge | 75 | glActiveTexture(GL_TEXTURE0); |
76 | glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]); |
||
77 | glTexParameteri(GL_TEXTURE_2D, |
||
78 | GL_TEXTURE_MIN_FILTER, |
||
79 | GL_NEAREST); |
||
80 | glTexParameteri(GL_TEXTURE_2D, |
||
81 | GL_TEXTURE_MAG_FILTER, |
||
82 | GL_NEAREST); |
||
83 | |||
84 | |||
4523 | Serge | 85 | xscale = 1.0/render->scr_width; |
86 | yscale = 1.0/render->scr_height; |
||
87 | |||
4502 | Serge | 88 | r = winx + render->dx + render->width; |
89 | b = winy + render->dy + render->height; |
||
90 | |||
91 | float t0, t1, t2, t5; |
||
92 | |||
4523 | Serge | 93 | vertices[0] = t0 = 2*(winx+render->dx)*xscale - 1.0; |
94 | vertices[1 * 2] = t2 = 2*r*xscale - 1.0; |
||
4502 | Serge | 95 | |
96 | vertices[2 * 2] = t2; |
||
97 | vertices[3 * 2] = t0; |
||
98 | |||
4523 | Serge | 99 | vertices[1] = t1 = 2*(winy+render->dy)*yscale - 1.0; |
100 | vertices[2*2+1] = t5 = 2*b*yscale - 1.0; |
||
4502 | Serge | 101 | vertices[1*2+1] = t1; |
102 | vertices[3*2+1] = t5; |
||
103 | |||
104 | texcoords[0] = 0.0; |
||
105 | texcoords[1] = 0.0; |
||
106 | texcoords[1*2] = 1.0; |
||
107 | texcoords[1*2+1]= 0.0; |
||
108 | texcoords[2*2] = 1.0; |
||
109 | texcoords[2*2+1]= 1.0; |
||
110 | texcoords[3*2] = 0.0; |
||
111 | texcoords[3*2+1]= 1.0; |
||
112 | |||
4523 | Serge | 113 | texcoords = render->tc_mask; |
114 | |||
115 | xscale = 1.0/winw; |
||
116 | yscale = 1.0/winh; |
||
117 | |||
118 | texcoords[0] = render->dx * xscale; |
||
119 | texcoords[1] = render->dy * yscale; |
||
120 | texcoords[1*2] = (render->dx+render->width)*xscale; |
||
121 | texcoords[1*2+1]= render->dy * yscale; |
||
122 | texcoords[2*2] = (render->dx+render->width)*xscale; |
||
123 | texcoords[2*2+1]= (render->dy+render->height)*yscale; |
||
124 | texcoords[3*2] = render->dx * xscale; |
||
125 | texcoords[3*2+1]= (render->dy+render->height)*yscale; |
||
126 | |||
127 | |||
4502 | Serge | 128 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
4523 | Serge | 129 | glFlush(); |
4502 | Serge | 130 | |
4517 | Serge | 131 | // glDisableVertexAttribArray(0); |
132 | // glDisableVertexAttribArray(1); |
||
133 | // glDisable(GL_TEXTURE_2D); |
||
134 | // glUseProgram(0); |
||
4502 | Serge | 135 | |
136 | render->back_buffer++; |
||
137 | render->back_buffer&=1; |
||
138 | |||
139 | err1: |
||
140 | eglMakeCurrent(render->dpy, draw, read, context); |
||
141 | } |
||
142 |