pack_client.c revision df504dfa2b5b186f4cac7f7859eabd09b30eebf0
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/* Copyright (c) 2001, Stanford University
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * All rights reserved
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync *
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * See the file LICENSE.txt for information on redistributing this software.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "packer.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "cr_opcodes.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#include "cr_version.h"
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#include "state/cr_limits.h"
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#include "cr_glstate.h"
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync/*Convert from GLint to GLfloat in [-1.f,1.f]*/
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync#define CRP_I2F_NORM(i) ((2.f*((GLint)(i))+1.f) * (1.f/4294967294.f))
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync/*Convert from GLshort to GLfloat in [-1.f,1.f]*/
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync#define CRP_S2F_NORM(s) ((2.f*((GLshort)(s))+1.f) * (1.f/65535.f))
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync/*Convert from GLbyte to GLfloat in [-1.f,1.f]*/
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync#define CRP_B2F_NORM(b) ((2.f*((GLbyte)(b))+1.f) * (1.f/255.f))
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync/*Convert from GLuint to GLfloat in [0.f,1.f]*/
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync#define CRP_UI2F_NORM(i) ((GLfloat)(i) * (1.f/4294967295.f))
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync/*Convert from GLushort to GLfloat in [0.f,1.f]*/
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync#define CRP_US2F_NORM(s) ((GLfloat)(s) * (1.f/65535.f))
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync/*Convert from GLubyte to GLfloat in [0.f,1.f]*/
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync#define CRP_UB2F_NORM(b) ((GLfloat)(b) * (1.f/255.f))
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncstatic void crPackVertexAttrib(const CRVertexArrays *array, unsigned int attr, GLint index)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync unsigned char *p = array->a[attr].p + index * array->a[attr].stride;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->a[attr].buffer && array->a[attr].buffer->data)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->a[attr].buffer->data) + (unsigned long)p;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync if (!p)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crWarning("crPackVertexAttrib: NULL ptr!");
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync return;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->a[attr].type)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_SHORT:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLshort *sPtr = (GLshort*) p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->a[attr].size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 1:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->a[attr].normalized)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib1fARB(attr, CRP_S2F_NORM(sPtr[0]));
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync else
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib1svARB(attr, sPtr);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->a[attr].normalized)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib2fARB(attr, CRP_S2F_NORM(sPtr[0]), CRP_S2F_NORM(sPtr[1]));
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync else
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib2svARB(attr, sPtr);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->a[attr].normalized)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib3fARB(attr, CRP_S2F_NORM(sPtr[0]), CRP_S2F_NORM(sPtr[1]), CRP_S2F_NORM(sPtr[2]));
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync else
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib3svARB(attr, sPtr);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 4:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->a[attr].normalized)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib4NsvARB(attr, sPtr);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync else
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib4svARB(attr, sPtr);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case GL_UNSIGNED_SHORT:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLushort *usPtr = (GLushort*) p;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync if (array->a[attr].normalized)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 1:
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync crPackVertexAttrib1fARB(attr, CRP_US2F_NORM(usPtr[0]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib2fARB(attr, CRP_US2F_NORM(usPtr[0]), CRP_US2F_NORM(usPtr[1]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib3fARB(attr, CRP_US2F_NORM(usPtr[0]), CRP_US2F_NORM(usPtr[1]), CRP_US2F_NORM(usPtr[2]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4NusvARB(attr, usPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync else
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLushort usv[4];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4usvARB(attr, usPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3: usv[2] = usPtr[2];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2: usv[1] = usPtr[1];
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 1:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync usv[0] = usPtr[0];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4usvARB(attr, usv);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_INT:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLint *iPtr = (GLint*) p;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync if (array->a[attr].normalized)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 1:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib1fARB(attr, CRP_I2F_NORM(iPtr[0]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib2fARB(attr, CRP_I2F_NORM(iPtr[0]), CRP_I2F_NORM(iPtr[1]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib3fARB(attr, CRP_I2F_NORM(iPtr[0]), CRP_I2F_NORM(iPtr[1]), CRP_I2F_NORM(iPtr[2]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 4:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib4NivARB(attr, iPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync else
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLint iv[4];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4ivARB(attr, iPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3: iv[2] = iPtr[2];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2: iv[1] = iPtr[1];
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 1:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync iv[0] = iPtr[0];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4ivARB(attr, iv);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case GL_UNSIGNED_INT:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLuint *uiPtr = (GLuint*) p;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync if (array->a[attr].normalized)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 1:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib1fARB(attr, CRP_UI2F_NORM(uiPtr[0]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib2fARB(attr, CRP_UI2F_NORM(uiPtr[0]), CRP_UI2F_NORM(uiPtr[1]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib3fARB(attr, CRP_UI2F_NORM(uiPtr[0]), CRP_UI2F_NORM(uiPtr[1]), CRP_UI2F_NORM(uiPtr[2]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4NivARB(attr, uiPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync else
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLuint uiv[4];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4uivARB(attr, uiPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3: uiv[2] = uiPtr[2];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2: uiv[1] = uiPtr[1];
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 1:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync uiv[0] = uiPtr[0];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4uivARB(attr, uiv);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_FLOAT:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->a[attr].size)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 1: crPackVertexAttrib1fvARB(attr, (GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackVertexAttrib2fvARB(attr, (GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackVertexAttrib3fvARB(attr, (GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackVertexAttrib4fvARB(attr, (GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_DOUBLE:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->a[attr].size)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 1: crPackVertexAttrib1dvARB(attr, (GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackVertexAttrib2dvARB(attr, (GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackVertexAttrib3dvARB(attr, (GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackVertexAttrib4dvARB(attr, (GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case GL_BYTE:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLbyte *bPtr = (GLbyte*) p;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync if (array->a[attr].normalized)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 1:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib1fARB(attr, CRP_B2F_NORM(bPtr[0]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib2fARB(attr, CRP_B2F_NORM(bPtr[0]), CRP_B2F_NORM(bPtr[1]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib3fARB(attr, CRP_B2F_NORM(bPtr[0]), CRP_B2F_NORM(bPtr[1]), CRP_B2F_NORM(bPtr[2]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4NbvARB(attr, bPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync else
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLbyte bv[4];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4bvARB(attr, bPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3: bv[2] = bPtr[2];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2: bv[1] = bPtr[1];
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 1:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync bv[0] = bPtr[0];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4bvARB(attr, bv);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case GL_UNSIGNED_BYTE:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLubyte *ubPtr = (GLubyte*) p;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync if (array->a[attr].normalized)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 1:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib1fARB(attr, CRP_UB2F_NORM(ubPtr[0]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib2fARB(attr, CRP_UB2F_NORM(ubPtr[0]), CRP_UB2F_NORM(ubPtr[1]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib3fARB(attr, CRP_UB2F_NORM(ubPtr[0]), CRP_UB2F_NORM(ubPtr[1]), CRP_UB2F_NORM(ubPtr[2]));
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4NubvARB(attr, ubPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync else
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync GLubyte ubv[4];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync switch (array->a[attr].size)
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync {
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 4:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4ubvARB(attr, ubPtr);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 3: ubv[2] = ubPtr[2];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync case 2: ubv[1] = ubPtr[1];
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync case 1:
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync ubv[0] = ubPtr[0];
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync crPackVertexAttrib4ubvARB(attr, ubv);
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync break;
fc46b5c3d89b3be1b5da0fda86c9ee094dd02b89vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync default:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crWarning("Bad datatype for vertex attribute [%d] array: 0x%x\n",
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync attr, array->a[attr].type);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync}
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync/*
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync * Expand glArrayElement into crPackVertex/Color/Normal/etc.
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync */
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncvoid
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsynccrPackExpandArrayElement(GLint index, CRClientState *c)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync{
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync unsigned char *p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync unsigned int unit, attr;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync const CRVertexArrays *array = &(c->array);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync const GLboolean vpEnabled = crStateGetCurrent()->program.vpEnabled;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
e44afe4f6981a920db4f9371e7199cae6a0f6e64vboxsync /*crDebug("crPackExpandArrayElement(%i)", index);*/
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->n.enabled && !(vpEnabled && array->a[VERT_ATTRIB_NORMAL].enabled))
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = array->n.p + index * array->n.stride;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->n.buffer && array->n.buffer->data)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->n.buffer->data) + (unsigned long)p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->n.type)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_BYTE: crPackNormal3bv((GLbyte *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_SHORT: crPackNormal3sv((GLshort *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_INT: crPackNormal3iv((GLint *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_FLOAT: crPackNormal3fv((GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_DOUBLE: crPackNormal3dv((GLdouble *)p); break;
977a7ff905883c1b7d4650a211a089684db421f6vboxsync default:
977a7ff905883c1b7d4650a211a089684db421f6vboxsync crWarning("Unhandled: crPackExpandArrayElement, array->n.type 0x%x", array->n.type);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->c.enabled && !(vpEnabled && array->a[VERT_ATTRIB_COLOR0].enabled))
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = array->c.p + index * array->c.stride;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->c.buffer && array->c.buffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->c.buffer->data) + (unsigned long)p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->c.type)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_BYTE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.c.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 3: crPackColor3bv((GLbyte *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 4: crPackColor4bv((GLbyte *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_BYTE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.c.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 3: crPackColor3ubv((GLubyte *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 4: crPackColor4ubv((GLubyte *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_SHORT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.c.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 3: crPackColor3sv((GLshort *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 4: crPackColor4sv((GLshort *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_SHORT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.c.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 3: crPackColor3usv((GLushort *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 4: crPackColor4usv((GLushort *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_INT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.c.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 3: crPackColor3iv((GLint *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 4: crPackColor4iv((GLint *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_INT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.c.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 3: crPackColor3uiv((GLuint *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 4: crPackColor4uiv((GLuint *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_FLOAT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.c.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 3: crPackColor3fv((GLfloat *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 4: crPackColor4fv((GLfloat *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_DOUBLE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.c.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 3: crPackColor3dv((GLdouble *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case 4: crPackColor4dv((GLdouble *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync default:
977a7ff905883c1b7d4650a211a089684db421f6vboxsync crWarning("Unhandled: crPackExpandArrayElement, array->c.type 0x%x", array->c.type);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_EXT_secondary_color
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->s.enabled && !(vpEnabled && array->a[VERT_ATTRIB_COLOR1].enabled))
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = array->s.p + index * array->s.stride;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->s.buffer && array->s.buffer->data)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->s.buffer->data) + (unsigned long)p;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->s.type)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_BYTE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackSecondaryColor3bvEXT((GLbyte *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_BYTE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackSecondaryColor3ubvEXT((GLubyte *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_SHORT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackSecondaryColor3svEXT((GLshort *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_SHORT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackSecondaryColor3usvEXT((GLushort *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_INT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackSecondaryColor3ivEXT((GLint *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_INT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackSecondaryColor3uivEXT((GLuint *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_FLOAT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackSecondaryColor3fvEXT((GLfloat *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_DOUBLE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackSecondaryColor3dvEXT((GLdouble *)p); break;
977a7ff905883c1b7d4650a211a089684db421f6vboxsync default:
977a7ff905883c1b7d4650a211a089684db421f6vboxsync crWarning("Unhandled: crPackExpandArrayElement, array->s.type 0x%x", array->s.type);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif // CR_EXT_secondary_color
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_EXT_fog_coord
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->f.enabled && !(vpEnabled && array->a[VERT_ATTRIB_FOG].enabled))
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = array->f.p + index * array->f.stride;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->f.buffer && array->f.buffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->f.buffer->data) + (unsigned long)p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackFogCoordfEXT( *((GLfloat *) p) );
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif // CR_EXT_fog_coord
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync for (unit = 0 ; unit < CR_MAX_TEXTURE_UNITS ; unit++)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->t[unit].enabled && !(vpEnabled && array->a[VERT_ATTRIB_TEX0+unit].enabled))
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = array->t[unit].p + index * array->t[unit].stride;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->t[unit].buffer && array->t[unit].buffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->t[unit].buffer->data) + (unsigned long)p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->t[unit].type)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_SHORT:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->t[unit].size)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 1: crPackMultiTexCoord1svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackMultiTexCoord2svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackMultiTexCoord3svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackMultiTexCoord4svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_INT:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->t[unit].size)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 1: crPackMultiTexCoord1ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackMultiTexCoord2ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackMultiTexCoord3ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackMultiTexCoord4ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_FLOAT:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->t[unit].size)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 1: crPackMultiTexCoord1fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackMultiTexCoord2fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackMultiTexCoord3fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackMultiTexCoord4fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_DOUBLE:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->t[unit].size)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 1: crPackMultiTexCoord1dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackMultiTexCoord2dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackMultiTexCoord3dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackMultiTexCoord4dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
977a7ff905883c1b7d4650a211a089684db421f6vboxsync default:
977a7ff905883c1b7d4650a211a089684db421f6vboxsync crWarning("Unhandled: crPackExpandArrayElement, array->t[%i].type 0x%x", unit, array->t[unit].type);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->i.enabled)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = array->i.p + index * array->i.stride;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->i.buffer && array->i.buffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->i.buffer->data) + (unsigned long)p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->i.type)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_SHORT: crPackIndexsv((GLshort *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_INT: crPackIndexiv((GLint *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_FLOAT: crPackIndexfv((GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_DOUBLE: crPackIndexdv((GLdouble *)p); break;
977a7ff905883c1b7d4650a211a089684db421f6vboxsync default:
977a7ff905883c1b7d4650a211a089684db421f6vboxsync crWarning("Unhandled: crPackExpandArrayElement, array->i.type 0x%x", array->i.type);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->e.enabled)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = array->e.p + index * array->e.stride;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->e.buffer && array->e.buffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->e.buffer->data) + (unsigned long)p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackEdgeFlagv(p);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync for (attr = 1; attr < VERT_ATTRIB_MAX; attr++)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->a[attr].enabled)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib(array, attr, index);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->a[VERT_ATTRIB_POS].enabled)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackVertexAttrib(array, 0, index);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync else if (array->v.enabled)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = array->v.p + index * array->v.stride;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (array->v.buffer && array->v.buffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(array->v.buffer->data) + (unsigned long)p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (array->v.type)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_SHORT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.v.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackVertex2sv((GLshort *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackVertex3sv((GLshort *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackVertex4sv((GLshort *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_INT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.v.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackVertex2iv((GLint *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackVertex3iv((GLint *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackVertex4iv((GLint *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_FLOAT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.v.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackVertex2fv((GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackVertex3fv((GLfloat *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackVertex4fv((GLfloat *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_DOUBLE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (c->array.v.size)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 2: crPackVertex2dv((GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 3: crPackVertex3dv((GLdouble *)p); break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case 4: crPackVertex4dv((GLdouble *)p); break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
977a7ff905883c1b7d4650a211a089684db421f6vboxsync default:
977a7ff905883c1b7d4650a211a089684db421f6vboxsync crWarning("Unhandled: crPackExpandArrayElement, array->v.type 0x%x", array->v.type);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackExpandDrawArrays(GLenum mode, GLint first, GLsizei count, CRClientState *c)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync int i;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync if (count < 0)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync __PackError(__LINE__, __FILE__, GL_INVALID_VALUE, "crPackDrawArrays(negative count)");
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync return;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync if (mode > GL_POLYGON)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, "crPackDrawArrays(bad mode)");
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync return;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackBegin(mode);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync for (i=0; i<count; i++)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackExpandArrayElement(first + i, c);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackEnd();
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncstatic GLsizei crPackElementsIndexSize(GLenum type)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync{
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (type)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_UNSIGNED_BYTE:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync return sizeof(GLubyte);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_UNSIGNED_SHORT:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync return sizeof(GLushort);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_UNSIGNED_INT:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync return sizeof(GLuint);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync default:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crError("Unknown type 0x%x in crPackElementsIndexSize", type);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync return 0;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid PACK_APIENTRY
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync unsigned char *data_ptr, *start_ptr;
4aef33e90cfa798b2e6db5b45f02c2a6c8bbc4aevboxsync int packet_length = sizeof(int) + sizeof(mode) + sizeof(count) + sizeof(type) + sizeof(GLuint);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync GLsizei indexsize;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
521a799e2d6b107f295561fbb2d4c8852717dbf1vboxsync packet_length += sizeof(GLint);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (elementsBuffer && elementsBuffer->name)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync /*@todo not sure it's possible, and not sure what to do*/
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (!elementsBuffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crWarning("crPackDrawElements: trying to use bound but empty elements buffer, ignoring.");
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync return;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync indexsize = 0;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync else
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync indexsize = crPackElementsIndexSize(type);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync packet_length += count * indexsize;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLenum, CR_DRAWELEMENTS_EXTEND_OPCODE );
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLenum, mode );
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLsizei, count);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLenum, type);
df504dfa2b5b186f4cac7f7859eabd09b30eebf0vboxsync WRITE_DATA_AI(GLuint, (GLuint) ((uintptr_t) indices) );
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
521a799e2d6b107f295561fbb2d4c8852717dbf1vboxsync WRITE_DATA_AI(GLint, (GLint)(indexsize>0));
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (indexsize>0)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crMemcpy(data_ptr, indices, count * indexsize);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crHugePacket(CR_EXTEND_OPCODE, start_ptr);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackFree(start_ptr);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync}
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsyncvoid PACK_APIENTRY
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsynccrPackDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync GLenum type, const GLvoid *indices)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync{
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync unsigned char *data_ptr, *start_ptr;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync int packet_length = sizeof(int) + sizeof(mode) + sizeof(start)
4aef33e90cfa798b2e6db5b45f02c2a6c8bbc4aevboxsync + sizeof(end) + sizeof(count) + sizeof(type) + sizeof(GLuint);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync GLsizei indexsize;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
521a799e2d6b107f295561fbb2d4c8852717dbf1vboxsync packet_length += sizeof(GLint);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (elementsBuffer && elementsBuffer->name)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync /*@todo not sure it's possible, and not sure what to do*/
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (!elementsBuffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crWarning("crPackDrawElements: trying to use bound but empty elements buffer, ignoring.");
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync return;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync indexsize = 0;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync else
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync indexsize = crPackElementsIndexSize(type);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync packet_length += count * indexsize;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLenum, CR_DRAWRANGEELEMENTS_EXTEND_OPCODE);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLenum, mode);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLuint, start);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLuint, end);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLsizei, count);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync WRITE_DATA_AI(GLenum, type);
df504dfa2b5b186f4cac7f7859eabd09b30eebf0vboxsync WRITE_DATA_AI(GLuint, (GLuint) ((uintptr_t) indices));
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
521a799e2d6b107f295561fbb2d4c8852717dbf1vboxsync WRITE_DATA_AI(GLint, (GLint) (indexsize>0));
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (indexsize>0)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crMemcpy(data_ptr, indices, count * indexsize);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crHugePacket(CR_EXTEND_OPCODE, start_ptr);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackFree(start_ptr);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/**
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Expand glDrawElements into crPackBegin/Vertex/End, etc commands.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Note: if mode==999, don't call glBegin/glEnd.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackExpandDrawElements(GLenum mode, GLsizei count, GLenum type,
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync const GLvoid *indices, CRClientState *c)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync int i;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync GLubyte *p = (GLubyte *)indices;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync if (count < 0)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync __PackError(__LINE__, __FILE__, GL_INVALID_VALUE,
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync "crPackDrawElements(negative count)");
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync return;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync if (mode > GL_POLYGON && mode != 999)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync __PackError(__LINE__, __FILE__, GL_INVALID_ENUM,
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync "crPackDrawElements(bad mode)");
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync return;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync if (type != GL_UNSIGNED_BYTE &&
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync type != GL_UNSIGNED_SHORT &&
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync type != GL_UNSIGNED_INT)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync __PackError(__LINE__, __FILE__, GL_INVALID_ENUM,
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync "crPackDrawElements(bad type)");
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync return;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#ifdef CR_ARB_vertex_buffer_object
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (elementsBuffer && elementsBuffer->data)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p = (unsigned char *)(elementsBuffer->data) + (unsigned long)p;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync#endif
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync if (mode != 999)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackBegin(mode);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync //crDebug("crPackExpandDrawElements mode:0x%x, count:%d, type:0x%x", mode, count, type);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync switch (type)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_UNSIGNED_BYTE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync for (i=0; i<count; i++)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackExpandArrayElement((GLint) *p++, c);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_UNSIGNED_SHORT:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync for (i=0; i<count; i++)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackExpandArrayElement((GLint) * (GLushort *) p, c);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p+=sizeof (GLushort);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync case GL_UNSIGNED_INT:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync for (i=0; i<count; i++)
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackExpandArrayElement((GLint) * (GLuint *) p, c);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync p+=sizeof (GLuint);
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync }
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync default:
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crError( "this can't happen: array_spu.self.DrawElements" );
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync if (mode != 999)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackEnd();
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/**
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Convert a glDrawElements command into a sequence of ArrayElement() calls.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * NOTE: Caller must issue the glBegin/glEnd.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackUnrollDrawElements(GLsizei count, GLenum type,
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync const GLvoid *indices)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync int i;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync switch (type) {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_BYTE:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync const GLubyte *p = (const GLubyte *) indices;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync for (i = 0; i < count; i++)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackArrayElement(p[i]);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_SHORT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync const GLushort *p = (const GLushort *) indices;
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync for (i = 0; i < count; i++)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackArrayElement(p[i]);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync case GL_UNSIGNED_INT:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync const GLuint *p = (const GLuint *) indices;
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync for (i = 0; i < count; i++)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync crPackArrayElement(p[i]);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync break;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync default:
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync __PackError(__LINE__, __FILE__, GL_INVALID_ENUM,
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync "crPackUnrollDrawElements(bad type)");
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/*
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * glDrawRangeElements, expanded into crPackBegin/Vertex/End/etc.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackExpandDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c)
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync if (start>end)
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync {
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crWarning("crPackExpandDrawRangeElements start>end (%d>%d)", start, end);
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync return;
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync }
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync
236b6e0fdf652661ff4c655314fe488998c5c17dvboxsync crPackExpandDrawElements(mode, count, type, indices, c);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#ifdef CR_EXT_multi_draw_arrays
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/*
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Pack real DrawArrays commands.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid PACK_APIENTRY
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count,
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync GLsizei primcount )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync GLint i;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync for (i = 0; i < primcount; i++) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (count[i] > 0) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crPackDrawArrays(mode, first[i], count[i]);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/*
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Pack with crPackBegin/Vertex/End/etc.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackExpandMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count,
54cdd2a4e7676bc8694fa8db62ece5a1447b3597vboxsync GLsizei primcount, CRClientState *c )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync GLint i;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync for (i = 0; i < primcount; i++) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (count[i] > 0) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crPackExpandDrawArrays(mode, first[i], count[i], c);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/*
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Pack real DrawElements commands.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid PACK_APIENTRY
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackMultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync const GLvoid **indices, GLsizei primcount )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync GLint i;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync for (i = 0; i < primcount; i++) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (count[i] > 0) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crPackDrawElements(mode, count[i], type, indices[i]);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync/*
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync * Pack with crPackBegin/Vertex/End/etc.
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync */
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsyncvoid
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsynccrPackExpandMultiDrawElementsEXT( GLenum mode, const GLsizei *count,
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync GLenum type, const GLvoid **indices,
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync GLsizei primcount, CRClientState *c )
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync{
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync GLint i;
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync for (i = 0; i < primcount; i++) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync if (count[i] > 0) {
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync crPackExpandDrawElements(mode, count[i], type, indices[i], c);
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync }
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync}
e0e0c19eefceaf5d4ec40f9466b58a771f50e799vboxsync#endif /* CR_EXT_multi_draw_arrays */
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsyncstatic int crPack_GetNumEnabledArrays(CRClientState *c, int *size)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync{
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync int i, count=0;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size = 0;
145ea91d89919d9fd788de37de35ca0907629cc2vboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.v.enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.v.bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.c.enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.c.bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.f.enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.f.bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.s.enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.s.bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.e.enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.e.bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.i.enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.i.bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.n.enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.n.bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.t[i].enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.t[i].bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (c->array.a[i].enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync count++;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *size += c->array.a[i].bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync return count;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync}
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsyncstatic void crPackLockClientPointer(GLint first, GLint count, unsigned char **ppData, int index, CRClientState *c)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync{
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync CRClientPointer *cp;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync unsigned char *data_ptr = *ppData, *cptr;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync GLint i;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync cp = crStateGetClientPointerByIndex(index, &c->array);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (cp->enabled)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (cp->buffer && cp->buffer->name)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync crWarning("crPackLockClientPointer called when there's VBO enabled!");
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync WRITE_DATA_AI(int, index);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync cptr = cp->p + first*cp->bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync if (cp->bytesPerIndex==cp->stride)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync crMemcpy(data_ptr, cptr, count*cp->bytesPerIndex);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync data_ptr += count*cp->bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync else
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync for (i=0; i<count; ++i)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync crMemcpy(data_ptr, cptr, cp->bytesPerIndex);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync data_ptr += cp->bytesPerIndex;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync cptr += cp->stride;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync *ppData = data_ptr;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync}
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsyncvoid PACK_APIENTRY crPackLockArraysEXT(GLint first, GLint count)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync{
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync CRContext *g = crStateGetCurrent();
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync CRClientState *c = &g->client;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync unsigned char *data_ptr, *start_ptr;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync int packet_length = sizeof(int); /*extopcode*/
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync int vertex_size, i, numenabled;
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync packet_length += sizeof(first) + sizeof(count); /*params*/
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync numenabled = crPack_GetNumEnabledArrays(c, &vertex_size);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync packet_length += sizeof(int) + numenabled*sizeof(int); /*numenabled + indices*/
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync packet_length += vertex_size * count; /*vertices data*/
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync WRITE_DATA_AI(GLenum, CR_LOCKARRAYSEXT_EXTEND_OPCODE );
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync WRITE_DATA_AI(GLint, first);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync WRITE_DATA_AI(GLint, count);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync WRITE_DATA_AI(int, numenabled);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync {
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync crPackLockClientPointer(first, count, &data_ptr, i, c);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync }
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync crHugePacket(CR_EXTEND_OPCODE, start_ptr);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync crPackFree(start_ptr);
10183353efa12aa94e0f3dc78e0f1c47f7928e8dvboxsync}