1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * GLX implementation that uses Apple's OpenGL.framework 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Copyright (c) 2007-2011 Apple Inc. 5bf215546Sopenharmony_ci * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved. 6bf215546Sopenharmony_ci * Copyright (c) 2002 Greg Parker. All Rights Reserved. 7bf215546Sopenharmony_ci * 8bf215546Sopenharmony_ci * Portions of this file are copied from Mesa's xf86glx.c, 9bf215546Sopenharmony_ci * which contains the following copyright: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. 12bf215546Sopenharmony_ci * All Rights Reserved. 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 15bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 16bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 17bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 18bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 19bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 20bf215546Sopenharmony_ci * 21bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 22bf215546Sopenharmony_ci * all copies or substantial portions of the Software. 23bf215546Sopenharmony_ci * 24bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 27bf215546Sopenharmony_ci * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 28bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 29bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 30bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 31bf215546Sopenharmony_ci */ 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#include <assert.h> 34bf215546Sopenharmony_ci#include <dlfcn.h> 35bf215546Sopenharmony_ci#include <stdlib.h> 36bf215546Sopenharmony_ci#include <string.h> 37bf215546Sopenharmony_ci#include <stdio.h> 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci#include <GL/gl.h> 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci#include "main/glheader.h" 42bf215546Sopenharmony_ci#include "glapi.h" 43bf215546Sopenharmony_ci#include "glapitable.h" 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci#include "apple_glx.h" 46bf215546Sopenharmony_ci#include "apple_xgl_api.h" 47bf215546Sopenharmony_ci#include "apple_cgl.h" 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_cistruct _glapi_table * __ogl_framework_api = NULL; 50bf215546Sopenharmony_cistruct _glapi_table * __applegl_api = NULL; 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_cistatic void _apple_glapi_create_table(void) { 53bf215546Sopenharmony_ci if (__applegl_api) 54bf215546Sopenharmony_ci return; 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci __ogl_framework_api = _glapi_create_table_from_handle(apple_cgl_get_dl_handle(), "gl"); 57bf215546Sopenharmony_ci assert(__ogl_framework_api); 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci __applegl_api = malloc(sizeof(struct _glapi_table)); 60bf215546Sopenharmony_ci assert(__applegl_api); 61bf215546Sopenharmony_ci memcpy(__applegl_api, __ogl_framework_api, sizeof(struct _glapi_table)); 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci _glapi_table_patch(__applegl_api, "ReadPixels", __applegl_glReadPixels); 64bf215546Sopenharmony_ci _glapi_table_patch(__applegl_api, "CopyPixels", __applegl_glCopyPixels); 65bf215546Sopenharmony_ci _glapi_table_patch(__applegl_api, "CopyColorTable", __applegl_glCopyColorTable); 66bf215546Sopenharmony_ci _glapi_table_patch(__applegl_api, "DrawBuffers", __applegl_glDrawBuffer); 67bf215546Sopenharmony_ci _glapi_table_patch(__applegl_api, "Viewport", __applegl_glViewport); 68bf215546Sopenharmony_ci} 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_civoid apple_glapi_set_dispatch(void) { 71bf215546Sopenharmony_ci _apple_glapi_create_table(); 72bf215546Sopenharmony_ci _glapi_set_dispatch(__applegl_api); 73bf215546Sopenharmony_ci} 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_civoid apple_glapi_oglfw_viewport_scissor(GLint x, GLint y, GLsizei width, GLsizei height) { 76bf215546Sopenharmony_ci _apple_glapi_create_table(); 77bf215546Sopenharmony_ci __ogl_framework_api->Viewport(x, y, width, height); 78bf215546Sopenharmony_ci __ogl_framework_api->Scissor(x, y, width, height); 79bf215546Sopenharmony_ci} 80