1 /*
2 OSMesa LDG linker, misc functions
3
4 Copyright (C) 2004 Patrice Mandin
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /*--- Includes ---*/
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <mint/osbind.h>
27
28 #include "lib-osmesa.h"
29 #include "lib-oldmesa.h"
30 #include "nfosmesa_nfapi.h"
31
32 /*--- Defines ---*/
33
34 #define GL_VENDOR 0x1F00
35 #define GL_RENDERER 0x1F01
36 #define GL_VERSION 0x1F02
37 #define GL_EXTENSIONS 0x1F03
38 #define GL_SHADING_LANGUAGE_VERSION 0x8B8C
39
40 /*--- Variables ---*/
41
42 static const GLubyte empty_str[1];
43
44 /*--- Functions ---*/
45
internal_glGetString(gl_private * private,GLenum name)46 const GLubyte* APIENTRY internal_glGetString( gl_private *private, GLenum name )
47 {
48 int i;
49 size_t len;
50 unsigned int c = CTX_TO_IDX(private->cur_context);
51 if (c == 0)
52 return empty_str;
53
54 switch(name) {
55 case GL_VERSION:
56 i=1;
57 break;
58 case GL_RENDERER:
59 i=2;
60 break;
61 case GL_VENDOR:
62 i=3;
63 break;
64 case GL_EXTENSIONS:
65 i=4;
66 break;
67 default:
68 return empty_str;
69 }
70
71 if (private->contexts[c].gl_strings[i]==NULL) {
72 unsigned long params[3];
73
74 params[0] = (unsigned long) private->cur_context;
75 params[1] = (unsigned long) name;
76
77 len = (*HostCall_p)(NFOSMESA_LENGLGETSTRING, private->cur_context, params);
78 private->contexts[c].gl_strings[i] = (GLubyte *)private->pub.m_alloc(len+1);
79 if (private->contexts[c].gl_strings[i]) {
80 params[0] = (unsigned long) private->cur_context;
81 params[1] = (unsigned long) name;
82 params[2] = (unsigned long) private->contexts[c].gl_strings[i];
83 (*HostCall_p)(NFOSMESA_PUTGLGETSTRING, private->cur_context, params);
84 } else {
85 return empty_str;
86 }
87 }
88
89 return private->contexts[c].gl_strings[i];
90 }
91
internal_glGetStringi(gl_private * private,GLenum name,GLuint index)92 const GLubyte* APIENTRY internal_glGetStringi(gl_private *private, GLenum name, GLuint index )
93 {
94 int i;
95 size_t len;
96 unsigned int c = CTX_TO_IDX(private->cur_context);
97 if (c == 0)
98 return empty_str;
99
100 switch(name) {
101 case GL_EXTENSIONS:
102 i=5;
103 break;
104 case GL_SHADING_LANGUAGE_VERSION:
105 i=6;
106 break;
107 default:
108 return empty_str;
109 }
110
111 if (private->contexts[c].gl_strings[i]!=NULL) {
112 private->pub.m_free(private->contexts[c].gl_strings[i]);
113 private->contexts[c].gl_strings[i] = NULL;
114 }
115 {
116 unsigned long params[4];
117
118 params[0] = (unsigned long) private->cur_context;
119 params[1] = (unsigned long) name;
120 params[2] = (unsigned long) index;
121
122 len = (*HostCall_p)(NFOSMESA_LENGLGETSTRINGI, private->cur_context, params);
123 if (len < 0)
124 return NULL;
125 private->contexts[c].gl_strings[i] = (GLubyte *)private->pub.m_alloc(len+1);
126 if (private->contexts[c].gl_strings[i]) {
127 params[0] = (unsigned long) private->cur_context;
128 params[1] = (unsigned long) name;
129 params[2] = (unsigned long) index;
130 params[3] = (unsigned long) private->contexts[c].gl_strings[i];
131 (*HostCall_p)(NFOSMESA_PUTGLGETSTRINGI, private->cur_context, params);
132 } else {
133 return empty_str;
134 }
135 }
136
137 return private->contexts[c].gl_strings[i];
138 }
139
freeglGetString(gl_private * private,OSMesaContext ctx)140 void freeglGetString(gl_private *private, OSMesaContext ctx)
141 {
142 int i;
143 unsigned int c = CTX_TO_IDX(ctx);
144
145 for (i=1;i<7;i++) {
146 if (private->contexts[c].gl_strings[i]) {
147 private->pub.m_free(private->contexts[c].gl_strings[i]);
148 private->contexts[c].gl_strings[i]=NULL;
149 }
150 }
151 }
152
internal_tinyglswapbuffer(gl_private * private,void * buf)153 void APIENTRY internal_tinyglswapbuffer(gl_private *private, void *buf)
154 {
155 (*HostCall_p)(NFOSMESA_TINYGLSWAPBUFFER, private->cur_context, &buf);
156 }
157
158
internal_tinyglexception_error(gl_private * private,void CALLBACK (* exception)(GLenum param))159 void APIENTRY internal_tinyglexception_error(gl_private *private, void CALLBACK (*exception)(GLenum param))
160 {
161 private->gl_exception = exception;
162 }
163
164
gl_exception_error(gl_private * private,GLenum exception)165 int gl_exception_error(gl_private *private, GLenum exception)
166 {
167 if (private->gl_exception)
168 {
169 (*private->gl_exception)(exception);
170 return 1;
171 }
172 return 0;
173 }
174
175
gl_fatal_error(gl_private * private,GLenum error,long except,const char * format)176 void gl_fatal_error(gl_private *private, GLenum error, long except, const char *format)
177 {
178 if (!gl_exception_error(private, except))
179 {
180 static char const err[] = "TinyGL: fatal error: ";
181 (void) Fwrite(2, sizeof(err) - 1, err);
182 (void) Fwrite(2, strlen(format), format);
183 (void) Fwrite(2, 2, "\r\n");
184 }
185 }
186