Rev 4472 | Rev 4485 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4464 | Serge | 1 | #include |
2 | #include |
||
3 | #include |
||
4 | #include |
||
5 | |||
6 | #define EGL_EGLEXT_PROTOTYPES |
||
4472 | Serge | 7 | #define GL_GLEXT_PROTOTYPES |
8 | |||
4464 | Serge | 9 | #include "EGL/egl.h" |
10 | #include "EGL/eglext.h" |
||
11 | #include "GL/gl.h" |
||
12 | #include "gbm.h" |
||
4472 | Serge | 13 | #include |
4464 | Serge | 14 | #include |
15 | #include |
||
16 | |||
4473 | Serge | 17 | EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
18 | int width, int height, int stride, int name); |
||
4472 | Serge | 19 | |
4464 | Serge | 20 | int main() |
21 | { |
||
22 | struct gbm_device *gbm; |
||
23 | struct gbm_surface *gs; |
||
24 | |||
25 | EGLDisplay dpy; |
||
26 | EGLint major, minor; |
||
27 | |||
28 | EGLContext context; |
||
29 | EGLSurface surface; |
||
4472 | Serge | 30 | EGLImageKHR fb_image; |
4464 | Serge | 31 | EGLConfig config; |
32 | |||
33 | EGLint config_attribs[32]; |
||
34 | EGLint num_configs, i; |
||
35 | GLint list; |
||
4473 | Serge | 36 | GLuint texture, buffer; |
4464 | Serge | 37 | |
4473 | Serge | 38 | |
4464 | Serge | 39 | int fd; |
40 | |||
41 | fd = get_service("DISPLAY"); |
||
42 | gbm = gbm_create_device(fd); |
||
43 | if( gbm == NULL){ |
||
44 | printf("failed to initialize GBM device"); |
||
45 | return 1; |
||
46 | }; |
||
47 | |||
4472 | Serge | 48 | init_pixlib(HW_BIT_BLIT); |
49 | |||
4464 | Serge | 50 | dpy = eglGetDisplay((EGLNativeDisplayType)gbm); |
51 | |||
52 | if (!eglInitialize(dpy, &major, &minor)) |
||
53 | printf("failed to initialize EGL display"); |
||
54 | |||
55 | printf("EGL_VERSION = %s\n", eglQueryString(dpy, EGL_VERSION)); |
||
56 | printf("EGL_VENDOR = %s\n", eglQueryString(dpy, EGL_VENDOR)); |
||
57 | printf("EGL_EXTENSIONS = %s\n", eglQueryString(dpy, EGL_EXTENSIONS)); |
||
58 | printf("EGL_CLIENT_APIS = %s\n",eglQueryString(dpy, EGL_CLIENT_APIS)); |
||
59 | |||
60 | i = 0; |
||
61 | config_attribs[i++] = EGL_RED_SIZE; |
||
62 | config_attribs[i++] = 1; |
||
63 | config_attribs[i++] = EGL_GREEN_SIZE; |
||
64 | config_attribs[i++] = 1; |
||
65 | config_attribs[i++] = EGL_BLUE_SIZE; |
||
66 | config_attribs[i++] = 1; |
||
67 | config_attribs[i++] = EGL_DEPTH_SIZE; |
||
68 | config_attribs[i++] = 1; |
||
69 | |||
70 | config_attribs[i++] = EGL_SURFACE_TYPE; |
||
71 | config_attribs[i++] = EGL_WINDOW_BIT; |
||
72 | |||
73 | config_attribs[i++] = EGL_RENDERABLE_TYPE; |
||
74 | config_attribs[i++] = EGL_OPENGL_BIT; |
||
75 | config_attribs[i] = EGL_NONE; |
||
76 | |||
77 | if (!eglChooseConfig(dpy,config_attribs, &config, 1, &num_configs) || !num_configs) |
||
78 | printf("failed to choose a config"); |
||
79 | |||
80 | eglBindAPI(EGL_OPENGL_API); |
||
81 | context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL); |
||
82 | if (!context) |
||
83 | printf("failed to create context"); |
||
84 | |||
4473 | Serge | 85 | gs = gbm_surface_create(gbm, 1024, 768, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); |
4464 | Serge | 86 | |
87 | |||
88 | BeginDraw(); |
||
89 | DrawWindow(20, 20, 400+9, 300+24, "gl-render", 0x000000, 0x74); |
||
90 | EndDraw(); |
||
91 | |||
4472 | Serge | 92 | sna_create_mask(); |
93 | |||
4464 | Serge | 94 | surface = eglCreateWindowSurface(dpy,config, (EGLNativeWindowType)gs, NULL); |
95 | if (surface == EGL_NO_SURFACE) |
||
96 | printf("failed to create surface"); |
||
97 | |||
98 | if (!eglMakeCurrent(dpy, surface, surface, context)) |
||
99 | printf("failed to make window current"); |
||
100 | |||
4472 | Serge | 101 | |
102 | if(fd) |
||
103 | { |
||
104 | int ret; |
||
4473 | Serge | 105 | GLenum status; |
4472 | Serge | 106 | struct drm_i915_fb_info fb; |
107 | |||
108 | memset(&fb, 0, sizeof(fb)); |
||
109 | ret = drmIoctl(fd, SRV_FBINFO, &fb); |
||
110 | if( ret != 0 ) |
||
111 | printf("failed to get framebuffer info\n"); |
||
112 | |||
4473 | Serge | 113 | fb_image = px_create_image(dpy,context,fb.width,fb.height, |
114 | fb.pitch,fb.name); |
||
4472 | Serge | 115 | |
4473 | Serge | 116 | printf("fb_image %p\n", fb_image); |
117 | |||
4472 | Serge | 118 | asm volatile ("int3"); |
119 | |||
4473 | Serge | 120 | glGenTextures(1, &texture); |
121 | glBindTexture(GL_TEXTURE_2D, texture); |
||
4472 | Serge | 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 | |||
4473 | Serge | 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); |
||
164 | } |
||
165 | |||
166 | glViewport(0, 0,fb.width, fb.height); |
||
167 | |||
168 | glMatrixMode(GL_PROJECTION); |
||
169 | glLoadIdentity(); |
||
170 | glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 100.0); |
||
171 | glMatrixMode(GL_MODELVIEW); |
||
172 | glLoadIdentity(); |
||
4472 | Serge | 173 | } |
174 | |||
4464 | Serge | 175 | glClearColor( 0, 0, 0, 1); |
176 | |||
177 | list = glGenLists(1); |
||
178 | glNewList(list, GL_COMPILE); |
||
179 | |||
180 | /* XXX: this state-change will only be executed if list is called |
||
181 | * from outside a begin/end pair: |
||
182 | */ |
||
183 | glShadeModel( GL_FLAT ); |
||
184 | glBegin(GL_TRIANGLES); |
||
185 | glColor3f(0,0,.7); |
||
186 | glVertex3f( -0.9, 0.9, -30.0); |
||
187 | glColor3f(0,.9,0); |
||
188 | glVertex3f( -0.9, -0.9, -30.0); |
||
189 | glColor3f(.8,0,0); |
||
190 | glVertex3f( 0.9, 0.0, -30.0); |
||
191 | glEnd(); |
||
192 | |||
193 | /* This statechange is potentially NOT redundant: |
||
194 | */ |
||
195 | glShadeModel( GL_FLAT ); |
||
196 | glBegin(GL_TRIANGLES); |
||
197 | glColor3f(0,1,0); |
||
198 | glVertex3f( -0.5, 0.5, -30.0); |
||
199 | glColor3f(0,0,1); |
||
200 | glVertex3f( -0.5, -0.5, -30.0); |
||
201 | glColor3f(1,0,0); |
||
202 | glVertex3f( 0.5, 0.0, -30.0); |
||
203 | glEnd(); |
||
204 | |||
205 | glEndList(); |
||
206 | |||
4472 | Serge | 207 | asm volatile ("int3"); |
208 | |||
4464 | Serge | 209 | glDrawBuffer(GL_BACK); |
210 | |||
4472 | Serge | 211 | glClear(GL_COLOR_BUFFER_BIT); |
4464 | Serge | 212 | |
213 | glShadeModel( GL_SMOOTH ); |
||
214 | |||
215 | glBegin(GL_TRIANGLES); |
||
216 | |||
217 | /* Note: call the list from inside a begin/end pair. The end is |
||
218 | * provided by the display list... |
||
219 | */ |
||
220 | glCallList(list); |
||
221 | glFlush(); |
||
222 | |||
223 | |||
4473 | Serge | 224 | // eglSwapBuffers(dpy, surface); |
4464 | Serge | 225 | |
226 | glFinish(); |
||
227 | eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
||
4473 | Serge | 228 | // eglDestroySurface(dpy, surface); |
229 | // gbm_surface_destroy(gs); |
||
4464 | Serge | 230 | eglDestroyContext(dpy, context); |
231 | eglTerminate(dpy); |
||
232 | |||
233 | while(1) |
||
234 | { |
||
235 | delay(1); |
||
236 | } |
||
4472 | Serge | 237 | |
4464 | Serge | 238 | return 0; |
239 | } |
||
4472 | Serge | 240 | |
241 | int drmIoctl(int fd, unsigned long request, void *arg) |
||
242 | { |
||
243 | ioctl_t io; |
||
244 | |||
245 | io.handle = fd; |
||
246 | io.io_code = request; |
||
247 | io.input = arg; |
||
248 | io.inp_size = 64; |
||
249 | io.output = NULL; |
||
250 | io.out_size = 0; |
||
251 | |||
252 | return call_service(&io); |
||
253 | } |
||
254 | |||
4473 | Serge | 255 | EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, |
256 | int width, int height, int stride, int name) |
||
4472 | Serge | 257 | { |
258 | EGLImageKHR image; |
||
259 | EGLint attribs[] = { |
||
260 | EGL_WIDTH, 0, |
||
261 | EGL_HEIGHT, 0, |
||
262 | EGL_DRM_BUFFER_STRIDE_MESA, 0, |
||
263 | EGL_DRM_BUFFER_FORMAT_MESA, |
||
264 | EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, |
||
265 | EGL_DRM_BUFFER_USE_MESA, |
||
266 | EGL_DRM_BUFFER_USE_SHARE_MESA | |
||
267 | EGL_DRM_BUFFER_USE_SCANOUT_MESA, |
||
268 | EGL_NONE |
||
269 | }; |
||
270 | attribs[1] = width; |
||
271 | attribs[3] = height; |
||
272 | attribs[5] = stride; |
||
4473 | Serge | 273 | |
274 | printf("%s w:%d :%d pitch:%d handle %d\n", __FUNCTION__, |
||
275 | width, height, stride, name); |
||
276 | |||
4472 | Serge | 277 | image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA, |
278 | (void *) (uintptr_t)name, attribs); |
||
279 | |||
280 | return image; |
||
281 | } |