File: lib-misc.c

package info (click to toggle)
aranym 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,488 kB
  • sloc: cpp: 178,117; ansic: 170,405; perl: 5,637; sh: 5,547; asm: 2,282; makefile: 1,324; objc: 218
file content (185 lines) | stat: -rw-r--r-- 4,620 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
	OSMesa LDG linker, misc functions

	Copyright (C) 2004	Patrice Mandin

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

/*--- Includes ---*/

#include <stdlib.h>
#include <string.h>

#include <mint/osbind.h>

#include "lib-osmesa.h"
#include "lib-oldmesa.h"
#include "nfosmesa_nfapi.h"

/*--- Defines ---*/

#define GL_VENDOR     0x1F00
#define GL_RENDERER   0x1F01
#define GL_VERSION    0x1F02
#define GL_EXTENSIONS 0x1F03
#define GL_SHADING_LANGUAGE_VERSION       0x8B8C

/*--- Variables ---*/

static const GLubyte empty_str[1];

/*--- Functions ---*/

const GLubyte* APIENTRY internal_glGetString( gl_private *private, GLenum name )
{
	int i;
	size_t len;
	unsigned int c = CTX_TO_IDX(private->cur_context);
	if (c == 0)
		return empty_str;
	
	switch(name) {
		case GL_VERSION:
			i=1;
			break;
		case GL_RENDERER:
			i=2;
			break;
		case GL_VENDOR:
			i=3;
			break;
		case GL_EXTENSIONS:
			i=4;
			break;
		default:
			return empty_str;
	}

	if (private->contexts[c].gl_strings[i]==NULL) {
		unsigned long params[3];
		
		params[0] = (unsigned long) private->cur_context;
		params[1] = (unsigned long) name;

		len = (*HostCall_p)(NFOSMESA_LENGLGETSTRING, private->cur_context, params);
		private->contexts[c].gl_strings[i] = (GLubyte *)private->pub.m_alloc(len+1);
		if (private->contexts[c].gl_strings[i]) {
			params[0] = (unsigned long) private->cur_context;
			params[1] = (unsigned long) name;
			params[2] = (unsigned long) private->contexts[c].gl_strings[i];
			(*HostCall_p)(NFOSMESA_PUTGLGETSTRING, private->cur_context, params);
		} else {
			return empty_str;
		}
	}

	return private->contexts[c].gl_strings[i];
}

const GLubyte* APIENTRY internal_glGetStringi(gl_private *private, GLenum name, GLuint index )
{
	int i;
	size_t len;
	unsigned int c = CTX_TO_IDX(private->cur_context);
	if (c == 0)
		return empty_str;
	
	switch(name) {
		case GL_EXTENSIONS:
			i=5;
			break;
		case GL_SHADING_LANGUAGE_VERSION:
			i=6;
			break;
		default:
			return empty_str;
	}

	if (private->contexts[c].gl_strings[i]!=NULL) {
		private->pub.m_free(private->contexts[c].gl_strings[i]);
		private->contexts[c].gl_strings[i] = NULL;
	}
	{
		unsigned long params[4];
		
		params[0] = (unsigned long) private->cur_context;
		params[1] = (unsigned long) name;
		params[2] = (unsigned long) index;

		len = (*HostCall_p)(NFOSMESA_LENGLGETSTRINGI, private->cur_context, params);
		if (len < 0)
			return NULL;
		private->contexts[c].gl_strings[i] = (GLubyte *)private->pub.m_alloc(len+1);
		if (private->contexts[c].gl_strings[i]) {
			params[0] = (unsigned long) private->cur_context;
			params[1] = (unsigned long) name;
			params[2] = (unsigned long) index;
			params[3] = (unsigned long) private->contexts[c].gl_strings[i];
			(*HostCall_p)(NFOSMESA_PUTGLGETSTRINGI, private->cur_context, params);
		} else {
			return empty_str;
		}
	}

	return private->contexts[c].gl_strings[i];
}

void freeglGetString(gl_private *private, OSMesaContext ctx)
{
	int i;
	unsigned int c = CTX_TO_IDX(ctx);
	
	for (i=1;i<7;i++) {
		if (private->contexts[c].gl_strings[i]) {
			private->pub.m_free(private->contexts[c].gl_strings[i]);
			private->contexts[c].gl_strings[i]=NULL;
		}
	}
}

void APIENTRY internal_tinyglswapbuffer(gl_private *private, void *buf)
{
	(*HostCall_p)(NFOSMESA_TINYGLSWAPBUFFER, private->cur_context, &buf);
}


void APIENTRY internal_tinyglexception_error(gl_private *private, void CALLBACK (*exception)(GLenum param))
{
	private->gl_exception = exception;
}


int gl_exception_error(gl_private *private, GLenum exception)
{
	if (private->gl_exception)
	{
		(*private->gl_exception)(exception);
		return 1;
	}
	return 0;
}


void gl_fatal_error(gl_private *private, GLenum error, long except, const char *format)
{
	if (!gl_exception_error(private, except))
	{
		static char const err[] = "TinyGL: fatal error: ";
		(void) Fwrite(2, sizeof(err) - 1, err);
		(void) Fwrite(2, strlen(format), format);
		(void) Fwrite(2, 2, "\r\n");
	}
}