MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / ParsePointer

Function ParsePointer

src/lua/LuaGLPointers.cpp:181–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179//============================================================================//
180
181static const void* ParsePointer(lua_State* L, int index, GLsizei count,
182 GLenum* dataType, int& maxElem, bool& useVBO,
183 GLenum arrayType) {
184 const char* data = NULL;
185 size_t size;
186 size_t offset = 0;
187 GLuint bufID = 0;
188
189 if (dataType != NULL) {
190 *dataType = (GLenum)luaL_checkint(L, index);
191 index++;
192 }
193
194 if (lua_israwstring(L, index)) {
195 data = lua_tolstring(L, index, &size);
196 offset = luaL_optint(L, index + 1, 0) ;
197 }
198 else {
199 const LuaGLBuffer* buf = LuaGLBufferMgr::TestLuaGLBuffer(L, index);
200 if (buf == NULL) {
201 luaL_error(L, "invalid data source");
202 }
203 offset = luaL_optint(L, index + 1, 0);
204
205 size = buf->size;
206 bufID = buf->id;
207
208 if (bufID == 0) {
209 maxElem = 0;
210 return NULL;
211 }
212 }
213
214 if (offset > size) {
215 luaL_error(L, "offset exceeds data size");
216 }
217 data += offset;
218 size -= offset;
219
220 const int typeSize = LuaGLBufferMgr::GetTypeSize(*dataType);
221 if (typeSize <= 0) {
222 maxElem = 0;
223 }
224 maxElem = size / (count * typeSize);
225 if (maxElem <= 0) {
226 return NULL;
227 }
228
229 if (bufID == 0) {
230 useVBO = false;
231 }
232 else {
233 useVBO = true;
234 glBindBuffer(GL_ARRAY_BUFFER, bufID);
235 }
236
237 CreateLuaRef(L, index, arrayType);
238 maxElements[arrayType] = maxElem;

Callers 7

VertexPointerMethod · 0.85
NormalPointerMethod · 0.85
HandleTexCoordPointerFunction · 0.85
ColorPointerMethod · 0.85
EdgeFlagPointerMethod · 0.85
VertexAttribPointerMethod · 0.85
VertexAttribIPointerMethod · 0.85

Calls 5

lua_israwstringFunction · 0.85
CreateLuaRefFunction · 0.85
UpdateMinElementFunction · 0.85
lua_tolstringFunction · 0.50
luaL_errorFunction · 0.50

Tested by

no test coverage detected