Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
osmesa_context.c
Go to the documentation of this file.
1//========================================================================
2// GLFW 3.4 OSMesa - www.glfw.org
3//------------------------------------------------------------------------
4// Copyright (c) 2016 Google Inc.
5// Copyright (c) 2016-2017 Camilla Löwy <elmindreda@glfw.org>
6//
7// This software is provided 'as-is', without any express or implied
8// warranty. In no event will the authors be held liable for any damages
9// arising from the use of this software.
10//
11// Permission is granted to anyone to use this software for any purpose,
12// including commercial applications, and to alter it and redistribute it
13// freely, subject to the following restrictions:
14//
15// 1. The origin of this software must not be misrepresented; you must not
16// claim that you wrote the original software. If you use this software
17// in a product, an acknowledgment in the product documentation would
18// be appreciated but is not required.
19//
20// 2. Altered source versions must be plainly marked as such, and must not
21// be misrepresented as being the original software.
22//
23// 3. This notice may not be removed or altered from any source
24// distribution.
25//
26//========================================================================
27// Please use C89 style variable declarations in this file because VS 2010
28//========================================================================
29
30#include <stdlib.h>
31#include <string.h>
32#include <assert.h>
33
34#include "internal.h"
35
36
37static void makeContextCurrentOSMesa(_GLFWwindow* window)
38{
39 if (window)
40 {
41 int width, height;
42 _glfwPlatformGetFramebufferSize(window, &width, &height);
43
44 // Check to see if we need to allocate a new buffer
45 if ((window->context.osmesa.buffer == NULL) ||
46 (width != window->context.osmesa.width) ||
47 (height != window->context.osmesa.height))
48 {
49 free(window->context.osmesa.buffer);
50
51 // Allocate the new buffer (width * height * 8-bit RGBA)
52 window->context.osmesa.buffer = calloc(4, (size_t) width * height);
53 window->context.osmesa.width = width;
54 window->context.osmesa.height = height;
55 }
56
58 window->context.osmesa.buffer,
60 width, height))
61 {
63 "OSMesa: Failed to make context current");
64 return;
65 }
66 }
67
69}
70
71static GLFWglproc getProcAddressOSMesa(const char* procname)
72{
73 return (GLFWglproc) OSMesaGetProcAddress(procname);
74}
75
76static void destroyContextOSMesa(_GLFWwindow* window)
77{
78 if (window->context.osmesa.handle)
79 {
81 window->context.osmesa.handle = NULL;
82 }
83
84 if (window->context.osmesa.buffer)
85 {
86 free(window->context.osmesa.buffer);
87 window->context.osmesa.width = 0;
88 window->context.osmesa.height = 0;
89 }
90}
91
92static void swapBuffersOSMesa(_GLFWwindow* window)
93{
94 // No double buffering on OSMesa
95}
96
97static void swapIntervalOSMesa(int interval)
98{
99 // No swap interval on OSMesa
100}
101
102static int extensionSupportedOSMesa(const char* extension)
103{
104 // OSMesa does not have extensions
105 return GLFW_FALSE;
106}
107
108
112
114{
115 int i;
116 const char* sonames[] =
117 {
118#if defined(_GLFW_OSMESA_LIBRARY)
119 _GLFW_OSMESA_LIBRARY,
120#elif defined(_WIN32)
121 "libOSMesa.dll",
122 "OSMesa.dll",
123#elif defined(__APPLE__)
124 "libOSMesa.8.dylib",
125#elif defined(__CYGWIN__)
126 "libOSMesa-8.so",
127#else
128 "libOSMesa.so.8",
129 "libOSMesa.so.6",
130#endif
131 NULL
132 };
133
134 if (_glfw.osmesa.handle)
135 return GLFW_TRUE;
136
137 for (i = 0; sonames[i]; i++)
138 {
139 _glfw.osmesa.handle = _glfw_dlopen(sonames[i]);
140 if (_glfw.osmesa.handle)
141 break;
142 }
143
144 if (!_glfw.osmesa.handle)
145 {
146 _glfwInputError(GLFW_API_UNAVAILABLE, "OSMesa: Library not found");
147 return GLFW_FALSE;
148 }
149
151 _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextExt");
153 _glfw_dlsym(_glfw.osmesa.handle, "OSMesaCreateContextAttribs");
155 _glfw_dlsym(_glfw.osmesa.handle, "OSMesaDestroyContext");
157 _glfw_dlsym(_glfw.osmesa.handle, "OSMesaMakeCurrent");
159 _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetColorBuffer");
161 _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetDepthBuffer");
163 _glfw_dlsym(_glfw.osmesa.handle, "OSMesaGetProcAddress");
164
171 {
173 "OSMesa: Failed to load required entry points");
174
176 return GLFW_FALSE;
177 }
178
179 return GLFW_TRUE;
180}
181
183{
184 if (_glfw.osmesa.handle)
185 {
188 }
189}
190
191#define setAttrib(a, v) \
192{ \
193 assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
194 attribs[index++] = a; \
195 attribs[index++] = v; \
196}
197
199 const _GLFWctxconfig* ctxconfig,
200 const _GLFWfbconfig* fbconfig)
201{
202 OSMesaContext share = NULL;
203 const int accumBits = fbconfig->accumRedBits +
204 fbconfig->accumGreenBits +
205 fbconfig->accumBlueBits +
206 fbconfig->accumAlphaBits;
207
208 if (ctxconfig->client == GLFW_OPENGL_ES_API)
209 {
211 "OSMesa: OpenGL ES is not available on OSMesa");
212 return GLFW_FALSE;
213 }
214
215 if (ctxconfig->share)
216 share = ctxconfig->share->context.osmesa.handle;
217
219 {
220 int index = 0, attribs[40];
221
225 setAttrib(OSMESA_ACCUM_BITS, accumBits);
226
227 if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE)
228 {
230 }
231 else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE)
232 {
234 }
235
236 if (ctxconfig->major != 1 || ctxconfig->minor != 0)
237 {
240 }
241
242 if (ctxconfig->forward)
243 {
245 "OSMesa: Forward-compatible contexts not supported");
246 return GLFW_FALSE;
247 }
248
249 setAttrib(0, 0);
250
251 window->context.osmesa.handle =
252 OSMesaCreateContextAttribs(attribs, share);
253 }
254 else
255 {
256 if (ctxconfig->profile)
257 {
259 "OSMesa: OpenGL profiles unavailable");
260 return GLFW_FALSE;
261 }
262
263 window->context.osmesa.handle =
265 fbconfig->depthBits,
266 fbconfig->stencilBits,
267 accumBits,
268 share);
269 }
270
271 if (window->context.osmesa.handle == NULL)
272 {
274 "OSMesa: Failed to create context");
275 return GLFW_FALSE;
276 }
277
278 window->context.makeCurrent = makeContextCurrentOSMesa;
279 window->context.swapBuffers = swapBuffersOSMesa;
280 window->context.swapInterval = swapIntervalOSMesa;
281 window->context.extensionSupported = extensionSupportedOSMesa;
282 window->context.getProcAddress = getProcAddressOSMesa;
283 window->context.destroy = destroyContextOSMesa;
284
285 return GLFW_TRUE;
286}
287
288#undef setAttrib
289
290
294
296 int* height, int* format, void** buffer)
297{
298 void* mesaBuffer;
299 GLint mesaWidth, mesaHeight, mesaFormat;
300 _GLFWwindow* window = (_GLFWwindow*) handle;
301 assert(window != NULL);
302
304
306 &mesaWidth, &mesaHeight,
307 &mesaFormat, &mesaBuffer))
308 {
310 "OSMesa: Failed to retrieve color buffer");
311 return GLFW_FALSE;
312 }
313
314 if (width)
315 *width = mesaWidth;
316 if (height)
317 *height = mesaHeight;
318 if (format)
319 *format = mesaFormat;
320 if (buffer)
321 *buffer = mesaBuffer;
322
323 return GLFW_TRUE;
324}
325
327 int* width, int* height,
328 int* bytesPerValue,
329 void** buffer)
330{
331 void* mesaBuffer;
332 GLint mesaWidth, mesaHeight, mesaBytes;
333 _GLFWwindow* window = (_GLFWwindow*) handle;
334 assert(window != NULL);
335
337
339 &mesaWidth, &mesaHeight,
340 &mesaBytes, &mesaBuffer))
341 {
343 "OSMesa: Failed to retrieve depth buffer");
344 return GLFW_FALSE;
345 }
346
347 if (width)
348 *width = mesaWidth;
349 if (height)
350 *height = mesaHeight;
351 if (bytesPerValue)
352 *bytesPerValue = mesaBytes;
353 if (buffer)
354 *buffer = mesaBuffer;
355
356 return GLFW_TRUE;
357}
358
360{
361 _GLFWwindow* window = (_GLFWwindow*) handle;
363
364 if (window->context.client == GLFW_NO_API)
365 {
367 return NULL;
368 }
369
370 return window->context.osmesa.handle;
371}
372
#define _glfw_dlopen(name)
#define _glfw_dlsym(handle, name)
#define _glfw_dlclose(handle)
void _glfwPlatformGetFramebufferSize(_GLFWwindow *window, int *width, int *height)
int GLint
Definition: glad.h:2314
#define GL_UNSIGNED_BYTE
Definition: glad.h:1861
#define GLFW_OPENGL_ES_API
Definition: glfw3.h:1088
#define GLFWAPI
Definition: glfw3.h:269
#define GLFW_NO_API
Definition: glfw3.h:1086
#define GLFW_OPENGL_COMPAT_PROFILE
Definition: glfw3.h:1096
#define GLFW_OPENGL_CORE_PROFILE
Definition: glfw3.h:1095
void(* GLFWglproc)(void)
GLFW API types.
Definition: glfw3.h:1281
#define GLFW_API_UNAVAILABLE
GLFW could not find support for the requested API on the system.
Definition: glfw3.h:730
#define GLFW_NO_WINDOW_CONTEXT
The specified window does not have an OpenGL or OpenGL ES context.
Definition: glfw3.h:785
#define GLFW_VERSION_UNAVAILABLE
The requested OpenGL or OpenGL ES version is not available.
Definition: glfw3.h:747
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
Definition: glfw3.h:758
#define GLFW_TRUE
One.
Definition: glfw3.h:310
#define GLFW_FALSE
Zero.
Definition: glfw3.h:319
struct GLFWwindow GLFWwindow
Opaque window object.
Definition: glfw3.h:1319
_GLFWlibrary _glfw
Definition: init.c:46
void _glfwInputError(int code, const char *format,...)
Definition: init.c:160
void _glfwPlatformSetTls(_GLFWtls *tls, void *value)
Definition: posix_thread.c:68
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
Definition: internal.h:214
int GLFWbool
Definition: internal.h:61
#define NULL
Definition: miniaudio.h:3718
GLFWbool _glfwCreateContextOSMesa(_GLFWwindow *window, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
void _glfwTerminateOSMesa(void)
GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow *handle, int *width, int *height, int *bytesPerValue, void **buffer)
#define setAttrib(a, v)
GLFWbool _glfwInitOSMesa(void)
GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow *handle, int *width, int *height, int *format, void **buffer)
GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow *handle)
GLFWglproc(GLAPIENTRY * PFN_OSMesaGetProcAddress)(const char *)
int(GLAPIENTRY * PFN_OSMesaGetDepthBuffer)(OSMesaContext, int *, int *, int *, void **)
#define OSMESA_ACCUM_BITS
OSMesaContext(GLAPIENTRY * PFN_OSMesaCreateContextAttribs)(const int *, OSMesaContext)
OSMesaContext(GLAPIENTRY * PFN_OSMesaCreateContextExt)(GLenum, GLint, GLint, GLint, OSMesaContext)
#define OSMesaGetDepthBuffer
#define OSMESA_STENCIL_BITS
#define OSMESA_CORE_PROFILE
#define OSMesaGetProcAddress
#define OSMesaGetColorBuffer
int(GLAPIENTRY * PFN_OSMesaGetColorBuffer)(OSMesaContext, int *, int *, int *, void **)
#define OSMesaDestroyContext
#define OSMesaMakeCurrent
#define OSMesaCreateContextExt
#define OSMESA_FORMAT
#define OSMESA_DEPTH_BITS
#define OSMESA_CONTEXT_MINOR_VERSION
#define OSMESA_CONTEXT_MAJOR_VERSION
void * OSMesaContext
#define OSMesaCreateContextAttribs
#define OSMESA_PROFILE
void(GLAPIENTRY * PFN_OSMesaDestroyContext)(OSMesaContext)
#define OSMESA_RGBA
int(GLAPIENTRY * PFN_OSMesaMakeCurrent)(OSMesaContext, void *, int, int, int)
#define OSMESA_COMPAT_PROFILE
_GLFWswapintervalfun swapInterval
Definition: internal.h:362
_GLFWswapbuffersfun swapBuffers
Definition: internal.h:361
_GLFWdestroycontextfun destroy
Definition: internal.h:365
_GLFWcontextOSMesa osmesa
Definition: internal.h:372
_GLFWmakecontextcurrentfun makeCurrent
Definition: internal.h:360
_GLFWextensionsupportedfun extensionSupported
Definition: internal.h:363
_GLFWgetprocaddressfun getProcAddress
Definition: internal.h:364
OSMesaContext handle
_GLFWwindow * share
Definition: internal.h:309
GLFWbool forward
Definition: internal.h:303
int accumBlueBits
Definition: internal.h:333
int stencilBits
Definition: internal.h:330
int accumGreenBits
Definition: internal.h:332
int accumAlphaBits
Definition: internal.h:334
int accumRedBits
Definition: internal.h:331
_GLFWtls contextSlot
Definition: internal.h:552
_GLFWlibraryOSMesa osmesa
Definition: internal.h:597
PFN_OSMesaGetProcAddress GetProcAddress
PFN_OSMesaGetDepthBuffer GetDepthBuffer
PFN_OSMesaDestroyContext DestroyContext
PFN_OSMesaMakeCurrent MakeCurrent
PFN_OSMesaGetColorBuffer GetColorBuffer
PFN_OSMesaCreateContextAttribs CreateContextAttribs
PFN_OSMesaCreateContextExt CreateContextExt
_GLFWcontext context
Definition: internal.h:409