2 * Offscreen OpenGL abstraction layer
4 * Copyright (c) 2010 Intel Corporation
6 * Gordon Williams <gordon.williams@collabora.co.uk>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #include "gloffscreen.h"
38 #include <OpenGL/gl.h>
45 #ifdef MANGLE_OPENGL_SYMBOLS
46 #include "gl_mangled.h"
49 // ---------------------------------------------------
50 // Copied from glx.h as we need them in windows too
52 * Tokens for glXChooseVisual and glXGetConfig:
55 #define GLX_BUFFER_SIZE 2
58 #define GLX_DOUBLEBUFFER 5
60 #define GLX_AUX_BUFFERS 7
61 #define GLX_RED_SIZE 8
62 #define GLX_GREEN_SIZE 9
63 #define GLX_BLUE_SIZE 10
64 #define GLX_ALPHA_SIZE 11
65 #define GLX_DEPTH_SIZE 12
66 #define GLX_STENCIL_SIZE 13
67 #define GLX_ACCUM_RED_SIZE 14
68 #define GLX_ACCUM_GREEN_SIZE 15
69 #define GLX_ACCUM_BLUE_SIZE 16
70 #define GLX_ACCUM_ALPHA_SIZE 17
71 // ---------------------------------------------------
76 #define CHECK_SUCCESS 0
78 int gl_acceleration_capability_check (void) {
79 //int test_failure = 0;
82 unsigned char *datain;
83 unsigned char *datain_flip;
84 unsigned char *dataout;
87 const int bufferAttributes[] = {
97 #ifdef MANGLE_OPENGL_SYMBOLS
98 if (mgl_load_symbols("libGL.so.1")) {
103 int bufferFlags = glo_flags_get_from_glx(bufferAttributes, 0);
104 int bpp = glo_flags_get_bytes_per_pixel(bufferFlags);
105 int glFormat, glType;
107 if (glo_sanity_test () != 0) {
112 datain = (unsigned char *)malloc(4*TX*TY);
113 datain_flip = (unsigned char *)malloc(4*TX*TY);
115 memset(datain, 0, TX*TY*4);
116 memset(datain_flip, 0, TX*TY*4);
123 //if (y&1) { p[0]=0; p[1]=0; }
125 if (bpp>3) p[3] = 0xFF;
128 memcpy(&datain_flip[((TY-1)-y)*bpp*TX], &datain[y*bpp*TX], bpp*TX);
131 if (glo_init() != 0) {
132 printf ("Host does not have GL hardware acceleration!(glo_init() failed)\n");
139 context = glo_context_create(bufferFlags, 0);
140 if (context == NULL) {
141 printf ("Host does not have GL hardware acceleration!(context_create() failed)\n");
147 surface = glo_surface_create(TX, TY, context);
148 if (surface == NULL) {
149 printf ("Host does not have GL hardware acceleration!(surface_create() failed)\n");
155 glo_surface_makecurrent(surface);
156 printf("GL VENDOR %s\n", glGetString(GL_VENDOR));
157 printf("GL RENDERER %s\n", glGetString(GL_RENDERER));
158 printf("GL VERSION %s\n", glGetString(GL_VERSION));
159 //printf("GLSL VERSION %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
161 if (strstr((const char*)glGetString(GL_RENDERER), "Software")) {
162 printf ("Host does not have GL hardware acceleration!(No host gl driver)\n");
168 // fill with stuff (in correctly ordered way)
169 glClear(GL_COLOR_BUFFER_BIT);
170 glMatrixMode(GL_PROJECTION);
172 glOrtho(0,TX, 0,TY, 0, 1);
173 glMatrixMode(GL_MODELVIEW);
176 glo_flags_get_readpixel_type(bufferFlags, &glFormat, &glType);
177 printf("glFormat: 0x%08X glType: 0x%08X\n", glFormat, glType);
178 glDrawPixels(TX,TY,glFormat, glType, datain_flip);
181 dataout = (unsigned char *)malloc(4*TX*TY);
182 memset(dataout, 0, bpp*TX*TY);
184 glo_surface_getcontents(surface, TX*bpp, bpp*8, dataout);
187 glo_surface_destroy(surface);
188 glo_context_destroy(context);
190 if (memcmp(datain, dataout, bpp*TX*TY)!=0) {
191 printf ("Host does not have GL hardware acceleration!(datain != dataout)\n");
199 //printf ("Testing %s\n", (test_failure ? "FAILED" : "PASSED"));
204 return CHECK_SUCCESS;