Rev 4495 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4495 | Rev 4498 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | #include "gbm.h" |
12 | #include "gbm.h" |
13 | #include |
13 | #include |
14 | #include |
14 | #include |
15 | #include |
15 | #include |
Line -... | Line 16... | ||
- | 16 | ||
- | 17 | enum px_buffer |
|
- | 18 | { |
|
- | 19 | PX_FRONT = 0, |
|
- | 20 | PX_BACK = 1 |
|
- | 21 | }; |
|
- | 22 | ||
- | 23 | struct render |
|
- | 24 | { |
|
- | 25 | EGLDisplay dpy; |
|
- | 26 | EGLContext context; |
|
- | 27 | GLuint framebuffer; |
|
- | 28 | EGLImageKHR front, back, screen; |
|
- | 29 | GLuint tx_buffers[2]; |
|
- | 30 | GLuint tx_screen; |
|
- | 31 | int back_buffer; |
|
- | 32 | GLuint blit_prog; |
|
- | 33 | GLint sampler; |
|
- | 34 | float vertices[8], texcoords[8]; |
|
- | 35 | }; |
|
- | 36 | ||
16 | 37 | ||
17 | EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
38 | EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
18 | int width, int height, int stride, int name); |
39 | int width, int height, int stride, int name); |
19 | GLuint create_framebuffer(int width, int height, GLuint *tex); |
40 | GLuint create_framebuffer(int width, int height, GLuint *tex); |
- | 41 | GLint create_shader(GLenum type, const char *source); |
|
- | 42 | struct render* create_render(EGLDisplay dpy, EGLSurface surface); |
|
- | 43 | void blit_texture(struct render *render, GLuint tex, int x, int y, int w, int h); |
|
Line 20... | Line 44... | ||
20 | GLint create_shader(GLenum type, const char *source); |
44 | void render_swap_buffers(struct render *render, int x, int y, int w, int h); |
21 | 45 | ||
22 | int main() |
46 | int main() |
23 | { |
47 | { |
- | 48 | struct gbm_device *gbm; |
|
Line 24... | Line 49... | ||
24 | struct gbm_device *gbm; |
49 | struct gbm_surface *gs; |
25 | struct gbm_surface *gs; |
50 | struct render *render; |
Line 26... | Line 51... | ||
26 | 51 | ||
27 | EGLDisplay dpy; |
52 | EGLDisplay dpy; |
28 | EGLint major, minor; |
- | |
- | 53 | EGLint major, minor; |
|
29 | 54 | ||
Line 30... | Line 55... | ||
30 | EGLContext context; |
55 | EGLContext context; |
31 | EGLSurface surface; |
56 | EGLSurface surface; |
32 | EGLImageKHR front,fb_image; |
- | |
33 | EGLConfig config; |
- | |
Line 34... | Line 57... | ||
34 | 57 | ||
Line 35... | Line 58... | ||
35 | EGLint config_attribs[32]; |
58 | EGLConfig config; |
36 | EGLint num_configs, i; |
59 | |
Line 83... | Line 106... | ||
83 | if (!context) |
106 | if (!context) |
84 | printf("failed to create context"); |
107 | printf("failed to create context"); |
Line 85... | Line 108... | ||
85 | 108 | ||
Line 86... | Line -... | ||
86 | gs = gbm_surface_create(gbm, 400, 300, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); |
- | |
87 | 109 | gs = gbm_surface_create(gbm, 400, 300, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); |
|
88 | 110 | ||
89 | BeginDraw(); |
111 | BeginDraw(); |
Line 90... | Line -... | ||
90 | DrawWindow(20, 20, 400+9, 300+24, "gl-render", 0x000000, 0x74); |
- | |
91 | EndDraw(); |
- | |
92 | 112 | DrawWindow(20, 20, 400+9, 300+24, "gl-render", 0x000000, 0x74); |
|
93 | sna_create_mask(); |
113 | EndDraw(); |
94 | 114 | ||
Line 95... | Line 115... | ||
95 | surface = eglCreateWindowSurface(dpy,config, (EGLNativeWindowType)gs, NULL); |
115 | surface = eglCreateWindowSurface(dpy,config, (EGLNativeWindowType)gs, NULL); |
96 | if (surface == EGL_NO_SURFACE) |
116 | if (surface == EGL_NO_SURFACE) |
Line 97... | Line -... | ||
97 | printf("failed to create surface"); |
- | |
98 | - | ||
99 | if (!eglMakeCurrent(dpy, surface, surface, context)) |
- | |
100 | printf("failed to make window current"); |
- | |
101 | - | ||
102 | - | ||
103 | front = eglGetBufferImage(dpy, surface, EGL_DRM_BUFFER_BACK); |
- | |
Line 104... | Line 117... | ||
104 | glGenTextures(1, &f_tex); |
117 | printf("failed to create surface"); |
105 | glBindTexture(GL_TEXTURE_2D, f_tex); |
118 | |
106 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); |
119 | if (!eglMakeCurrent(dpy, surface, surface, context)) |
107 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); |
120 | printf("failed to make window current"); |
Line 132... | Line 145... | ||
132 | glVertex3f( 0.1, -0.9, -30.0); |
145 | glVertex3f( 0.1, -0.9, -30.0); |
133 | glEnd(); |
146 | glEnd(); |
Line 134... | Line 147... | ||
134 | 147 | ||
Line 135... | Line 148... | ||
135 | glFlush(); |
148 | glFlush(); |
Line -... | Line 149... | ||
- | 149 | ||
- | 150 | asm volatile ("int3"); |
|
- | 151 | ||
- | 152 | render = create_render(dpy, surface); |
|
- | 153 | glViewport(0, 0, 1024, 768); |
|
- | 154 | glMatrixMode(GL_PROJECTION); |
|
- | 155 | glLoadIdentity(); |
|
- | 156 | glMatrixMode(GL_MODELVIEW); |
|
- | 157 | glLoadIdentity(); |
|
- | 158 | ||
- | 159 | render_swap_buffers(render, 20, 20, 400, 300); |
|
- | 160 | ||
- | 161 | glFinish(); |
|
- | 162 | eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
|
- | 163 | // eglDestroySurface(dpy, surface); |
|
- | 164 | // gbm_surface_destroy(gs); |
|
136 | 165 | eglDestroyContext(dpy, context); |
|
137 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
166 | eglTerminate(dpy); |
- | 167 | ||
- | 168 | while(1) |
|
- | 169 | { |
|
- | 170 | delay(1); |
|
- | 171 | } |
|
- | 172 | ||
- | 173 | return 0; |
|
- | 174 | } |
|
- | 175 | ||
- | 176 | int drmIoctl(int fd, unsigned long request, void *arg) |
|
- | 177 | { |
|
- | 178 | ioctl_t io; |
|
- | 179 | ||
- | 180 | io.handle = fd; |
|
- | 181 | io.io_code = request; |
|
- | 182 | io.input = arg; |
|
- | 183 | io.inp_size = 64; |
|
- | 184 | io.output = NULL; |
|
- | 185 | io.out_size = 0; |
|
- | 186 | ||
- | 187 | return call_service(&io); |
|
- | 188 | } |
|
- | 189 | ||
- | 190 | EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
|
- | 191 | int width, int height, int stride, int name) |
|
- | 192 | { |
|
- | 193 | EGLImageKHR image; |
|
- | 194 | EGLint attribs[] = { |
|
- | 195 | EGL_WIDTH, 0, |
|
- | 196 | EGL_HEIGHT, 0, |
|
- | 197 | EGL_DRM_BUFFER_STRIDE_MESA, 0, |
|
- | 198 | EGL_DRM_BUFFER_FORMAT_MESA, |
|
- | 199 | EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, |
|
- | 200 | EGL_DRM_BUFFER_USE_MESA, |
|
- | 201 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
|
- | 202 | EGL_DRM_BUFFER_USE_SCANOUT_MESA, |
|
- | 203 | EGL_NONE |
|
- | 204 | }; |
|
- | 205 | attribs[1] = width; |
|
- | 206 | attribs[3] = height; |
|
- | 207 | attribs[5] = stride/4; |
|
- | 208 | ||
- | 209 | printf("%s w:%d :%d pitch:%d handle %d\n", __FUNCTION__, |
|
- | 210 | width, height, stride, name); |
|
- | 211 | ||
- | 212 | image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA, |
|
- | 213 | (void *) (uintptr_t)name, attribs); |
|
- | 214 | ||
- | 215 | return image; |
|
- | 216 | } |
|
- | 217 | ||
- | 218 | GLint create_shader(GLenum type, const char *source) |
|
- | 219 | { |
|
- | 220 | GLint ok; |
|
- | 221 | GLint shader; |
|
138 | 222 | ||
- | 223 | shader = glCreateShader(type); |
|
- | 224 | if(shader == 0) |
|
- | 225 | goto err; |
|
- | 226 | ||
- | 227 | glShaderSource(shader, 1, (const GLchar **) &source, NULL); |
|
- | 228 | glCompileShader(shader); |
|
- | 229 | glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); |
|
- | 230 | if (!ok) { |
|
- | 231 | GLchar *info; |
|
- | 232 | GLint size; |
|
- | 233 | ||
- | 234 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &size); |
|
- | 235 | info = malloc(size); |
|
- | 236 | ||
- | 237 | glGetShaderInfoLog(shader, size, NULL, info); |
|
- | 238 | printf("Failed to compile %s: %s\n", |
|
- | 239 | type == GL_FRAGMENT_SHADER ? "FS" : "VS",info); |
|
- | 240 | printf("Program source:\n%s", source); |
|
139 | if(fd) |
241 | printf("GLSL compile failure\n"); |
- | 242 | free(info); |
|
- | 243 | glDeleteProgram(shader); |
|
- | 244 | shader = 0; |
|
- | 245 | } |
|
- | 246 | err: |
|
- | 247 | return shader; |
|
- | 248 | } |
|
- | 249 | ||
- | 250 | ||
- | 251 | struct render* create_render(EGLDisplay dpy, EGLSurface surface) |
|
- | 252 | { |
|
- | 253 | const char *vs_src = |
|
- | 254 | "attribute vec4 v_position;\n" |
|
- | 255 | "attribute vec4 v_texcoord0;\n" |
|
- | 256 | "varying vec2 source_texture;\n" |
|
- | 257 | "void main()\n" |
|
- | 258 | "{\n" |
|
- | 259 | " gl_Position = v_position;\n" |
|
- | 260 | " source_texture = v_texcoord0.xy;\n" |
|
- | 261 | "}\n"; |
|
- | 262 | ||
- | 263 | const char *fs_src = |
|
- | 264 | // "precision mediump float;\n" |
|
- | 265 | "varying vec2 source_texture;\n" |
|
- | 266 | "uniform sampler2D sampler;\n" |
|
- | 267 | "void main()\n" |
|
- | 268 | "{\n" |
|
- | 269 | " vec3 cg = texture2D(sampler, source_texture).rgb;\n" |
|
- | 270 | " gl_FragColor = vec4(cg.r,cg.g,cg.b,1.0);\n" |
|
- | 271 | "}\n"; |
|
- | 272 | EGLint config_attribs[14]; |
|
- | 273 | EGLConfig config; |
|
- | 274 | EGLint num_configs; |
|
140 | { |
275 | |
- | 276 | EGLContext context; |
|
- | 277 | ||
- | 278 | struct drm_i915_fb_info fb; |
|
- | 279 | GLint vs_shader, fs_shader; |
|
- | 280 | GLenum status; |
|
- | 281 | GLint ret; |
|
- | 282 | int fd; |
|
- | 283 | struct render *render; |
|
- | 284 | ||
Line 141... | Line 285... | ||
141 | int ret; |
285 | |
142 | GLenum status; |
286 | |
143 | struct drm_i915_fb_info fb; |
287 | fd = get_service("DISPLAY"); |
144 | 288 | ||
- | 289 | memset(&fb, 0, sizeof(fb)); |
|
- | 290 | ret = drmIoctl(fd, SRV_FBINFO, &fb); |
|
- | 291 | if( ret != 0 ) |
|
- | 292 | { printf("failed to get framebuffer info\n"); |
|
- | 293 | goto err; |
|
- | 294 | }; |
|
- | 295 | ||
- | 296 | render = (struct render*)malloc(sizeof(struct render)); |
|
- | 297 | if(render == NULL) |
|
- | 298 | goto err; |
|
- | 299 | ||
- | 300 | render->dpy = dpy; |
|
- | 301 | ||
- | 302 | render->front = eglGetBufferImage(dpy, surface, EGL_DRM_BUFFER_FRONT); |
|
- | 303 | if(render->front == EGL_NO_IMAGE_KHR) |
|
- | 304 | goto err1; |
|
- | 305 | ||
- | 306 | render->back = eglGetBufferImage(dpy, surface, EGL_DRM_BUFFER_BACK); |
|
- | 307 | if( render->back == EGL_NO_IMAGE_KHR) |
|
- | 308 | goto err2; |
|
- | 309 | ||
- | 310 | glGenTextures(2, render->tx_buffers); |
|
- | 311 | if(glGetError() != GL_NO_ERROR) |
|
- | 312 | goto err3; |
|
- | 313 | ||
- | 314 | glBindTexture(GL_TEXTURE_2D, render->tx_buffers[EGL_DRM_BUFFER_FRONT]); |
|
- | 315 | if(glGetError() != GL_NO_ERROR) |
|
- | 316 | goto err4; |
|
- | 317 | ||
- | 318 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); |
|
- | 319 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); |
|
- | 320 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->front); |
|
- | 321 | if(glGetError() != GL_NO_ERROR) |
|
- | 322 | goto err4; |
|
- | 323 | ||
- | 324 | glBindTexture(GL_TEXTURE_2D, render->tx_buffers[EGL_DRM_BUFFER_BACK]); |
|
- | 325 | if(glGetError() != GL_NO_ERROR) |
|
- | 326 | goto err4; |
|
- | 327 | ||
- | 328 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); |
|
- | 329 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); |
|
- | 330 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->back); |
|
- | 331 | if(glGetError() != GL_NO_ERROR) |
|
- | 332 | goto err4; |
|
- | 333 | ||
- | 334 | glBindTexture(GL_TEXTURE_2D, 0); |
|
- | 335 | ||
- | 336 | render->back_buffer = EGL_DRM_BUFFER_BACK; |
|
- | 337 | ||
- | 338 | context = eglGetCurrentContext(); |
|
- | 339 | ||
- | 340 | config_attribs[0] = EGL_RED_SIZE; |
|
- | 341 | config_attribs[1] = 1; |
|
- | 342 | config_attribs[2] = EGL_GREEN_SIZE; |
|
- | 343 | config_attribs[3] = 1; |
|
- | 344 | config_attribs[4] = EGL_BLUE_SIZE; |
|
- | 345 | config_attribs[5] = 1; |
|
- | 346 | config_attribs[6] = EGL_DEPTH_SIZE; |
|
- | 347 | config_attribs[7] = 1; |
|
- | 348 | ||
- | 349 | config_attribs[8] = EGL_SURFACE_TYPE; |
|
- | 350 | config_attribs[9] = EGL_WINDOW_BIT; |
|
- | 351 | ||
- | 352 | config_attribs[10] = EGL_RENDERABLE_TYPE; |
|
- | 353 | config_attribs[11] = EGL_OPENGL_BIT; |
|
- | 354 | config_attribs[12] = EGL_NONE; |
|
- | 355 | ||
- | 356 | if (!eglChooseConfig(dpy,config_attribs, &config, 1, &num_configs) || !num_configs) |
|
- | 357 | { |
|
- | 358 | printf("failed to choose a config"); |
|
- | 359 | goto err4; |
|
- | 360 | } |
|
- | 361 | ||
- | 362 | render->context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL); |
|
- | 363 | if (!context) |
|
Line -... | Line 364... | ||
- | 364 | { |
|
- | 365 | printf("failed to create context"); |
|
- | 366 | goto err4; |
|
- | 367 | }; |
|
- | 368 | ||
- | 369 | if (!eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context)) |
|
145 | memset(&fb, 0, sizeof(fb)); |
370 | { |
146 | ret = drmIoctl(fd, SRV_FBINFO, &fb); |
371 | printf("failed to make window current"); |
- | 372 | goto err5; |
|
- | 373 | }; |
|
Line 147... | Line 374... | ||
147 | if( ret != 0 ) |
374 | |
- | 375 | render->screen = px_create_image(dpy,context,fb.width,fb.height, |
|
- | 376 | fb.pitch,fb.name); |
|
- | 377 | if(render->screen == EGL_NO_IMAGE_KHR) |
|
- | 378 | goto err6; |
|
- | 379 | ||
- | 380 | glGenTextures(1, &render->tx_screen); |
|
Line 148... | Line -... | ||
148 | printf("failed to get framebuffer info\n"); |
- | |
149 | - | ||
150 | fb_image = px_create_image(dpy,context,fb.width,fb.height, |
381 | if(glGetError() != GL_NO_ERROR) |
151 | fb.pitch,fb.name); |
382 | goto err6; |
- | 383 | ||
- | 384 | glBindTexture(GL_TEXTURE_2D, render->tx_screen); |
|
- | 385 | if(glGetError() != GL_NO_ERROR) |
|
Line 152... | Line -... | ||
152 | - | ||
153 | printf("fb_image %p\n", fb_image); |
386 | goto err7; |
Line 154... | Line 387... | ||
154 | 387 | ||
- | 388 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); |
|
- | 389 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); |
|
- | 390 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->screen); |
|
155 | glGenTextures(1, &texture); |
391 | if(glGetError() != GL_NO_ERROR) |
156 | glBindTexture(GL_TEXTURE_2D, texture); |
392 | goto err7; |
- | 393 | ||
- | 394 | glBindTexture(GL_TEXTURE_2D, 0); |
|
157 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); |
395 | |
158 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); |
396 | glGenFramebuffers(1, &render->framebuffer); |
- | 397 | if(glGetError() != GL_NO_ERROR) |
|
159 | 398 | goto err8; |
|
160 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,fb_image); |
399 | |
161 | glBindTexture(GL_TEXTURE_2D, 0); |
400 | glBindFramebuffer(GL_FRAMEBUFFER, render->framebuffer); |
162 | 401 | if(glGetError() != GL_NO_ERROR) |
|
163 | glGenFramebuffers(1, &buffer); |
402 | goto err9; |
Line 191... | Line 430... | ||
191 | break; |
430 | break; |
192 | default: |
431 | default: |
193 | str = "unknown error"; |
432 | str = "unknown error"; |
194 | break; |
433 | break; |
195 | } |
434 | } |
196 | - | ||
197 | printf("destination is framebuffer incomplete: %s [%#x]\n", |
435 | printf("destination is framebuffer incomplete: %s [%#x]\n", str, status); |
198 | str, status); |
- | |
199 | } |
436 | goto err9; |
200 | } |
437 | } |
Line 201... | Line -... | ||
201 | - | ||
202 | glViewport(0, 0, 1024, 768); |
- | |
203 | glMatrixMode(GL_PROJECTION); |
- | |
204 | glLoadIdentity(); |
- | |
205 | glMatrixMode(GL_MODELVIEW); |
- | |
206 | glLoadIdentity(); |
- | |
207 | - | ||
208 | - | ||
209 | const char *vs_src = |
- | |
210 | "attribute vec4 v_position;\n" |
438 | |
211 | "attribute vec4 v_texcoord0;\n" |
439 | render->blit_prog = glCreateProgram(); |
212 | "varying vec2 source_texture;\n" |
440 | if(render->blit_prog == 0) |
213 | "void main()\n" |
- | |
214 | "{\n" |
- | |
215 | " gl_Position = v_position;\n" |
- | |
216 | " source_texture = v_texcoord0.xy;\n" |
- | |
Line 217... | Line -... | ||
217 | "}\n"; |
- | |
218 | - | ||
219 | const char *fs_src = |
- | |
220 | // "precision mediump float;\n" |
- | |
221 | "varying vec2 source_texture;\n" |
- | |
222 | "uniform sampler2D sampler;\n" |
- | |
223 | "void main()\n" |
- | |
224 | "{\n" |
- | |
225 | " vec3 cg = texture2D(sampler, source_texture).rgb;\n" |
- | |
226 | " gl_FragColor = vec4(cg.r,cg.g,cg.b,1.0);\n" |
- | |
227 | "}\n"; |
- | |
228 | - | ||
229 | GLuint blit_prog; |
- | |
230 | GLint vs_shader, fs_shader; |
- | |
231 | - | ||
232 | asm volatile ("int3"); |
- | |
233 | 441 | goto err9; |
|
- | 442 | ||
- | 443 | vs_shader = create_shader(GL_VERTEX_SHADER,vs_src); |
|
- | 444 | if(vs_shader == 0) |
|
234 | blit_prog = glCreateProgram(); |
445 | goto err10; |
235 | vs_shader = create_shader(GL_VERTEX_SHADER,vs_src); |
446 | |
236 | fs_shader = create_shader(GL_FRAGMENT_SHADER, fs_src); |
447 | fs_shader = create_shader(GL_FRAGMENT_SHADER, fs_src); |
237 | glAttachShader(blit_prog, vs_shader); |
- | |
238 | glAttachShader(blit_prog, fs_shader); |
- | |
Line -... | Line 448... | ||
- | 448 | if(fs_shader == 0) |
|
- | 449 | goto err11; |
|
- | 450 | ||
- | 451 | glAttachShader(render->blit_prog, vs_shader); |
|
239 | glBindAttribLocation(blit_prog, 0, "v_position"); |
452 | glAttachShader(render->blit_prog, fs_shader); |
Line 240... | Line -... | ||
240 | glBindAttribLocation(blit_prog, 1, "v_texcoord0"); |
- | |
241 | 453 | glBindAttribLocation(render->blit_prog, 0, "v_position"); |
|
242 | GLint ok; |
454 | glBindAttribLocation(render->blit_prog, 1, "v_texcoord0"); |
- | 455 | glLinkProgram(render->blit_prog); |
|
243 | 456 | ||
244 | glLinkProgram(blit_prog); |
457 | glGetProgramiv(render->blit_prog, GL_LINK_STATUS, &ret); |
Line 245... | Line 458... | ||
245 | glGetProgramiv(blit_prog, GL_LINK_STATUS, &ok); |
458 | if (!ret) |
246 | if (!ok) { |
459 | { |
Line 247... | Line 460... | ||
247 | GLchar *info; |
460 | GLchar *info; |
248 | GLint size; |
461 | GLint size; |
249 | 462 | ||
- | 463 | glGetProgramiv(render->blit_prog, GL_INFO_LOG_LENGTH, &size); |
|
250 | glGetProgramiv(blit_prog, GL_INFO_LOG_LENGTH, &size); |
464 | info = malloc(size); |
Line -... | Line 465... | ||
- | 465 | ||
- | 466 | glGetProgramInfoLog(render->blit_prog, size, NULL, info); |
|
- | 467 | printf("Failed to link: %s\n", info); |
|
- | 468 | printf("GLSL link failure\n"); |
|
251 | info = malloc(size); |
469 | free(info); |
- | 470 | } |
|
- | 471 | ||
- | 472 | render->sampler = glGetUniformLocation(render->blit_prog,"sampler"); |
|
- | 473 | ||
- | 474 | eglMakeCurrent(dpy, surface, surface, context); |
|
- | 475 | ||
- | 476 | return render; |
|
- | 477 | ||
- | 478 | err11: |
|
- | 479 | glDeleteShader(vs_shader); |
|
- | 480 | err10: |
|
- | 481 | glDeleteProgram(render->blit_prog); |
|
- | 482 | err9: |
|
- | 483 | glDeleteFramebuffers(1, &render->framebuffer); |
|
- | 484 | err8: |
|
- | 485 | eglDestroyImageKHR(dpy, render->screen); |
|
- | 486 | err7: |
|
- | 487 | glDeleteTextures(1, &render->tx_screen); |
|
- | 488 | err6: |
|
- | 489 | eglMakeCurrent(dpy, surface, surface, context); |
|
- | 490 | err5: |
|
- | 491 | eglDestroyContext(dpy, render->context); |
|
- | 492 | err4: |
|
- | 493 | glDeleteTextures(2, render->tx_buffers); |
|
- | 494 | err3: |
|
- | 495 | eglDestroyImageKHR(dpy, render->back); |
|
- | 496 | err2: |
|
- | 497 | eglDestroyImageKHR(dpy, render->front); |
|
- | 498 | err1: |
|
- | 499 | free(render); |
|
- | 500 | err: |
|
- | 501 | return NULL; |
|
- | 502 | }; |
|
252 | 503 | ||
253 | glGetProgramInfoLog(blit_prog, size, NULL, info); |
504 | void render_swap_buffers(struct render *render, int x, int y, int w, int h) |
254 | printf("Failed to link: %s\n", info); |
505 | { |
- | 506 | EGLContext context; |
|
- | 507 | EGLSurface draw, read; |
|
- | 508 | ||
- | 509 | float dst_xscale, dst_yscale; |
|
- | 510 | float *vertices = render->vertices; |
|
- | 511 | float *texcoords = render->texcoords; |
|
- | 512 | int r, b; |
|
- | 513 | ||
- | 514 | if(render == NULL) |
|
- | 515 | return; |
|
- | 516 | ||
- | 517 | context = eglGetCurrentContext(); |
|
- | 518 | draw = eglGetCurrentSurface(EGL_DRAW); |
|
- | 519 | read = eglGetCurrentSurface(EGL_READ); |
|
- | 520 | ||
Line 255... | Line -... | ||
255 | printf("GLSL link failure\n"); |
- | |
256 | } |
521 | eglSwapBuffers(render->dpy,draw); |
257 | 522 | ||
Line 258... | Line 523... | ||
258 | GLint sampler; |
523 | if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context)) |
259 | float vertices[8], texcoords[8]; |
524 | { |
Line 260... | Line 525... | ||
260 | GLfloat dst_xscale, dst_yscale; //, src_xscale, src_yscale; |
525 | printf("failed to make window current"); |
261 | int l, t, r, b, stride; |
526 | goto err1; |
262 | 527 | }; |
|
263 | sampler = glGetUniformLocation(blit_prog,"sampler"); |
528 | |
264 | glUseProgram(blit_prog); |
529 | glUseProgram(render->blit_prog); |
265 | glUniform1i(sampler, 0); |
530 | glUniform1i(render->sampler, 0); |
266 | 531 | ||
267 | glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),vertices); |
532 | glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices); |
Line 268... | Line 533... | ||
268 | glEnableVertexAttribArray(0); |
533 | glEnableVertexAttribArray(0); |
269 | 534 | ||
Line 270... | Line 535... | ||
270 | glActiveTexture(GL_TEXTURE0); |
535 | glActiveTexture(GL_TEXTURE0); |
271 | glBindTexture(GL_TEXTURE_2D, f_tex); |
536 | glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]); |
272 | glTexParameteri(GL_TEXTURE_2D, |
- | |
273 | GL_TEXTURE_MIN_FILTER, |
- | |
Line 274... | Line -... | ||
274 | GL_NEAREST); |
- | |
275 | glTexParameteri(GL_TEXTURE_2D, |
- | |
276 | GL_TEXTURE_MAG_FILTER, |
- | |
277 | GL_NEAREST); |
- | |
278 | 537 | glTexParameteri(GL_TEXTURE_2D, |
|
279 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),texcoords); |
538 | GL_TEXTURE_MIN_FILTER, |
Line 280... | Line 539... | ||
280 | glEnableVertexAttribArray(1); |
539 | GL_NEAREST); |
Line 281... | Line 540... | ||
281 | 540 | glTexParameteri(GL_TEXTURE_2D, |
|
282 | dst_xscale = 1.0/1024; |
541 | GL_TEXTURE_MAG_FILTER, |
Line 283... | Line 542... | ||
283 | dst_yscale = 1.0/768; |
542 | GL_NEAREST); |
284 | // src_xscale = 1.0/400; |
543 | |
Line 285... | Line 544... | ||
285 | // src_yscale = 1.0/300; |
544 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords); |
286 | 545 | glEnableVertexAttribArray(1); |
|
287 | stride = 2; |
546 | |
288 | 547 | dst_xscale = 1.0/1024; |
|
Line 289... | Line 548... | ||
289 | l = 20; |
548 | dst_yscale = 1.0/768; |
Line 318... | Line 577... | ||
318 | glDisableVertexAttribArray(0); |
577 | glDisableVertexAttribArray(0); |
319 | glDisableVertexAttribArray(1); |
578 | glDisableVertexAttribArray(1); |
320 | glDisable(GL_TEXTURE_2D); |
579 | glDisable(GL_TEXTURE_2D); |
321 | glUseProgram(0); |
580 | glUseProgram(0); |
Line 322... | Line -... | ||
322 | - | ||
323 | glFinish(); |
- | |
324 | eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
- | |
325 | // eglDestroySurface(dpy, surface); |
- | |
326 | // gbm_surface_destroy(gs); |
- | |
327 | eglDestroyContext(dpy, context); |
581 | |
328 | eglTerminate(dpy); |
- | |
329 | - | ||
330 | while(1) |
- | |
331 | { |
- | |
332 | delay(1); |
- | |
333 | } |
- | |
334 | - | ||
335 | return 0; |
- | |
336 | } |
- | |
337 | - | ||
338 | int drmIoctl(int fd, unsigned long request, void *arg) |
- | |
339 | { |
- | |
340 | ioctl_t io; |
- | |
341 | - | ||
342 | io.handle = fd; |
- | |
343 | io.io_code = request; |
- | |
344 | io.input = arg; |
- | |
345 | io.inp_size = 64; |
- | |
346 | io.output = NULL; |
- | |
347 | io.out_size = 0; |
- | |
348 | 582 | render->back_buffer++; |
|
349 | return call_service(&io); |
- | |
350 | } |
- | |
351 | - | ||
352 | EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
- | |
353 | int width, int height, int stride, int name) |
- | |
354 | { |
- | |
355 | EGLImageKHR image; |
- | |
356 | EGLint attribs[] = { |
- | |
357 | EGL_WIDTH, 0, |
- | |
358 | EGL_HEIGHT, 0, |
- | |
359 | EGL_DRM_BUFFER_STRIDE_MESA, 0, |
- | |
360 | EGL_DRM_BUFFER_FORMAT_MESA, |
- | |
361 | EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, |
- | |
362 | EGL_DRM_BUFFER_USE_MESA, |
- | |
363 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
- | |
364 | EGL_DRM_BUFFER_USE_SCANOUT_MESA, |
- | |
365 | EGL_NONE |
- | |
366 | }; |
- | |
367 | attribs[1] = width; |
- | |
368 | attribs[3] = height; |
- | |
369 | attribs[5] = stride/4; |
- | |
370 | - | ||
371 | printf("%s w:%d :%d pitch:%d handle %d\n", __FUNCTION__, |
- | |
372 | width, height, stride, name); |
- | |
373 | - | ||
374 | image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA, |
- | |
375 | (void *) (uintptr_t)name, attribs); |
- | |
376 | - | ||
377 | return image; |
- | |
378 | } |
- | |
379 | - | ||
380 | GLint create_shader(GLenum type, const char *source) |
- | |
381 | { |
- | |
382 | GLint ok; |
- | |
383 | GLint prog; |
- | |
384 | - | ||
385 | prog = glCreateShader(type); |
- | |
386 | glShaderSource(prog, 1, (const GLchar **) &source, NULL); |
- | |
387 | glCompileShader(prog); |
- | |
388 | glGetShaderiv(prog, GL_COMPILE_STATUS, &ok); |
- | |
389 | if (!ok) { |
- | |
390 | GLchar *info; |
- | |
391 | GLint size; |
- | |
392 | - | ||
393 | glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size); |
- | |
394 | info = malloc(size); |
- | |
395 | - | ||
396 | glGetShaderInfoLog(prog, size, NULL, info); |
- | |
397 | printf("Failed to compile %s: %s\n", |
- | |
398 | type == GL_FRAGMENT_SHADER ? "FS" : "VS",info); |
- | |
399 | printf("Program source:\n%s", source); |
- | |
400 | printf("GLSL compile failure\n"); |
- | |
Line 401... | Line 583... | ||
401 | } |
583 | render->back_buffer&=1; |
- | 584 | ||
402 | 585 | err1: |
|
Line -... | Line 586... | ||
- | 586 | eglMakeCurrent(render->dpy, draw, read, context); |
|
403 | return prog; |
587 | } |
404 | } |
588 | |
405 | 589 | #if 0 |
|
Line 406... | Line 590... | ||
406 | GLuint create_framebuffer(int width, int height, GLuint *tex) |
590 | GLuint create_framebuffer(int width, int height, GLuint *tex) |
Line 421... | Line 605... | ||
421 | glFramebufferTexture2D(GL_FRAMEBUFFER, |
605 | glFramebufferTexture2D(GL_FRAMEBUFFER, |
422 | GL_COLOR_ATTACHMENT0, |
606 | GL_COLOR_ATTACHMENT0, |
423 | GL_TEXTURE_2D, *tex,0); |
607 | GL_TEXTURE_2D, *tex,0); |
424 | return buffer; |
608 | return buffer; |
425 | } |
609 | } |
- | 610 | #endif |