ecere/gfx/drivers/OpenGL: Shaders migration -- Initial Take
[sdk] / ecere / src / gfx / drivers / gl3 / egl.ec
1 #if defined(__ANDROID__) || defined(__ODROID__)
2
3 #include <EGL/egl.h>
4
5 EGLDisplay eglDisplay;
6 EGLSurface eglSurface;
7 EGLContext eglContext;
8 int eglWidth, eglHeight;
9
10 #if defined(__ANDROID__)
11 static bool egl_init_display(ANativeWindow* window)
12 #else
13 static bool egl_init_display(uint window)
14 #endif
15 {
16    const EGLint attribs[] =
17    {
18       EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
19       EGL_BLUE_SIZE, 8,
20       EGL_GREEN_SIZE, 8,
21       EGL_RED_SIZE, 8,
22       EGL_DEPTH_SIZE, 16, //24,
23       /*EGL_SAMPLE_BUFFERS, 1,
24       EGL_SAMPLES, 0, //2,*/
25       EGL_NONE
26    };
27    EGLint w, h, format;
28    EGLint numConfigs;
29    EGLConfig config;
30    EGLSurface surface;
31    EGLContext context;
32
33    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
34    eglInitialize(display, 0, 0);
35    eglChooseConfig(display, attribs, &config, 1, &numConfigs);
36    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
37
38    surface = eglCreateWindowSurface(display, config, window, null);
39    context = eglCreateContext(display, config, null, null);
40
41    if(!eglMakeCurrent(display, surface, surface, context))
42       return false;
43
44    eglQuerySurface(display, surface, EGL_WIDTH, &w);
45    eglQuerySurface(display, surface, EGL_HEIGHT, &h);
46
47    eglDisplay = display;
48    eglContext = context;
49    eglSurface = surface;
50    eglWidth = w;
51    eglHeight = h;
52
53    glEnableClientState(GL_VERTEX_ARRAY);
54    /*
55    // Initialize GL state.
56    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
57    glEnable(GL_CULL_FACE);
58    glShadeModel(GL_SMOOTH);
59    glDisable(GL_DEPTH_TEST);
60    */
61    glDisable(GL_CULL_FACE);
62    glDisable(GL_DEPTH_TEST);
63
64    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
65    glEnable(GL_BLEND);
66
67    matrixStack[0][0].Identity();
68    matrixStack[1][0].Identity();
69    matrixStack[2][0].Identity();
70
71    glmsMatrixMode(GL_MODELVIEW);
72    glScaled(1.0, 1.0, -1.0);
73    glmsMatrixMode(GL_PROJECTION);
74    glShadeModel(GL_FLAT);
75
76    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
77    glFogi(GL_FOG_MODE, GL_EXP);
78    glFogf(GL_FOG_DENSITY, 0);
79    glEnable(GL_NORMALIZE);
80    glDepthFunc(GL_LESS);
81    glClearDepth(1.0);
82    glDisable(GL_MULTISAMPLE_ARB);
83
84    glViewport(0,0,w,h);
85    glmsLoadIdentity();
86    glOrtho(0,w,h,0,0.0,1.0);
87
88    glabCurArrayBuffer = 0;
89    glabCurElementBuffer = 0;
90    return true;
91 }
92
93 static void egl_term_display()
94 {
95    if(stippleTexture)
96    {
97       glDeleteTextures(1, &stippleTexture);
98       stippleTexture = 0;
99    }
100    if(eglDisplay != EGL_NO_DISPLAY)
101    {
102       eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
103       if(eglContext != EGL_NO_CONTEXT)
104          eglDestroyContext(eglDisplay, eglContext);
105       if(eglSurface != EGL_NO_SURFACE)
106          eglDestroySurface(eglDisplay, eglSurface);
107       eglTerminate(eglDisplay);
108    }
109    eglDisplay = EGL_NO_DISPLAY;
110    eglContext = EGL_NO_CONTEXT;
111    eglSurface = EGL_NO_SURFACE;
112 }
113
114 #endif