Acme-MITHALDU-BleedingOpenGL
view release on metacpan or search on metacpan
case GL_PIXEL_MAP_B_TO_B:
glGetIntegerv(GL_PIXEL_MAP_B_TO_B_SIZE, &s);
return s;
case GL_PIXEL_MAP_A_TO_A:
glGetIntegerv(GL_PIXEL_MAP_A_TO_A_SIZE, &s);
return s;
default:
croak("unknown pixelmap");
}
return 0; // Just to make the compiler happy
}
int gl_state_count(GLenum state) {
switch (state) {
case GL_CURRENT_COLOR: return 4;
case GL_CURRENT_INDEX: return 1;
}
return 0;
}
unsigned long gl_pixelbuffer_size(
GLenum format,
GLsizei width,
GLsizei height,
GLenum type,
int mode);
GLvoid * EL(SV * sv, int needlen)
{
STRLEN skip = 0;
SV * svref;
if (SvREADONLY(sv))
croak("Readonly value for buffer");
if(SvROK(sv)) {
svref = SvRV(sv);
sv = svref;
}
else
{
#ifdef USE_STRICT_UNGLOB
if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV)
sv_unglob(sv);
#endif
SvUPGRADE(sv, SVt_PV);
SvGROW(sv, (unsigned int)(needlen + 1));
SvPOK_on(sv);
SvCUR_set(sv, needlen);
*SvEND(sv) = '\0'; /* Why is this here? -chm */
}
return SvPV_force(sv, skip);
}
GLvoid * ELI(SV * sv, GLsizei width, GLsizei height,
GLenum format, GLenum type, int mode)
{
int needlen = 0;
if (!SvROK(sv)) /* don't calc length if arg is a perl ref */
needlen = gl_pixelbuffer_size(format, width, height, type, mode);
return EL(sv, needlen);
}
int gl_type_size(GLenum type)
{
switch (type) {
#ifdef GL_VERSION_1_2
case GL_UNSIGNED_BYTE_3_3_2:
case GL_UNSIGNED_BYTE_2_3_3_REV:
return sizeof(GLubyte);
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_5_6_5_REV:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL_UNSIGNED_SHORT_5_5_5_1:
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
return sizeof(GLushort);
case GL_UNSIGNED_INT_8_8_8_8:
case GL_UNSIGNED_INT_8_8_8_8_REV:
case GL_UNSIGNED_INT_10_10_10_2:
case GL_UNSIGNED_INT_2_10_10_10_REV:
return sizeof(GLuint);
#endif
case GL_UNSIGNED_BYTE: return sizeof(GLubyte); break;
case GL_BITMAP: return sizeof(GLubyte); break;
case GL_BYTE: return sizeof(GLbyte); break;
case GL_UNSIGNED_SHORT: return sizeof(GLushort); break;
case GL_SHORT: return sizeof(GLshort); break;
case GL_UNSIGNED_INT: return sizeof(GLuint); break;
case GL_INT: return sizeof(GLint); break;
case GL_FLOAT: return sizeof(GLfloat); break;
case GL_DOUBLE: return sizeof(GLdouble); break;
case GL_2_BYTES: return 2;
case GL_3_BYTES: return 3;
case GL_4_BYTES: return 4;
default:
croak("unknown type");
}
return 0; // Just to make the compiler happy
}
int gl_component_count(GLenum format, GLenum type)
{
int n;
switch (format) {
#ifdef GL_VERSION_1_2
case GL_BGR:
n = 3; break;
case GL_BGRA:
n = 4; break;
#endif
/* 18 */
#ifdef GL_EXT_cmyka
case GL_CMYK:
#ifdef GL_EXT_agbr
case GL_AGBR:
n = 4; break;
#endif
case GL_COLOR_INDEX:
case GL_STENCIL_INDEX:
case GL_DEPTH_COMPONENT:
case GL_RED:
case GL_GREEN:
case GL_BLUE:
case GL_ALPHA:
case GL_LUMINANCE:
n = 1; break;
case GL_LUMINANCE_ALPHA:
n = 2; break;
case GL_RGB:
n = 3; break;
case GL_RGBA:
n = 4; break;
default:
croak("unknown format");
}
#ifdef GL_VERSION_1_2
switch (type) {
case GL_UNSIGNED_BYTE_3_3_2:
case GL_UNSIGNED_BYTE_2_3_3_REV:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_5_6_5_REV:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL_UNSIGNED_SHORT_5_5_5_1:
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
case GL_UNSIGNED_INT_8_8_8_8:
case GL_UNSIGNED_INT_8_8_8_8_REV:
case GL_UNSIGNED_INT_10_10_10_2:
case GL_UNSIGNED_INT_2_10_10_10_REV:
n = 1;
}
#endif
return n;
}
/* From Mesa */
/* Compute ceiling of integer quotient of A divided by B: */
#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
unsigned long gl_pixelbuffer_size(
GLenum format,
GLsizei width,
GLsizei height,
GLenum type,
int mode)
{
GLint n; /* elements in a group */
GLint l; /* number of groups in a row */
GLint r; /* pack/unpack row length (overrides l if nonzero) */
GLint s; /* size (in bytes) of an element */
GLint a; /* alignment */
unsigned long k; /* size in bytes of row */
r = 0;
a = 4;
if (mode == gl_pixelbuffer_pack) {
glGetIntegerv(GL_PACK_ROW_LENGTH, &r);
glGetIntegerv(GL_PACK_ALIGNMENT, &a);
} else if (mode == gl_pixelbuffer_unpack) {
glGetIntegerv(GL_UNPACK_ROW_LENGTH, &r);
glGetIntegerv(GL_UNPACK_ALIGNMENT, &a);
}
l = r > 0 ? r : width;
s = gl_type_size(type);
n = gl_component_count(format, type);
/* From Mesa, more or less */
if (type == GL_BITMAP) {
k = a * CEILING( n * l, 8 * a);
} else {
k = l * s * n;
if ( s < a ) {
k = (a / s * CEILING(k, a)) * s;
}
}
return k * height;
}
/* Compute ceiling of integer quotient of A divided by B: */
#define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
void gl_pixelbuffer_size2(
GLsizei width,
GLsizei height,
GLsizei depth,
GLenum format,
GLenum type,
int mode,
GLsizei * length,
GLsizei * items)
{
GLint n; /* elements in a group */
GLint l; /* number of groups in a row */
GLint s; /* size (in bytes) of an element */
GLint a; /* alignment */
unsigned long k; /* size in bytes of row */
a = 4;
l = width;
if (mode == gl_pixelbuffer_pack) {
glGetIntegerv(GL_PACK_ROW_LENGTH, &l);
glGetIntegerv(GL_PACK_ALIGNMENT, &a);
} else if (mode == gl_pixelbuffer_unpack) {
glGetIntegerv(GL_UNPACK_ROW_LENGTH, &l);
glGetIntegerv(GL_UNPACK_ALIGNMENT, &a);
}
s = gl_type_size(type);
n = gl_component_count(format, type);
/* From Mesa, more or less */
if (type == GL_BITMAP) {
k = a * CEILING( n * l, 8 * a);
} else {
k = l * s * n;
if ( s < a ) {
k = (a / s * CEILING(k, a)) * s;
}
}
*items = l * n * height * depth;
*length = (k * height * depth);
}
void pgl_set_type(SV * sv, GLenum type, void ** ptr)
{
#define RIV(t) \
(*(t*)*ptr) = (t)SvIV(sv); \
*(unsigned char**)ptr += sizeof(t);\
break;
#define RNV(t) \
(*(t*)*ptr) = (t)SvNV(sv); \
*(unsigned char**)ptr += sizeof(t);\
break;
switch (type) {
#ifdef GL_VERSION_1_2
case GL_UNSIGNED_BYTE_3_3_2:
case GL_UNSIGNED_BYTE_2_3_3_REV:
RIV(GLubyte)
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_5_6_5_REV:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL_UNSIGNED_SHORT_5_5_5_1:
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
RIV(GLushort)
case GL_UNSIGNED_INT_8_8_8_8:
case GL_UNSIGNED_INT_8_8_8_8_REV:
case GL_UNSIGNED_INT_10_10_10_2:
case GL_UNSIGNED_INT_2_10_10_10_REV:
RIV(GLuint)
#endif
case GL_UNSIGNED_BYTE:
case GL_BITMAP:
case GL_BYTE:
RIV(GLubyte)
case GL_UNSIGNED_SHORT:
case GL_SHORT:
RIV(GLushort)
case GL_UNSIGNED_INT:
case GL_INT:
RIV(GLuint)
case GL_FLOAT:
RNV(GLfloat)
case GL_DOUBLE:
RNV(GLdouble)
case GL_2_BYTES:
{
unsigned long v = SvIV(sv);
(*(GLubyte*)*ptr) = (GLubyte)(v >> 8);
(*(unsigned char**)ptr)++;
(*(GLubyte*)*ptr) = (GLubyte)(v & 0xff);
(*(unsigned char**)ptr)++;
break;
}
case GL_3_BYTES:
{
unsigned long v = SvIV(sv);
(*(GLubyte*)*ptr) = (GLubyte)((v >> 16) & 0xff);
(*(unsigned char**)ptr)++;
(*(GLubyte*)*ptr) = (GLubyte)((v >> 8) & 0xff);
( run in 1.389 second using v1.01-cache-2.11-cpan-5837b0d9d2c )