Rev 4472 | Rev 4485 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4472 | Rev 4473 | ||
---|---|---|---|
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 16... | Line 16... | ||
16 | 16 | ||
17 | static EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
17 | EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
Line 18... | Line 18... | ||
18 | int width, int height, int stride, int name, int depth); |
18 | int width, int height, int stride, int name); |
19 | 19 | ||
20 | int main() |
20 | int main() |
21 | { |
21 | { |
Line 31... | Line 31... | ||
31 | EGLConfig config; |
31 | EGLConfig config; |
Line 32... | Line 32... | ||
32 | 32 | ||
33 | EGLint config_attribs[32]; |
33 | EGLint config_attribs[32]; |
34 | EGLint num_configs, i; |
34 | EGLint num_configs, i; |
35 | GLint list; |
35 | GLint list; |
- | 36 | GLuint texture, buffer; |
|
Line 36... | Line 37... | ||
36 | GLuint *texture; |
37 | |
Line 37... | Line 38... | ||
37 | 38 | ||
38 | int fd; |
39 | int fd; |
Line 79... | Line 80... | ||
79 | eglBindAPI(EGL_OPENGL_API); |
80 | eglBindAPI(EGL_OPENGL_API); |
80 | context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL); |
81 | context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL); |
81 | if (!context) |
82 | if (!context) |
82 | printf("failed to create context"); |
83 | printf("failed to create context"); |
Line 83... | Line 84... | ||
83 | 84 | ||
Line 84... | Line 85... | ||
84 | gs = gbm_surface_create(gbm, 400, 300, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); |
85 | gs = gbm_surface_create(gbm, 1024, 768, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); |
85 | 86 | ||
86 | 87 | ||
Line 99... | Line 100... | ||
99 | 100 | ||
100 | 101 | ||
101 | if(fd) |
102 | if(fd) |
- | 103 | { |
|
102 | { |
104 | int ret; |
103 | int ret; |
- | |
Line 104... | Line 105... | ||
104 | struct drm_i915_fb_info fb; |
105 | GLenum status; |
105 | struct drm_gem_open open_arg; |
106 | struct drm_i915_fb_info fb; |
106 | 107 | ||
107 | memset(&fb, 0, sizeof(fb)); |
108 | memset(&fb, 0, sizeof(fb)); |
Line 108... | Line -... | ||
108 | ret = drmIoctl(fd, SRV_FBINFO, &fb); |
- | |
109 | if( ret != 0 ) |
- | |
110 | printf("failed to get framebuffer info\n"); |
109 | ret = drmIoctl(fd, SRV_FBINFO, &fb); |
111 | - | ||
112 | memset(&open_arg,0,sizeof(open_arg)); |
110 | if( ret != 0 ) |
113 | open_arg.name = fb.name; |
- | |
Line 114... | Line 111... | ||
114 | ret = drmIoctl(fd,DRM_IOCTL_GEM_OPEN,&open_arg); |
111 | printf("failed to get framebuffer info\n"); |
Line 115... | Line 112... | ||
115 | if (ret != 0) { |
112 | |
116 | printf("Couldn't reference framebuffer handle 0x%08x\n", fb.name); |
- | |
Line 117... | Line 113... | ||
117 | } |
113 | fb_image = px_create_image(dpy,context,fb.width,fb.height, |
118 | 114 | fb.pitch,fb.name); |
|
119 | asm volatile ("int3"); |
115 | |
120 | 116 | printf("fb_image %p\n", fb_image); |
|
Line 121... | Line 117... | ||
121 | fb_image = px_create_image(dpy,context,fb.width,fb.height, |
117 | |
122 | fb.pitch,open_arg.handle,32); |
118 | asm volatile ("int3"); |
Line -... | Line 119... | ||
- | 119 | ||
- | 120 | glGenTextures(1, &texture); |
|
- | 121 | glBindTexture(GL_TEXTURE_2D, texture); |
|
- | 122 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); |
|
- | 123 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); |
|
- | 124 | ||
- | 125 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,fb_image); |
|
- | 126 | glBindTexture(GL_TEXTURE_2D, 0); |
|
- | 127 | ||
- | 128 | glGenFramebuffers(1, &buffer); |
|
- | 129 | glBindFramebuffer(GL_FRAMEBUFFER, buffer); |
|
- | 130 | glFramebufferTexture2D(GL_FRAMEBUFFER, |
|
- | 131 | GL_COLOR_ATTACHMENT0, |
|
- | 132 | GL_TEXTURE_2D, texture,0); |
|
- | 133 | status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
|
- | 134 | if (status != GL_FRAMEBUFFER_COMPLETE) |
|
- | 135 | { |
|
- | 136 | const char *str; |
|
- | 137 | switch (status) |
|
- | 138 | { |
|
- | 139 | case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: |
|
- | 140 | str = "incomplete attachment"; |
|
- | 141 | break; |
|
- | 142 | case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: |
|
- | 143 | str = "incomplete/missing attachment"; |
|
- | 144 | break; |
|
- | 145 | case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: |
|
- | 146 | str = "incomplete draw buffer"; |
|
- | 147 | break; |
|
- | 148 | case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: |
|
- | 149 | str = "incomplete read buffer"; |
|
- | 150 | break; |
|
- | 151 | case GL_FRAMEBUFFER_UNSUPPORTED: |
|
- | 152 | str = "unsupported"; |
|
- | 153 | break; |
|
- | 154 | case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: |
|
- | 155 | str = "incomplete multiple"; |
|
- | 156 | break; |
|
- | 157 | default: |
|
- | 158 | str = "unknown error"; |
|
- | 159 | break; |
|
- | 160 | } |
|
- | 161 | ||
- | 162 | printf("destination is framebuffer incomplete: %s [%#x]\n", |
|
- | 163 | str, status); |
|
123 | 164 | } |
|
Line 124... | Line 165... | ||
124 | glGenTextures(1, texture); |
165 | |
Line 125... | Line 166... | ||
125 | glBindTexture(GL_TEXTURE_2D, *texture); |
166 | glViewport(0, 0,fb.width, fb.height); |
Line 165... | Line 206... | ||
165 | 206 | ||
Line 166... | Line 207... | ||
166 | asm volatile ("int3"); |
207 | asm volatile ("int3"); |
Line 167... | Line -... | ||
167 | - | ||
168 | glDrawBuffer(GL_BACK); |
- | |
169 | - | ||
170 | glViewport(0, 0, (GLint)400, (GLint)300); |
- | |
171 | - | ||
172 | glMatrixMode(GL_PROJECTION); |
- | |
173 | glLoadIdentity(); |
- | |
174 | glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 100.0); |
208 | |
Line 175... | Line 209... | ||
175 | glMatrixMode(GL_MODELVIEW); |
209 | glDrawBuffer(GL_BACK); |
Line 176... | Line 210... | ||
176 | 210 | ||
Line 185... | Line 219... | ||
185 | */ |
219 | */ |
186 | glCallList(list); |
220 | glCallList(list); |
187 | glFlush(); |
221 | glFlush(); |
Line 188... | Line 222... | ||
188 | 222 | ||
Line 189... | Line 223... | ||
189 | 223 | ||
190 | eglSwapBuffers(dpy, surface); |
224 | // eglSwapBuffers(dpy, surface); |
191 | 225 | ||
192 | glFinish(); |
226 | glFinish(); |
193 | eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
227 | eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
194 | eglDestroySurface(dpy, surface); |
228 | // eglDestroySurface(dpy, surface); |
Line 195... | Line 229... | ||
195 | gbm_surface_destroy(gs); |
229 | // gbm_surface_destroy(gs); |
196 | eglDestroyContext(dpy, context); |
230 | eglDestroyContext(dpy, context); |
Line 216... | Line 250... | ||
216 | io.out_size = 0; |
250 | io.out_size = 0; |
Line 217... | Line 251... | ||
217 | 251 | ||
218 | return call_service(&io); |
252 | return call_service(&io); |
Line 219... | Line 253... | ||
219 | } |
253 | } |
220 | 254 | ||
221 | static EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
255 | EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
222 | int width, int height, int stride, int name, int depth) |
256 | int width, int height, int stride, int name) |
223 | { |
257 | { |
224 | EGLImageKHR image; |
258 | EGLImageKHR image; |
225 | EGLint attribs[] = { |
259 | EGLint attribs[] = { |
Line 234... | Line 268... | ||
234 | EGL_NONE |
268 | EGL_NONE |
235 | }; |
269 | }; |
236 | attribs[1] = width; |
270 | attribs[1] = width; |
237 | attribs[3] = height; |
271 | attribs[3] = height; |
238 | attribs[5] = stride; |
272 | attribs[5] = stride; |
- | 273 | ||
239 | if (depth != 32 && depth != 24) |
274 | printf("%s w:%d :%d pitch:%d handle %d\n", __FUNCTION__, |
240 | return EGL_NO_IMAGE_KHR; |
275 | width, height, stride, name); |
- | 276 | ||
241 | image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA, |
277 | image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA, |
242 | (void *) (uintptr_t)name, attribs); |
278 | (void *) (uintptr_t)name, attribs); |
243 | if (image == EGL_NO_IMAGE_KHR) |
- | |
244 | return EGL_NO_IMAGE_KHR; |
- | |
Line 245... | Line 279... | ||
245 | 279 | ||
246 | return image; |
280 | return image; |