summaryrefslogtreecommitdiff
path: root/es_1_1/29buffer.c
blob: d8b6a4a7db6767a2ec3341868a923f6b10fb057f (plain)
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
/* 
 * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 * 
 * Contact:
 * DongKyun Yun <dk77.yun@samsung.com>
 * SangJin Kim <sangjin3.kim@samsung.com>
 * HyunGoo Kang <hyungoo1.kang@samsung.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 * 
 * Contributors:
 * - S-Core Co., Ltd
 *
 */

#include "gl_imp.h"
#include <malloc.h>
#include <string.h>

#if ! defined(GL_BUFFER_ACCESS)
#define	GL_BUFFER_ACCESS	0x88BB	
#endif
#if ! defined(GL_WRITE_ONLY)
#define	GL_WRITE_ONLY		0x88B9	
#endif

static void INTFN(ResizeBuffer)(int n) {
	if (CCV(nBuffer) <= n) {
		int newSize = CCV(nBuffer);
		while (newSize <= n) { newSize *= 2; }
		CCV(pBufferStatus) = realloc(CCV(pBufferStatus), newSize * sizeof(GLint));
		memset(CCV(pBufferStatus) + CCV(nBuffer), 0, (newSize - CCV(nBuffer)) * sizeof(GLint));
		CCV(nBuffer) = newSize;
	}
}

#if ALEXGL_INTERNAL_VERSION >= 110
GL_API void GL_APIENTRY EXTFN(GenBuffers)(GLsizei n, GLuint* buffers) {
	int max;
	int i;
	FNPTR(GenBuffers)(n, buffers);
	max = 0;
	for (i = 0; buffers != NULL && i < n; i++) {
		if (buffers[i] > max) max = buffers[i];
	}
	INTFN(ResizeBuffer)(max);
	for (i = 0; buffers != NULL && i < n; i++) {
		CCV(pBufferStatus)[buffers[i]] = ALEXGL_BUFFER_GENERATED;
	}
}
#endif

#if ALEXGL_INTERNAL_VERSION >= 110
GL_API void GL_APIENTRY EXTFN(BindBuffer)(GLenum target, GLuint buffer) {
	if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) {
		INTFN(SetError)(GL_INVALID_ENUM);
		return;
	}
	FNPTR(BindBuffer)(target, buffer);
	INTFN(ResizeBuffer)(buffer);
	CCV(pBufferStatus)[buffer] = ALEXGL_BUFFER_BOUND;
}
#endif

#if ALEXGL_INTERNAL_VERSION >= 110
GL_API void GL_APIENTRY EXTFN(DeleteBuffers)(GLsizei n, const GLuint* buffers) {
	int max;
	int i;
	FNPTR(DeleteBuffers)(n, buffers);
	max = 0;
	for (i = 0; buffers != NULL && i < n; i++) {
		if (buffers[i] > max) max = buffers[i];
	}
	INTFN(ResizeBuffer)(max);
	for (i = 0; buffers != NULL && i < n; i++) {
		CCV(pBufferStatus)[buffers[i]] = ALEXGL_BUFFER_NULL;
	}
}
#endif

#if ALEXGL_INTERNAL_VERSION >= 110
GL_API GLboolean GL_APIENTRY EXTFN(IsBuffer)(GLuint buffer) {
	register GLboolean bAnswer;
	bAnswer = FNPTR(IsBuffer)(buffer);
	INTFN(ResizeBuffer)(buffer);
	if (bAnswer == GL_TRUE && CCV(pBufferStatus)[buffer] != ALEXGL_BUFFER_BOUND) {
		bAnswer = GL_FALSE;
	}
	return (bAnswer == GL_FALSE) ? GL_FALSE : GL_TRUE;
}
#endif

#if ALEXGL_INTERNAL_VERSION >= 110
GL_API void GL_APIENTRY EXTFN(GetBufferParameteriv)(GLenum target, GLenum pname, GLint* params) {
	if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) {
		INTFN(SetError)(GL_INVALID_ENUM);
		return;
	}
	if (pname != GL_BUFFER_SIZE && pname != GL_BUFFER_USAGE && pname != GL_BUFFER_ACCESS) {
		INTFN(SetError)(GL_INVALID_ENUM);
		return;
	}
	FNPTR(GetBufferParameteriv)(target, pname, params);
	if (pname == GL_BUFFER_ACCESS && *params == GL_READ_WRITE) {
		*params = GL_WRITE_ONLY;
	}
}
#endif

#if ALEXGL_INTERNAL_VERSION >= 110
GL_API void GL_APIENTRY EXTFN(BufferData)(GLenum target,
		GLsizeiptr size, const GLvoid* data, GLenum usage) {
	if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) {
		INTFN(SetError)(GL_INVALID_ENUM);
		return;
	}
	if (usage != GL_STATIC_DRAW && usage != GL_DYNAMIC_DRAW) {
		INTFN(SetError)(GL_INVALID_ENUM);
		return;
	}
	FNPTR(BufferData)(target, size, data, usage);
}
#endif

#if ALEXGL_INTERNAL_VERSION >= 110
GL_API void GL_APIENTRY EXTFN(BufferSubData)(GLenum target,
		GLintptr offset, GLsizeiptr size, const GLvoid* data) {
	if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) {
		INTFN(SetError)(GL_INVALID_ENUM);
		return;
	}
	FNPTR(BufferSubData)(target, offset, size, data);
}
#endif