Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GLES2/gl2.h>
- #include <EGL/egl.h>
- #include <EGL/eglext.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <stdlib.h>
- #define N_TEXTURES 40
- static const EGLint attribs[] = {
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_RED_SIZE, 1,
- EGL_GREEN_SIZE, 1,
- EGL_BLUE_SIZE, 1,
- EGL_DEPTH_SIZE, 1,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_NONE
- };
- static const EGLint context_attribs[] ={
- EGL_CONTEXT_CLIENT_VERSION, 2,
- EGL_NONE
- };
- struct egl_state {
- Display *dpy;
- Window win;
- EGLDisplay egl_dpy;
- EGLConfig cfg;
- EGLContext ctx;
- EGLSurface surf;
- EGLint major, minor;
- int depth;
- int width;
- int height;
- };
- static void
- create_window (struct egl_state *state)
- {
- XSetWindowAttributes window_attr;
- XVisualInfo template, *vinfo;
- EGLint id;
- unsigned long mask;
- int screen = DefaultScreen (state->dpy);
- Window root_win = RootWindow (state->dpy, screen);
- int count;
- if (!eglGetConfigAttrib (state->egl_dpy,
- state->cfg, EGL_NATIVE_VISUAL_ID, &id))
- {
- fprintf (stderr, "eglGetConfigAttrib() failed\n");
- exit (1);
- }
- template.visualid = id;
- vinfo = XGetVisualInfo (state->dpy, VisualIDMask, &template, &count);
- if (count != 1)
- {
- fprintf (stderr, "XGetVisualInfo() failed\n");
- exit (1);
- }
- state->depth = vinfo->depth;
- window_attr.background_pixel = 0;
- window_attr.border_pixel = 0;
- window_attr.colormap = XCreateColormap (state->dpy, root_win,
- vinfo->visual, AllocNone);
- window_attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
- mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
- state->win = XCreateWindow (state->dpy, root_win, 0, 0,
- state->width, state->height,
- 0, vinfo->depth, InputOutput,
- vinfo->visual, mask, &window_attr);
- XMapWindow (state->dpy, state->win);
- XFree (vinfo);
- }
- static void
- run_test (void)
- {
- GLuint textures[N_TEXTURES];
- int i;
- /* Create all of the textures straight up */
- for (i = 0; i < N_TEXTURES; i++)
- {
- glGenTextures (1, textures + i);
- glBindTexture (GL_TEXTURE_2D, textures[i]);
- glTexParameteri (GL_TEXTURE_2D,
- GL_TEXTURE_MIN_FILTER,
- GL_NEAREST);
- glTexImage2D (GL_TEXTURE_2D, 0,
- GL_RGBA,
- 128, 128,
- 0,
- GL_RGBA,
- GL_UNSIGNED_BYTE,
- NULL);
- }
- /* Bind and destroy an FBO to each one in turn */
- for (i = 0; i < N_TEXTURES; i++)
- {
- GLuint fbo;
- GLenum status;
- glGenFramebuffers (1, &fbo);
- glBindFramebuffer (GL_FRAMEBUFFER, fbo);
- glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, textures[i], 0);
- status = glCheckFramebufferStatus (GL_FRAMEBUFFER);
- printf ("status of FBO %i = 0x%x (%s)\n",
- i,
- status,
- status == GL_FRAMEBUFFER_COMPLETE ? "complete" :
- status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
- ? "incomplete attachment" :
- status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
- ? "missing attachment" :
- "?");
- glDeleteFramebuffers (1, &fbo);
- }
- glDeleteTextures (N_TEXTURES, textures);
- }
- int
- main (int argc, char **argv)
- {
- struct egl_state state;
- int count;
- state.dpy = XOpenDisplay (NULL);
- if (state.dpy == NULL)
- {
- fprintf (stderr, "couldn't open display\n");
- return EXIT_FAILURE;
- }
- state.egl_dpy = eglGetDisplay (state.dpy);
- if (state.egl_dpy == EGL_NO_DISPLAY)
- {
- fprintf (stderr, "eglGetDisplay() failed\n");
- return EXIT_FAILURE;
- }
- if (!eglInitialize (state.egl_dpy, &state.major, &state.minor))
- {
- fprintf (stderr, "eglInitialize() failed\n");
- return EXIT_FAILURE;
- }
- if (!eglChooseConfig (state.egl_dpy, attribs, &state.cfg, 1, &count) ||
- count == 0)
- {
- fprintf (stderr, "eglChooseConfig() failed\n");
- return EXIT_FAILURE;
- }
- state.ctx = eglCreateContext (state.egl_dpy, state.cfg,
- EGL_NO_CONTEXT, context_attribs);
- if (state.ctx == EGL_NO_CONTEXT)
- {
- fprintf (stderr, "eglCreateContext() failed\n");
- return EXIT_FAILURE;
- }
- state.width = 300;
- state.height = 300;
- create_window (&state);
- state.surf = eglCreateWindowSurface (state.egl_dpy,
- state.cfg, state.win, NULL);
- if (state.surf == EGL_NO_SURFACE)
- {
- fprintf (stderr, "eglCreateWindowSurface() failed\n");
- return EXIT_FAILURE;
- }
- if (!eglMakeCurrent (state.egl_dpy, state.surf, state.surf, state.ctx))
- {
- fprintf (stderr, "eglMakeCurrent() failed\n");
- return EXIT_FAILURE;
- }
- run_test ();
- eglTerminate (state.egl_dpy);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement