diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 03:01:46 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 03:01:46 +0000 |
commit | f8fe689a81f906d1b91bb3220acde2a4ecb14c5b (patch) | |
tree | 26484e9d7e2c67806c2d1760196ff01aaa858e8c /src/VBox/GuestHost/OpenGL/packer | |
parent | Initial commit. (diff) | |
download | virtualbox-f8fe689a81f906d1b91bb3220acde2a4ecb14c5b.tar.xz virtualbox-f8fe689a81f906d1b91bb3220acde2a4ecb14c5b.zip |
Adding upstream version 6.0.4-dfsg.upstream/6.0.4-dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/GuestHost/OpenGL/packer')
49 files changed, 10530 insertions, 0 deletions
diff --git a/src/VBox/GuestHost/OpenGL/packer/Makefile.kup b/src/VBox/GuestHost/OpenGL/packer/Makefile.kup new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/Makefile.kup diff --git a/src/VBox/GuestHost/OpenGL/packer/opcodes.py b/src/VBox/GuestHost/OpenGL/packer/opcodes.py new file mode 100755 index 00000000..798ca677 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/opcodes.py @@ -0,0 +1,106 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +# This script generates include/cr_opcodes.h from the gl_header.parsed file. + +from __future__ import print_function +import sys; +import string; +import re; + +import apiutil + +apiutil.CopyrightC() + +print("") +print("/* DO NOT EDIT - THIS FILE GENERATED BY THE opcodes.py SCRIPT */") +print("") +print("#ifndef CR_OPCODES_H") +print("#define CR_OPCODES_H") +print("") + +keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") +assert len(keys) > 0 + +print("/* Functions with no return value and input-only parameters */") +print("typedef enum {") + +enum_index = 0 +for func in keys: + if "pack" in apiutil.ChromiumProps(func): + print("\t%s = %d," % ( apiutil.OpcodeName(func), enum_index )) + enum_index = enum_index + 1 + +print("\tCR_EXTEND_OPCODE=%d," % enum_index) +enum_index = enum_index + 1 +print("\tCR_CMDBLOCKBEGIN_OPCODE=%d," % enum_index) +enum_index = enum_index + 1 +print("\tCR_CMDBLOCKEND_OPCODE=%d," % enum_index) +enum_index = enum_index + 1 +print("\tCR_CMDBLOCKFLUSH_OPCODE=%d," % enum_index) +print("\tCR_NOP_OPCODE=255") +if enum_index > 254: + # This would have saved Mike some grief if it had been here earlier. + print >> sys.stderr, "You have more than 255 opcodes! You've been adding functions to" + print >> sys.stderr, "glapi_parser/APIspec! Each new function you add" + print >> sys.stderr, "gets an opcode assigned to it. Fortunately for you, we have" + print >> sys.stderr, "an ``extend'' opcode. Please mark the function as" + print >> sys.stderr, "'extpack' in APIspec so as to keep the main opcode pool" + print >> sys.stderr, "less than 255! THIS IS A CATASTROPHIC FAILURE, and I WILL NOT CONTINUE!" + print >> sys.stderr, "I'm putting an error in the generated header file so you won't miss" + print >> sys.stderr, "this even if you're doing a 'make -k.'" + print("#error -- more than 255 opcodes!") + sys.exit(-1) +print("} CROpcode;\n") + +# count up number of extended opcode commands +num_extends = 0 +num_auto_codes = 0 +for func in keys: + if "extpack" in apiutil.ChromiumProps(func): + num_extends += 1 + if apiutil.ChromiumRelOpCode(func) < 0: + num_auto_codes += 1 + +# sanity check for compatibility breakage +# we currently have 304 +if num_auto_codes != 304: + print >> sys.stderr, "number of auto-generated op-codes should be 304, but is " + str(num_auto_codes) + print >> sys.stderr, "which breaks backwards compatibility" + print >> sys.stderr, "if this is really what you want to do, please adjust this script" + print >> sys.stderr, "to handle a new auto-generated opcodes count" + print("#error -- num_auto_codes should be 304, but is " + str(num_auto_codes)) + sys.exit(-1) + +print("/* Functions with a return value or output parameters */") +print("typedef enum {") + +opcode_index = 0 +enum_index = 0 +chrelopcodes = {} +for func in keys: + if "extpack" in apiutil.ChromiumProps(func): + opcodeName = apiutil.ExtendedOpcodeName(func) + chrelopcode = apiutil.ChromiumRelOpCode(func) + opcode = -1 + if chrelopcode >= 0: + if not chrelopcode in chrelopcodes: + chrelopcodes[chrelopcode] = chrelopcode + else: + print >> sys.stderr, "non-unique chrelopcode: " + str(chrelopcode) + print("#error -- non-unique chrelopcode: " + str(num_auto_codes)) + sys.exit(-1) + opcode = num_auto_codes + chrelopcode + else: + opcode = opcode_index + opcode_index = opcode_index + 1 + + if enum_index != num_extends-1: + print("\t%s = %d," % (opcodeName, opcode )) + else: + print("\t%s = %d" % (opcodeName, opcode )) + enum_index = enum_index + 1 +print("} CRExtendOpcode;\n") +print("#endif /* CR_OPCODES_H */") diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_arrays.c b/src/VBox/GuestHost/OpenGL/packer/pack_arrays.c new file mode 100644 index 00000000..540865c6 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_arrays.c @@ -0,0 +1,209 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_error.h" +#include "iprt/types.h" + +#define UNUSED(x) ((void)(x)) +/** + * \mainpage Packer + * + * \section PackerIntroduction Introduction + * + * Chromium consists of all the top-level files in the cr + * directory. The packer module basically takes care of API dispatch, + * and OpenGL state management. + * + */ + +void PACK_APIENTRY crPackVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) +{ + /* Packing this command is only useful if we have server-side vertex + * arrays - GL_ARB_vertex_buffer_object. Note that pointer will really + * be an offset into a server-side buffer. + * @todo Because of that we'd only transfer lowest 32bit as there're no 4gb+VBOs (yet?). + * Look at glgets regarding max vertices in arrays. + */ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 24; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_VERTEXPOINTER_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, size ); + WRITE_DATA( 12, GLenum, type ); + WRITE_DATA( 16, GLsizei, stride ); + WRITE_DATA( 20, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 24; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_COLORPOINTER_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, size ); + WRITE_DATA( 12, GLenum, type ); + WRITE_DATA( 16, GLsizei, stride ); + WRITE_DATA( 20, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 20; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_NORMALPOINTER_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, type ); + WRITE_DATA( 12, GLsizei, stride ); + WRITE_DATA( 16, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 24; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_TEXCOORDPOINTER_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, size ); + WRITE_DATA( 12, GLenum, type ); + WRITE_DATA( 16, GLsizei, stride ); + WRITE_DATA( 20, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackEdgeFlagPointer( GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_EDGEFLAGPOINTER_EXTEND_OPCODE ); + WRITE_DATA( 8, GLsizei, stride ); + WRITE_DATA( 12, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackIndexPointer( GLenum type, GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 20; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_INDEXPOINTER_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, type ); + WRITE_DATA( 12, GLsizei, stride ); + WRITE_DATA( 16, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackSecondaryColorPointerEXT( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 24; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_SECONDARYCOLORPOINTEREXT_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, size ); + WRITE_DATA( 12, GLenum, type ); + WRITE_DATA( 16, GLsizei, stride ); + WRITE_DATA( 20, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackFogCoordPointerEXT( GLenum type, GLsizei stride, const GLvoid * pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 20; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_FOGCOORDPOINTEREXT_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, type ); + WRITE_DATA( 12, GLsizei, stride ); + WRITE_DATA( 16, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttribPointerARB( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 32; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_VERTEXATTRIBPOINTERARB_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, index ); + WRITE_DATA( 12, GLint, size ); + WRITE_DATA( 16, GLenum, type ); + WRITE_DATA( 20, GLboolean, normalized ); + WRITE_DATA( 24, GLsizei, stride ); + WRITE_DATA( 28, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttribPointerNV( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 28; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_VERTEXATTRIBPOINTERNV_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, index ); + WRITE_DATA( 12, GLint, size ); + WRITE_DATA( 16, GLenum, type ); + WRITE_DATA( 20, GLsizei, stride ); + WRITE_DATA( 24, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackInterleavedArrays( GLenum format, GLsizei stride, const GLvoid *pointer ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 20; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_INTERLEAVEDARRAYS_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, format ); + WRITE_DATA( 12, GLsizei, stride ); + WRITE_DATA( 16, GLuint, (GLuint) ((uintptr_t) pointer) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void PACK_APIENTRY crPackVertexArrayRangeNV( GLsizei length, const GLvoid *pointer ) +{ + UNUSED( length ); + UNUSED( pointer ); + crWarning( "Unimplemented crPackVertexArrayRangeNV" ); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_bbox.h b/src/VBox/GuestHost/OpenGL/packer/pack_bbox.h new file mode 100644 index 00000000..8602f664 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_bbox.h @@ -0,0 +1,183 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved. + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#ifndef CR_PACK_BBOX_H +#define CR_PACK_BBOX_H + +#include "cr_pack.h" + +#define UPDATE_1D_BBOX() \ +if (pc->bounds_min.x > fx) pc->bounds_min.x = fx;\ +if (pc->bounds_min.y > 0.0f) pc->bounds_min.y = 0.0f;\ +if (pc->bounds_min.z > 0.0f) pc->bounds_min.z = 0.0f;\ +if (pc->bounds_max.x < fx) pc->bounds_max.x = fx;\ +if (pc->bounds_max.y < 0.0f) pc->bounds_max.y = 0.0f;\ +if (pc->bounds_max.z < 0.0f) pc->bounds_max.z = 0.0f + +#define UPDATE_2D_BBOX() \ +if (pc->bounds_min.x > fx) pc->bounds_min.x = fx;\ +if (pc->bounds_min.y > fy) pc->bounds_min.y = fy;\ +if (pc->bounds_min.z > 0.0f) pc->bounds_min.z = 0.0f;\ +if (pc->bounds_max.x < fx) pc->bounds_max.x = fx;\ +if (pc->bounds_max.y < fy) pc->bounds_max.y = fy;\ +if (pc->bounds_max.z < 0.0f) pc->bounds_max.z = 0.0f + +#define UPDATE_3D_BBOX() \ +if (pc->bounds_min.x > fx) pc->bounds_min.x = fx; \ +if (pc->bounds_min.y > fy) pc->bounds_min.y = fy; \ +if (pc->bounds_min.z > fz) pc->bounds_min.z = fz; \ +if (pc->bounds_max.x < fx) pc->bounds_max.x = fx; \ +if (pc->bounds_max.y < fy) pc->bounds_max.y = fy; \ +if (pc->bounds_max.z < fz) pc->bounds_max.z = fz + +#ifdef SIMD +#define UPDATE_3D_BBOX_SIMD() \ +__asm {\ + __asm movups xmm0, fx\ + __asm movaps xmm1, pc->bounds_min.x\ + __asm movaps xmm2, pc->bounds_max.x\ + __asm minps xmm1, xmm0\ + __asm maxps xmm2, xmm0\ + __asm movaps pc->bounds_min.x, xmm1\ + __asm movaps pc->bounds_max.x, xmm2\ +} +#define UPDATE_3D_BBOX_SIMD_PACK() \ +__asm {\ + __asm mov ecx, [data_ptr]\ + __asm movups xmm0, fx\ + __asm movaps xmm1, pc->bounds_min.x\ + __asm movaps xmm2, pc->bounds_max.x\ + __asm minps xmm1, xmm0\ + __asm maxps xmm2, xmm0\ + __asm movaps pc->bounds_min.x, xmm1\ + __asm movaps pc->bounds_max.x, xmm2\ + __asm movups [ecx], xmm0\ +} +#define UPDATE_3DV_BBOX_SIMD() \ +__asm {\ + __asm mov eax, [v]\ + __asm mov ecx, [data_ptr]\ + __asm movups xmm0, [eax]\ + __asm movaps xmm1, pc->bounds_min.x\ + __asm movaps xmm2, pc->bounds_max.x\ + __asm minps xmm1, xmm0\ + __asm maxps xmm2, xmm0\ + __asm movaps pc->bounds_min.x, xmm1\ + __asm movaps pc->bounds_max.x, xmm2\ + __asm movups [ecx], xmm0\ +} +#else +#define UPDATE_3DV_BBOX_SIMD() { CREATE_3D_VFLOATS(); UPDATE_3D_BBOX();} +#define UPDATE_3D_BBOX_SIMD() UPDATE_3D_BBOX() +#endif + +#define CREATE_1D_FLOATS() \ + GLfloat fx = (GLfloat) x; + +#define CREATE_2D_FLOATS() \ + GLfloat fx = (GLfloat) x; \ + GLfloat fy = (GLfloat) y + +#define CREATE_3D_FLOATS() \ + GLfloat fx = (GLfloat) x; \ + GLfloat fy = (GLfloat) y; \ + GLfloat fz = (GLfloat) z + +#define CREATE_4D_FLOATS() \ + GLfloat fx = (GLfloat) x; \ + GLfloat fy = (GLfloat) y; \ + GLfloat fz = (GLfloat) z; \ + GLfloat fw = (GLfloat) w; \ + fx /= fw; fy /= fw; fz/= fw + +/* For glVertexAttrib4N*ARB */ +#define CREATE_3D_FLOATS_B_NORMALIZED() \ + GLfloat fx = (GLfloat) x * (1.0 / 128.0); \ + GLfloat fy = (GLfloat) y * (1.0 / 128.0); \ + GLfloat fz = (GLfloat) z * (1.0 / 128.0); + +#define CREATE_3D_FLOATS_UB_NORMALIZED() \ + GLfloat fx = (GLfloat) x * (1.0 / 255.0); \ + GLfloat fy = (GLfloat) y * (1.0 / 255.0); \ + GLfloat fz = (GLfloat) z * (1.0 / 255.0); + +#define CREATE_3D_FLOATS_US_NORMALIZED() \ + GLfloat fx = (GLfloat) x * (1.0 / 65535.0); \ + GLfloat fy = (GLfloat) y * (1.0 / 65535.0); \ + GLfloat fz = (GLfloat) z * (1.0 / 65535.0); + + +#define CREATE_1D_VFLOATS() \ + GLfloat fx = (GLfloat) v[0]; + +#define CREATE_2D_VFLOATS() \ + GLfloat fx = (GLfloat) v[0]; \ + GLfloat fy = (GLfloat) v[1] + +#define CREATE_3D_VFLOATS() \ + GLfloat fx = (GLfloat) v[0]; \ + GLfloat fy = (GLfloat) v[1]; \ + GLfloat fz = (GLfloat) v[2] + +#define CREATE_4D_VFLOATS() \ + GLfloat fx = (GLfloat) v[0]; \ + GLfloat fy = (GLfloat) v[1]; \ + GLfloat fz = (GLfloat) v[2]; \ + GLfloat fw = (GLfloat) v[3]; \ + fx /= fw; fy /= fw; fz/= fw + +/* For glVertexAttrib4N*ARB */ +#define CREATE_4D_FLOATS_UB_NORMALIZED() \ + GLfloat fx = (GLfloat) (x * (1.0 / 255.0)); \ + GLfloat fy = (GLfloat) (y * (1.0 / 255.0)); \ + GLfloat fz = (GLfloat) (z * (1.0 / 255.0)); \ + GLfloat fw = (GLfloat) (w * (1.0 / 255.0)); \ + fx /= fw; fy /= fw; fz/= fw + +#define CREATE_4D_VFLOATS_B_NORMALIZED() \ + GLfloat fx = (GLfloat) (v[0] * (1.0 / 128.0)); \ + GLfloat fy = (GLfloat) (v[1] * (1.0 / 128.0)); \ + GLfloat fz = (GLfloat) (v[2] * (1.0 / 128.0)); \ + GLfloat fw = (GLfloat) (v[3] * (1.0 / 128.0)); \ + fx /= fw; fy /= fw; fz/= fw + +#define CREATE_4D_VFLOATS_S_NORMALIZED() \ + GLfloat fx = (GLfloat) (2.0 * v[0] + 1.0) / ((GLfloat) (0xffff)); \ + GLfloat fy = (GLfloat) (2.0 * v[1] + 1.0) / ((GLfloat) (0xffff)); \ + GLfloat fz = (GLfloat) (2.0 * v[2] + 1.0) / ((GLfloat) (0xffff)); \ + GLfloat fw = (GLfloat) (2.0 * v[3] + 1.0) / ((GLfloat) (0xffff)); \ + fx /= fw; fy /= fw; fz/= fw + +#define CREATE_4D_VFLOATS_I_NORMALIZED() \ + GLfloat fx = (GLfloat) (2.0 * v[0] + 1.0) / ((GLfloat) (0xffffffff)); \ + GLfloat fy = (GLfloat) (2.0 * v[1] + 1.0) / ((GLfloat) (0xffffffff)); \ + GLfloat fz = (GLfloat) (2.0 * v[2] + 1.0) / ((GLfloat) (0xffffffff)); \ + GLfloat fw = (GLfloat) (2.0 * v[3] + 1.0) / ((GLfloat) (0xffffffff)); \ + fx /= fw; fy /= fw; fz/= fw + +#define CREATE_4D_VFLOATS_UB_NORMALIZED() \ + GLfloat fx = (GLfloat) (v[0] * (1.0 / 255.0)); \ + GLfloat fy = (GLfloat) (v[1] * (1.0 / 255.0)); \ + GLfloat fz = (GLfloat) (v[2] * (1.0 / 255.0)); \ + GLfloat fw = (GLfloat) (v[3] * (1.0 / 255.0)); \ + fx /= fw; fy /= fw; fz/= fw + +#define CREATE_4D_VFLOATS_US_NORMALIZED() \ + GLfloat fx = (GLfloat) (v[0] * (1.0 / 65535.0)); \ + GLfloat fy = (GLfloat) (v[1] * (1.0 / 65535.0)); \ + GLfloat fz = (GLfloat) (v[2] * (1.0 / 65535.0)); \ + GLfloat fw = (GLfloat) (v[3] * (1.0 / 65535.0)); \ + fx /= fw; fy /= fw; fz/= fw + +#define CREATE_4D_VFLOATS_UI_NORMALIZED() \ + GLfloat fx = v[0] / ((GLfloat) (0xffffffff)); \ + GLfloat fy = v[1] / ((GLfloat) (0xffffffff)); \ + GLfloat fz = v[2] / ((GLfloat) (0xffffffff)); \ + GLfloat fw = v[3] / ((GLfloat) (0xffffffff)); \ + fx /= fw; fy /= fw; fz/= fw + +#endif /* CR_PACK_BBOX_H */ + diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_beginend.c b/src/VBox/GuestHost/OpenGL/packer/pack_beginend.c new file mode 100644 index 00000000..e6057639 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_beginend.c @@ -0,0 +1,86 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_protocol.h" + +void PACK_APIENTRY crPackBegin( GLenum mode ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + + if (CR_CMDBLOCK_IS_STARTED(pc, CRPACKBLOCKSTATE_OP_BEGIN)) + { + WARN(("recursive begin?")); + return; + } + + CR_CMDBLOCK_BEGIN( pc, CRPACKBLOCKSTATE_OP_BEGIN ); +#ifndef VBOX + if (pc->buffer.canBarf) + { + if (!pc->buffer.holds_BeginEnd) + pc->Flush( pc->flush_arg ); + pc->buffer.in_BeginEnd = 1; + pc->buffer.holds_BeginEnd = 1; + } +#endif + CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, 4, GL_FALSE); + pc->current.begin_data = data_ptr; + pc->current.begin_op = pc->buffer.opcode_current; + pc->current.attribsUsedMask = 0; + WRITE_DATA( 0, GLenum, mode ); + WRITE_OPCODE( pc, CR_BEGIN_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackBeginSWAP( GLenum mode ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; +#ifndef VBOX + if (pc->buffer.canBarf) + { + if (!pc->buffer.holds_BeginEnd) + pc->Flush( pc->flush_arg ); + pc->buffer.in_BeginEnd = 1; + pc->buffer.holds_BeginEnd = 1; + } +#endif + CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, 4, GL_FALSE); + pc->current.begin_data = data_ptr; + pc->current.begin_op = pc->buffer.opcode_current; + pc->current.attribsUsedMask = 0; + WRITE_DATA( 0, GLenum, SWAP32(mode) ); + WRITE_OPCODE( pc, CR_BEGIN_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackEnd( void ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER_NO_ARGS( pc ); + WRITE_OPCODE( pc, CR_END_OPCODE ); + pc->buffer.in_BeginEnd = 0; + CR_CMDBLOCK_END( pc, CRPACKBLOCKSTATE_OP_BEGIN ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackEndSWAP( void ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER_NO_ARGS( pc ); + WRITE_OPCODE( pc, CR_END_OPCODE ); + pc->buffer.in_BeginEnd = 0; + CR_CMDBLOCK_END( pc, CRPACKBLOCKSTATE_OP_BEGIN ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_bounds.c b/src/VBox/GuestHost/OpenGL/packer/pack_bounds.c new file mode 100644 index 00000000..191383bd --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_bounds.c @@ -0,0 +1,50 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_mem.h" + +void PACK_APIENTRY crPackBoundsInfoCR( CR_PACKER_CONTEXT_ARGDECL const CRrecti *bounds, const GLbyte *payload, GLint len, GLint num_opcodes ) +{ + CR_GET_PACKER_CONTEXT(pc); + /* Don't get the buffered_ptr here because we've already + * verified that there's enough space for everything. */ + + unsigned char *data_ptr; + int len_aligned, total_len; + + CR_LOCK_PACKER_CONTEXT(pc); + + data_ptr = pc->buffer.data_current; + len_aligned = ( len + 0x3 ) & ~0x3; + total_len = 24 + len_aligned; + + WRITE_DATA( 0, int, total_len ); + WRITE_DATA( 4, int, bounds->x1 ); + WRITE_DATA( 8, int, bounds->y1 ); + WRITE_DATA( 12, int, bounds->x2 ); + WRITE_DATA( 16, int, bounds->y2 ); + WRITE_DATA( 20, int, num_opcodes ); + + /* skip the BOUNDSINFO */ + data_ptr += 24; + + /* put in padding opcodes (deliberately bogus) */ + switch ( len_aligned - len ) + { + case 3: *data_ptr++ = 0xff; RT_FALL_THRU(); + case 2: *data_ptr++ = 0xff; RT_FALL_THRU(); + case 1: *data_ptr++ = 0xff; RT_FALL_THRU(); + default: break; + } + + crMemcpy( data_ptr, payload, len ); + + WRITE_OPCODE( pc, CR_BOUNDSINFOCR_OPCODE ); + pc->buffer.data_current += 24 + len_aligned; + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_buffer.c b/src/VBox/GuestHost/OpenGL/packer/pack_buffer.c new file mode 100644 index 00000000..003b76c0 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_buffer.c @@ -0,0 +1,533 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "cr_mem.h" +#include "cr_string.h" +#include "packer.h" +#include "cr_error.h" +#include "cr_protocol.h" +#ifndef IN_RING0 +#include "cr_unpack.h" +#endif + +#ifndef IN_RING0 +void crWriteUnalignedDouble( void *buffer, double d ) +{ + unsigned int *ui = (unsigned int *) buffer; + ui[0] = ((unsigned int *) &d)[0]; + ui[1] = ((unsigned int *) &d)[1]; +} + +void crWriteSwappedDouble( void *buffer, double d ) +{ + unsigned int *ui = (unsigned int *) buffer; + ui[0] = SWAP32(((unsigned int *) &d)[1]); + ui[1] = SWAP32(((unsigned int *) &d)[0]); +} + +double crReadUnalignedDouble( const void *buffer ) +{ + const unsigned int *ui = (unsigned int *) buffer; + double d; + ((unsigned int *) &d)[0] = ui[0]; + ((unsigned int *) &d)[1] = ui[1]; + return d; +} +#endif +/* + * We need the packer to run as efficiently as possible. To avoid one + * pointer dereference from the CRPackContext to the current CRPackBuffer, + * we keep a _copy_ of the current CRPackBuffer in the CRPackContext and + * operate on the fields in CRPackContext, rather than the CRPackBuffer. + * + * To keep things in sync, when we change a context's + * buffer, we have to use the crPackSet/GetBuffer() functions. + */ + +void crPackSetBuffer( CRPackContext *pc, CRPackBuffer *buffer ) +{ + CRASSERT( pc ); + CRASSERT( buffer ); + + if (pc->currentBuffer == buffer) + return; /* re-bind is no-op */ + + if (pc->currentBuffer) { + /* Another buffer currently bound to this packer (shouldn't normally occur) + * Release it. Fixes Ensight issue. + */ + crPackReleaseBuffer(pc); + } + + CRASSERT( pc->currentBuffer == NULL); /* release if NULL? */ + CRASSERT( buffer->context == NULL ); + + /* bind context to buffer */ + pc->currentBuffer = buffer; + buffer->context = pc; + + /* update the context's packing fields with those from the buffer */ + pc->buffer = *buffer; /* struct copy */ +} + +#ifndef IN_RING0 +/* This is useful for debugging packer problems */ +void crPackSetBufferDEBUG( const char *file, int line, CRPackContext *pc, CRPackBuffer *buffer) + +{ + crPackSetBuffer( pc, buffer ); + /* record debugging info */ + pc->file = crStrdup(file); + pc->line = line; +} +#endif + +/* + * Release the buffer currently attached to the context. + * Update/resync data structures. + */ +void crPackReleaseBuffer( CRPackContext *pc ) +{ + CRPackBuffer *buf; + CRASSERT( pc ); + + if (!pc->currentBuffer) { + crWarning("crPackReleaseBuffer called with no current buffer"); + return; /* nothing to do */ + } + + CRASSERT( pc->currentBuffer->context == pc ); + + /* buffer to release */ + buf = pc->currentBuffer; + + /* copy context's fields back into the buffer to update it */ + *buf = pc->buffer; /* struct copy */ + + /* unbind buffer from context */ + buf->context = NULL; + pc->currentBuffer = NULL; + + /* zero-out context's packing fields just to be safe */ + crMemZero(&(pc->buffer), sizeof(pc->buffer)); + + /* update the debugging fields */ + if (pc->file) + crFree(pc->file); + pc->file = NULL; + pc->line = -1; +} + +void crPackFlushFunc( CRPackContext *pc, CRPackFlushFunc ff ) +{ + pc->Flush = ff; +} + +void crPackFlushArg( CRPackContext *pc, void *flush_arg ) +{ + pc->flush_arg = flush_arg; +} + +void crPackSendHugeFunc( CRPackContext *pc, CRPackSendHugeFunc shf ) +{ + pc->SendHuge = shf; +} + +/* + * This basically resets the buffer attached to <pc> to the default, empty + * state. + */ +void crPackResetPointers( CRPackContext *pc ) +{ + const GLboolean geom_only = pc->buffer.geometry_only; /* save this flag */ + const GLboolean holds_BeginEnd = pc->buffer.holds_BeginEnd; + const GLboolean in_BeginEnd = pc->buffer.in_BeginEnd; + const GLboolean canBarf = pc->buffer.canBarf; + CRPackBuffer *buf = pc->currentBuffer; + CRASSERT(buf); + crPackInitBuffer( buf, buf->pack, buf->size, buf->mtu +#ifdef IN_RING0 + , 0 +#endif + ); + pc->buffer.geometry_only = geom_only; /* restore the flag */ + pc->buffer.holds_BeginEnd = holds_BeginEnd; + pc->buffer.in_BeginEnd = in_BeginEnd; + pc->buffer.canBarf = canBarf; +} + + +/** + * Return max number of opcodes that'll fit in the given buffer size. + * Each opcode has at least a 1-word payload, so opcodes can occupy at most + * 20% of the space. + */ +int +crPackMaxOpcodes( int buffer_size ) +{ + int n = ( buffer_size - sizeof(CRMessageOpcodes) ) / 5; + /* Don't forget to add one here in case the buffer size is not + * divisible by 4. Thanks to Ken Moreland for finding this. + */ + n++; + /* round up to multiple of 4 */ + n = (n + 0x3) & (~0x3); + return n; +} + + +/** + * Return max number of data bytes that'll fit in the given buffer size. + */ +int +crPackMaxData( int buffer_size ) +{ + int n = buffer_size - sizeof(CRMessageOpcodes); + n -= crPackMaxOpcodes(buffer_size); + return n; +} + + +/** + * Initialize the given CRPackBuffer object. + * The buffer may or may not be currently bound to a CRPackContext. + * + * Opcodes and operands are packed into a buffer in a special way. + * Opcodes start at opcode_start and go downward in memory while operands + * start at data_start and go upward in memory. The buffer is full when we + * either run out of opcode space or operand space. + * + * Diagram (memory addresses increase upward): + * + * data_end -> | | <- buf->pack + buf->size + * +---------+ + * | | + * | | + * | operands| + * | | + * | | + * data_start -> +---------+ + * opcode_start -> | | + * | | + * | opcodes | + * | | + * | | + * opcode_end -> +---------+ <- buf->pack + * + * \param buf the CRPackBuffer to initialize + * \param pack the address of the buffer for packing opcodes/operands. + * \param size size of the buffer, in bytes + * \param mtu max transmission unit size, in bytes. When the buffer + * has 'mtu' bytes in it, we have to send it. The MTU might + * be somewhat smaller than the buffer size. + */ +void crPackInitBuffer( CRPackBuffer *buf, void *pack, int size, int mtu +#ifdef IN_RING0 + , unsigned int num_opcodes +#endif + ) +{ +#ifndef IN_RING0 + unsigned int num_opcodes; +#endif + + CRASSERT(mtu <= size); + + buf->size = size; + buf->mtu = mtu; + buf->pack = pack; + +#ifdef IN_RING0 + if(num_opcodes) + { + num_opcodes = (num_opcodes + 0x3) & (~0x3); + } + else +#endif + { + num_opcodes = crPackMaxOpcodes( buf->size ); + } + + buf->data_start = + (unsigned char *) buf->pack + num_opcodes + sizeof(CRMessageOpcodes); + buf->data_current = buf->data_start; + buf->data_end = (unsigned char *) buf->pack + buf->size; + + buf->opcode_start = buf->data_start - 1; + buf->opcode_current = buf->opcode_start; + buf->opcode_end = buf->opcode_start - num_opcodes; + + buf->geometry_only = GL_FALSE; + buf->holds_BeginEnd = GL_FALSE; + buf->in_BeginEnd = GL_FALSE; + buf->canBarf = GL_FALSE; + + if (buf->context) { + /* Also reset context's packing fields */ + CRPackContext *pc = buf->context; + CRASSERT(pc->currentBuffer == buf); + /*crMemcpy( &(pc->buffer), buf, sizeof(*buf) );*/ + pc->buffer = *buf; + } +} + + +int crPackCanHoldBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *src ) +{ + const int num_data = crPackNumData(src); + const int num_opcode = crPackNumOpcodes(src); + int res; + CR_GET_PACKER_CONTEXT(pc); + CR_LOCK_PACKER_CONTEXT(pc); + res = crPackCanHoldOpcode( pc, num_opcode, num_data ); + CR_UNLOCK_PACKER_CONTEXT(pc); + return res; +} + + +int crPackCanHoldBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *src ) +{ + const int len_aligned = (src->data_current - src->opcode_current - 1 + 3) & ~3; + CR_GET_PACKER_CONTEXT(pc); + /* 24 is the size of the bounds-info packet... */ + return crPackCanHoldOpcode( pc, 1, len_aligned + 24 ); +} + +void crPackAppendBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *src ) +{ + CR_GET_PACKER_CONTEXT(pc); + const int num_data = crPackNumData(src); + const int num_opcode = crPackNumOpcodes(src); + + CRASSERT(num_data >= 0); + CRASSERT(num_opcode >= 0); + + CR_LOCK_PACKER_CONTEXT(pc); + + /* don't append onto ourself! */ + CRASSERT(pc->currentBuffer); + CRASSERT(pc->currentBuffer != src); + + if (!crPackCanHoldBuffer(CR_PACKER_CONTEXT_ARG src)) + { + if (src->holds_BeginEnd) + { + crWarning( "crPackAppendBuffer: overflowed the destination!" ); + CR_UNLOCK_PACKER_CONTEXT(pc); + return; + } + else + { + crError( "crPackAppendBuffer: overflowed the destination!" ); + CR_UNLOCK_PACKER_CONTEXT(pc); + } + } + + /* Copy the buffer data/operands which are at the head of the buffer */ + crMemcpy( pc->buffer.data_current, src->data_start, num_data ); + pc->buffer.data_current += num_data; + + /* Copy the buffer opcodes which are at the tail of the buffer */ + CRASSERT( pc->buffer.opcode_current - num_opcode >= pc->buffer.opcode_end ); + crMemcpy( pc->buffer.opcode_current + 1 - num_opcode, src->opcode_current + 1, + num_opcode ); + pc->buffer.opcode_current -= num_opcode; + pc->buffer.holds_BeginEnd |= src->holds_BeginEnd; + pc->buffer.in_BeginEnd = src->in_BeginEnd; + pc->buffer.holds_List |= src->holds_List; + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void +crPackAppendBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *src, const CRrecti *bounds ) +{ + CR_GET_PACKER_CONTEXT(pc); + const GLbyte *payload = (const GLbyte *) src->opcode_current + 1; + const int num_opcodes = crPackNumOpcodes(src); + const int length = src->data_current - src->opcode_current - 1; + + CRASSERT(pc); + CR_LOCK_PACKER_CONTEXT(pc); + CRASSERT(pc->currentBuffer); + CRASSERT(pc->currentBuffer != src); + + /* + * payload points to the block of opcodes immediately followed by operands. + */ + + if ( !crPackCanHoldBoundedBuffer( CR_PACKER_CONTEXT_ARG src ) ) + { + if (src->holds_BeginEnd) + { + crWarning( "crPackAppendBoundedBuffer: overflowed the destination!" ); + CR_UNLOCK_PACKER_CONTEXT(pc); + return; + } + else + { + crError( "crPackAppendBoundedBuffer: overflowed the destination!" ); + CR_UNLOCK_PACKER_CONTEXT(pc); + } + } + + if (pc->swapping) + crPackBoundsInfoCRSWAP( CR_PACKER_CONTEXT_ARG bounds, payload, length, num_opcodes ); + else + crPackBoundsInfoCR( CR_PACKER_CONTEXT_ARG bounds, payload, length, num_opcodes ); + + pc->buffer.holds_BeginEnd |= src->holds_BeginEnd; + pc->buffer.in_BeginEnd = src->in_BeginEnd; + pc->buffer.holds_List |= src->holds_List; + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +#ifndef CHROMIUM_THREADSAFE +static unsigned char *sanityCheckPointer = NULL; +#endif + + +/* + * Allocate space for a command that might be very large, such as + * glTexImage2D or glBufferDataARB call. + * The command buffer _MUST_ then be transmitted by calling crHugePacket. + */ +void *crPackAlloc( CR_PACKER_CONTEXT_ARGDECL unsigned int size ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + + /* include space for the length and make the payload word-aligned */ + size = ( size + sizeof(unsigned int) + 0x3 ) & ~0x3; + + CR_LOCK_PACKER_CONTEXT(pc); + + if ( crPackCanHoldOpcode( pc, 1, size ) ) + { + /* we can just put it in the current buffer */ + CR_GET_BUFFERED_POINTER_NOLOCK(pc, size ); /* NOTE: this sets data_ptr */ + } + else + { + /* Okay, it didn't fit. Maybe it will after we flush. */ + CR_UNLOCK_PACKER_CONTEXT(pc); + pc->Flush( pc->flush_arg ); + CR_LOCK_PACKER_CONTEXT(pc); + if ( crPackCanHoldOpcode( pc, 1, size ) ) + { + CR_GET_BUFFERED_POINTER_NOLOCK(pc, size ); /* NOTE: this sets data_ptr */ + } + else + { + /* It's really way too big, so allocate a temporary packet + * with space for the single opcode plus the payload & + * header. + */ + data_ptr = (unsigned char *) + crAlloc( sizeof(CRMessageOpcodes) + 4 + size ); + + /* skip the header & opcode space */ + data_ptr += sizeof(CRMessageOpcodes) + 4; + } + } + + /* At the top of the function, we added four to the request size and + * rounded it up to the next multiple of four. + * + * At this point, we have: + * + * HIGH MEM | byte size - 1 | \ + * ... | + * ... | - original 'size' bytes for data + * | operand data | | + * return value -> | operand data | / + * | byte 3 | \ + * | byte 2 | |- These bytes will store 'size' + * | byte 1 | | + * data_ptr -> | byte 0 | / + * | CR opcode | <- Set in packspuHuge() + * | unused | + * | unused | + * | unused | + * | CRMessageOpcodes | + * | CRMessageOpcodes | + * ... + * | CRMessageOpcodes | + * | CRMessageOpcodes | + * LOW MEM +------------------+ + */ + + if (pc->swapping) + { + *((unsigned int *) data_ptr) = SWAP32(size); + crDebug( "Just swapped the length, putting %d on the wire!", *((unsigned int *) data_ptr)); + } + else + { + *((unsigned int *) data_ptr) = size; + } +#ifndef CHROMIUM_THREADSAFE + sanityCheckPointer = data_ptr + 4; +#endif + return data_ptr + 4; +} + +#define IS_BUFFERED( packet ) \ + ((unsigned char *) (packet) >= pc->buffer.data_start && \ + (unsigned char *) (packet) < pc->buffer.data_end) + + +/* + * Transmit a packet which was allocated with crPackAlloc. + */ +void crHugePacket( CR_PACKER_CONTEXT_ARGDECL CROpcode opcode, void *packet ) +{ + CR_GET_PACKER_CONTEXT(pc); +#ifndef CHROMIUM_THREADSAFE + CRASSERT(sanityCheckPointer == packet); + sanityCheckPointer = NULL; +#endif + + if ( IS_BUFFERED( packet ) ) + WRITE_OPCODE( pc, opcode ); + else + pc->SendHuge( opcode, packet ); +} + +void crPackFree( CR_PACKER_CONTEXT_ARGDECL void *packet ) +{ + CR_GET_PACKER_CONTEXT(pc); + + if ( IS_BUFFERED( packet ) ) + { + CR_UNLOCK_PACKER_CONTEXT(pc); + return; + } + + CR_UNLOCK_PACKER_CONTEXT(pc); + + /* the pointer passed in doesn't include the space for the single + * opcode (4 bytes because of the alignment requirement) or the + * length field or the header */ + crFree( (unsigned char *) packet - 8 - sizeof(CRMessageOpcodes) ); +} + +void crNetworkPointerWrite( CRNetworkPointer *dst, void *src ) +{ + /* init CRNetworkPointer with invalid values */ + dst->ptrAlign[0] = 0xDeadBeef; + dst->ptrAlign[1] = 0xCafeBabe; + /* copy the pointer's value into the CRNetworkPointer */ + crMemcpy( dst, &src, sizeof(src) ); + + /* if either assertion fails, it probably means that a packer function + * (which returns a value) was called without setting up the writeback + * pointer, or something like that. + */ + CRASSERT(dst->ptrAlign[0] != 0xffffffff); + CRASSERT(dst->ptrAlign[0] != 0xDeadBeef); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_bufferobject.c b/src/VBox/GuestHost/OpenGL/packer/pack_bufferobject.c new file mode 100644 index 00000000..d7bb275a --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_bufferobject.c @@ -0,0 +1,121 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_error.h" +#include "cr_string.h" +#include "cr_version.h" + + +void PACK_APIENTRY +crPackMapBufferARB( GLenum target, GLenum access, + void * return_value, int * writeback ) +{ + (void)writeback; + (void)return_value; + (void)target; + (void)access; + crWarning("Can't pack MapBufferARB command!"); +} + + +void PACK_APIENTRY +crPackUnmapBufferARB( GLenum target, GLboolean* return_value, int * writeback ) +{ + (void)target; + (void)return_value; + (void)writeback; + crWarning("Can't pack UnmapBufferARB command!"); +} + + +void PACK_APIENTRY +crPackBufferDataARB( GLenum target, GLsizeiptrARB size, + const GLvoid * data, GLenum usage ) +{ + unsigned char *data_ptr, *start_ptr; + int packet_length; + + packet_length = sizeof(GLenum) + + sizeof(target) + sizeof(GLuint) + sizeof(usage) + sizeof(GLint); + + /*Note: it's valid to pass a NULL pointer here, which tells GPU drivers to allocate memory for the VBO*/ + if (data) packet_length += size; + + start_ptr = data_ptr = (unsigned char *) crPackAlloc( packet_length ); + + WRITE_DATA_AI(GLenum, CR_BUFFERDATAARB_EXTEND_OPCODE); + WRITE_DATA_AI(GLenum, target); + WRITE_DATA_AI(GLuint, (GLuint) size); + WRITE_DATA_AI(GLenum, usage); + WRITE_DATA_AI(GLint, (GLint) (data!=NULL)); + if (data) + crMemcpy(data_ptr, data, size); + + crHugePacket( CR_EXTEND_OPCODE, start_ptr ); + crPackFree( start_ptr ); +} + + +void PACK_APIENTRY +crPackBufferSubDataARB( GLenum target, GLintptrARB offset, GLsizeiptrARB size, + const GLvoid * data ) +{ + unsigned char *data_ptr, *start_ptr; + int packet_length; + + if (!data) + return; + + packet_length = sizeof(GLenum) + + sizeof(target) + sizeof(GLuint) + sizeof(GLuint) + size; + + start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA_AI(GLenum, CR_BUFFERSUBDATAARB_EXTEND_OPCODE); + WRITE_DATA_AI(GLenum, target); + WRITE_DATA_AI(GLuint, (GLuint) offset); + WRITE_DATA_AI(GLuint, (GLuint) size); + crMemcpy(data_ptr, data, size); + + crHugePacket(CR_EXTEND_OPCODE, start_ptr); + crPackFree(start_ptr); +} + +void PACK_APIENTRY +crPackGetBufferSubDataARB( GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data, int * writeback ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER( pc, 36 ); + WRITE_DATA( 0, GLint, 36 ); + WRITE_DATA( 4, GLenum, CR_GETBUFFERSUBDATAARB_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, target ); + WRITE_DATA( 12, GLuint, (GLuint) offset ); + WRITE_DATA( 16, GLuint, (GLuint) size ); + WRITE_NETWORK_POINTER( 20, (void *) data ); + WRITE_NETWORK_POINTER( 28, (void *) writeback ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY +crPackDeleteBuffersARB(GLsizei n, const GLuint * buffers) +{ + unsigned char *data_ptr; + int packet_length = sizeof(GLenum) + sizeof(n) + n * sizeof(*buffers); + + if (!buffers) + return; + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA( 0, GLenum, CR_DELETEBUFFERSARB_EXTEND_OPCODE ); + WRITE_DATA( 4, GLsizei, n ); + crMemcpy( data_ptr + 8, buffers, n * sizeof(*buffers) ); + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_client.c b/src/VBox/GuestHost/OpenGL/packer/pack_client.c new file mode 100644 index 00000000..e9247692 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_client.c @@ -0,0 +1,1089 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_version.h" +#include "state/cr_limits.h" +#include "cr_glstate.h" + +/*Convert from GLint to GLfloat in [-1.f,1.f]*/ +#define CRP_I2F_NORM(i) ((2.f*((GLint)(i))+1.f) * (1.f/4294967294.f)) +/*Convert from GLshort to GLfloat in [-1.f,1.f]*/ +#define CRP_S2F_NORM(s) ((2.f*((GLshort)(s))+1.f) * (1.f/65535.f)) +/*Convert from GLbyte to GLfloat in [-1.f,1.f]*/ +#define CRP_B2F_NORM(b) ((2.f*((GLbyte)(b))+1.f) * (1.f/255.f)) +/*Convert from GLuint to GLfloat in [0.f,1.f]*/ +#define CRP_UI2F_NORM(i) ((GLfloat)(i) * (1.f/4294967295.f)) +/*Convert from GLushort to GLfloat in [0.f,1.f]*/ +#define CRP_US2F_NORM(s) ((GLfloat)(s) * (1.f/65535.f)) +/*Convert from GLubyte to GLfloat in [0.f,1.f]*/ +#define CRP_UB2F_NORM(b) ((GLfloat)(b) * (1.f/255.f)) + +static void crPackVertexAttrib(const CRVertexArrays *array, unsigned int attr, GLint index) +{ + unsigned char *p = array->a[attr].p + index * array->a[attr].stride; + +#ifdef DEBUG_misha + Assert(index >= 0); +#endif + +#ifdef CR_ARB_vertex_buffer_object + if (array->a[attr].buffer && array->a[attr].buffer->data) + { + Assert(((uintptr_t)p) < array->a[attr].buffer->size); + p = (unsigned char *)(array->a[attr].buffer->data) + (uintptr_t)p; + } +#endif + + if (!p) + { + crWarning("crPackVertexAttrib: NULL ptr!"); + return; + } + + switch (array->a[attr].type) + { + case GL_SHORT: + { + GLshort *sPtr = (GLshort*) p; + switch (array->a[attr].size) + { + case 1: + if (array->a[attr].normalized) + crPackVertexAttrib1fARB(attr, CRP_S2F_NORM(sPtr[0])); + else + crPackVertexAttrib1svARB(attr, sPtr); + break; + case 2: + if (array->a[attr].normalized) + crPackVertexAttrib2fARB(attr, CRP_S2F_NORM(sPtr[0]), CRP_S2F_NORM(sPtr[1])); + else + crPackVertexAttrib2svARB(attr, sPtr); + break; + case 3: + if (array->a[attr].normalized) + crPackVertexAttrib3fARB(attr, CRP_S2F_NORM(sPtr[0]), CRP_S2F_NORM(sPtr[1]), CRP_S2F_NORM(sPtr[2])); + else + crPackVertexAttrib3svARB(attr, sPtr); + break; + case 4: + if (array->a[attr].normalized) + crPackVertexAttrib4NsvARB(attr, sPtr); + else + crPackVertexAttrib4svARB(attr, sPtr); + break; + } + break; + } + case GL_UNSIGNED_SHORT: + { + GLushort *usPtr = (GLushort*) p; + if (array->a[attr].normalized) + { + switch (array->a[attr].size) + { + case 1: + crPackVertexAttrib1fARB(attr, CRP_US2F_NORM(usPtr[0])); + break; + case 2: + crPackVertexAttrib2fARB(attr, CRP_US2F_NORM(usPtr[0]), CRP_US2F_NORM(usPtr[1])); + break; + case 3: + crPackVertexAttrib3fARB(attr, CRP_US2F_NORM(usPtr[0]), CRP_US2F_NORM(usPtr[1]), CRP_US2F_NORM(usPtr[2])); + break; + case 4: + crPackVertexAttrib4NusvARB(attr, usPtr); + break; + } + } + else + { + GLushort usv[4]; + switch (array->a[attr].size) + { + case 4: + crPackVertexAttrib4usvARB(attr, usPtr); + break; + case 3: usv[2] = usPtr[2]; RT_FALL_THRU(); + case 2: usv[1] = usPtr[1]; RT_FALL_THRU(); + case 1: + usv[0] = usPtr[0]; + crPackVertexAttrib4usvARB(attr, usv); + break; + } + } + break; + } + case GL_INT: + { + GLint *iPtr = (GLint*) p; + if (array->a[attr].normalized) + { + switch (array->a[attr].size) + { + case 1: + crPackVertexAttrib1fARB(attr, CRP_I2F_NORM(iPtr[0])); + break; + case 2: + crPackVertexAttrib2fARB(attr, CRP_I2F_NORM(iPtr[0]), CRP_I2F_NORM(iPtr[1])); + break; + case 3: + crPackVertexAttrib3fARB(attr, CRP_I2F_NORM(iPtr[0]), CRP_I2F_NORM(iPtr[1]), CRP_I2F_NORM(iPtr[2])); + break; + case 4: + crPackVertexAttrib4NivARB(attr, iPtr); + break; + } + } + else + { + GLint iv[4]; + switch (array->a[attr].size) + { + case 4: + crPackVertexAttrib4ivARB(attr, iPtr); + break; + case 3: iv[2] = iPtr[2]; RT_FALL_THRU(); + case 2: iv[1] = iPtr[1]; RT_FALL_THRU(); + case 1: + iv[0] = iPtr[0]; + crPackVertexAttrib4ivARB(attr, iv); + break; + } + } + break; + } + case GL_UNSIGNED_INT: + { + GLuint *uiPtr = (GLuint*) p; + if (array->a[attr].normalized) + { + switch (array->a[attr].size) + { + case 1: + crPackVertexAttrib1fARB(attr, CRP_UI2F_NORM(uiPtr[0])); + break; + case 2: + crPackVertexAttrib2fARB(attr, CRP_UI2F_NORM(uiPtr[0]), CRP_UI2F_NORM(uiPtr[1])); + break; + case 3: + crPackVertexAttrib3fARB(attr, CRP_UI2F_NORM(uiPtr[0]), CRP_UI2F_NORM(uiPtr[1]), CRP_UI2F_NORM(uiPtr[2])); + break; + case 4: + crPackVertexAttrib4NuivARB(attr, uiPtr); + break; + } + } + else + { + GLuint uiv[4]; + switch (array->a[attr].size) + { + case 4: + crPackVertexAttrib4uivARB(attr, uiPtr); + break; + case 3: uiv[2] = uiPtr[2]; RT_FALL_THRU(); + case 2: uiv[1] = uiPtr[1]; RT_FALL_THRU(); + case 1: + uiv[0] = uiPtr[0]; + crPackVertexAttrib4uivARB(attr, uiv); + break; + } + } + break; + } + case GL_FLOAT: + switch (array->a[attr].size) + { + case 1: crPackVertexAttrib1fvARB(attr, (GLfloat *)p); break; + case 2: crPackVertexAttrib2fvARB(attr, (GLfloat *)p); break; + case 3: crPackVertexAttrib3fvARB(attr, (GLfloat *)p); break; + case 4: crPackVertexAttrib4fvARB(attr, (GLfloat *)p); break; + } + break; + case GL_DOUBLE: + switch (array->a[attr].size) + { + case 1: crPackVertexAttrib1dvARB(attr, (GLdouble *)p); break; + case 2: crPackVertexAttrib2dvARB(attr, (GLdouble *)p); break; + case 3: crPackVertexAttrib3dvARB(attr, (GLdouble *)p); break; + case 4: crPackVertexAttrib4dvARB(attr, (GLdouble *)p); break; + } + break; + case GL_BYTE: + { + GLbyte *bPtr = (GLbyte*) p; + if (array->a[attr].normalized) + { + switch (array->a[attr].size) + { + case 1: + crPackVertexAttrib1fARB(attr, CRP_B2F_NORM(bPtr[0])); + break; + case 2: + crPackVertexAttrib2fARB(attr, CRP_B2F_NORM(bPtr[0]), CRP_B2F_NORM(bPtr[1])); + break; + case 3: + crPackVertexAttrib3fARB(attr, CRP_B2F_NORM(bPtr[0]), CRP_B2F_NORM(bPtr[1]), CRP_B2F_NORM(bPtr[2])); + break; + case 4: + crPackVertexAttrib4NbvARB(attr, bPtr); + break; + } + } + else + { + GLbyte bv[4]; + switch (array->a[attr].size) + { + case 4: + crPackVertexAttrib4bvARB(attr, bPtr); + break; + case 3: bv[2] = bPtr[2]; RT_FALL_THRU(); + case 2: bv[1] = bPtr[1]; RT_FALL_THRU(); + case 1: + bv[0] = bPtr[0]; + crPackVertexAttrib4bvARB(attr, bv); + break; + } + } + break; + } + case GL_UNSIGNED_BYTE: + { + GLubyte *ubPtr = (GLubyte*) p; + if (array->a[attr].normalized) + { + switch (array->a[attr].size) + { + case 1: + crPackVertexAttrib1fARB(attr, CRP_UB2F_NORM(ubPtr[0])); + break; + case 2: + crPackVertexAttrib2fARB(attr, CRP_UB2F_NORM(ubPtr[0]), CRP_UB2F_NORM(ubPtr[1])); + break; + case 3: + crPackVertexAttrib3fARB(attr, CRP_UB2F_NORM(ubPtr[0]), CRP_UB2F_NORM(ubPtr[1]), CRP_UB2F_NORM(ubPtr[2])); + break; + case 4: + crPackVertexAttrib4NubvARB(attr, ubPtr); + break; + } + } + else + { + GLubyte ubv[4]; + switch (array->a[attr].size) + { + case 4: + crPackVertexAttrib4ubvARB(attr, ubPtr); + break; + case 3: ubv[2] = ubPtr[2]; RT_FALL_THRU(); + case 2: ubv[1] = ubPtr[1]; RT_FALL_THRU(); + case 1: + ubv[0] = ubPtr[0]; + crPackVertexAttrib4ubvARB(attr, ubv); + break; + } + } + break; + } + default: + crWarning("Bad datatype for vertex attribute [%d] array: 0x%x\n", + attr, array->a[attr].type); + } +} + +/* + * Expand glArrayElement into crPackVertex/Color/Normal/etc. + */ +void +crPackExpandArrayElement(GLint index, CRClientState *c, const GLfloat *pZva) +{ + unsigned char *p; + unsigned int unit, attr; + const CRVertexArrays *array = &(c->array); + const GLboolean vpEnabled = crStateGetCurrent()->program.vpEnabled; + + /*crDebug("crPackExpandArrayElement(%i)", index);*/ + + if (array->n.enabled && !(vpEnabled && array->a[VERT_ATTRIB_NORMAL].enabled)) + { + p = array->n.p + index * array->n.stride; + +#ifdef CR_ARB_vertex_buffer_object + if (array->n.buffer && array->n.buffer->data) + { + p = (unsigned char *)(array->n.buffer->data) + (uintptr_t)p; + } +#endif + + switch (array->n.type) + { + case GL_BYTE: crPackNormal3bv((GLbyte *)p); break; + case GL_SHORT: crPackNormal3sv((GLshort *)p); break; + case GL_INT: crPackNormal3iv((GLint *)p); break; + case GL_FLOAT: crPackNormal3fv((GLfloat *)p); break; + case GL_DOUBLE: crPackNormal3dv((GLdouble *)p); break; + default: + crWarning("Unhandled: crPackExpandArrayElement, array->n.type 0x%x", array->n.type); + } + } + + if (array->c.enabled && !(vpEnabled && array->a[VERT_ATTRIB_COLOR0].enabled)) + { + p = array->c.p + index * array->c.stride; + +#ifdef CR_ARB_vertex_buffer_object + if (array->c.buffer && array->c.buffer->data) + { + p = (unsigned char *)(array->c.buffer->data) + (uintptr_t)p; + } +#endif + + switch (array->c.type) + { + case GL_BYTE: + switch (c->array.c.size) + { + case 3: crPackColor3bv((GLbyte *)p); break; + case 4: crPackColor4bv((GLbyte *)p); break; + } + break; + case GL_UNSIGNED_BYTE: + switch (c->array.c.size) + { + case 3: crPackColor3ubv((GLubyte *)p); break; + case 4: crPackColor4ubv((GLubyte *)p); break; + } + break; + case GL_SHORT: + switch (c->array.c.size) + { + case 3: crPackColor3sv((GLshort *)p); break; + case 4: crPackColor4sv((GLshort *)p); break; + } + break; + case GL_UNSIGNED_SHORT: + switch (c->array.c.size) + { + case 3: crPackColor3usv((GLushort *)p); break; + case 4: crPackColor4usv((GLushort *)p); break; + } + break; + case GL_INT: + switch (c->array.c.size) + { + case 3: crPackColor3iv((GLint *)p); break; + case 4: crPackColor4iv((GLint *)p); break; + } + break; + case GL_UNSIGNED_INT: + switch (c->array.c.size) + { + case 3: crPackColor3uiv((GLuint *)p); break; + case 4: crPackColor4uiv((GLuint *)p); break; + } + break; + case GL_FLOAT: + switch (c->array.c.size) + { + case 3: crPackColor3fv((GLfloat *)p); break; + case 4: crPackColor4fv((GLfloat *)p); break; + } + break; + case GL_DOUBLE: + switch (c->array.c.size) + { + case 3: crPackColor3dv((GLdouble *)p); break; + case 4: crPackColor4dv((GLdouble *)p); break; + } + break; + default: + crWarning("Unhandled: crPackExpandArrayElement, array->c.type 0x%x", array->c.type); + } + } + +#ifdef CR_EXT_secondary_color + if (array->s.enabled && !(vpEnabled && array->a[VERT_ATTRIB_COLOR1].enabled)) + { + p = array->s.p + index * array->s.stride; + +#ifdef CR_ARB_vertex_buffer_object + if (array->s.buffer && array->s.buffer->data) + { + p = (unsigned char *)(array->s.buffer->data) + (uintptr_t)p; + } +#endif + + switch (array->s.type) + { + case GL_BYTE: + crPackSecondaryColor3bvEXT((GLbyte *)p); break; + case GL_UNSIGNED_BYTE: + crPackSecondaryColor3ubvEXT((GLubyte *)p); break; + case GL_SHORT: + crPackSecondaryColor3svEXT((GLshort *)p); break; + case GL_UNSIGNED_SHORT: + crPackSecondaryColor3usvEXT((GLushort *)p); break; + case GL_INT: + crPackSecondaryColor3ivEXT((GLint *)p); break; + case GL_UNSIGNED_INT: + crPackSecondaryColor3uivEXT((GLuint *)p); break; + case GL_FLOAT: + crPackSecondaryColor3fvEXT((GLfloat *)p); break; + case GL_DOUBLE: + crPackSecondaryColor3dvEXT((GLdouble *)p); break; + default: + crWarning("Unhandled: crPackExpandArrayElement, array->s.type 0x%x", array->s.type); + } + } +#endif /* CR_EXT_secondary_color */ + + +#ifdef CR_EXT_fog_coord + if (array->f.enabled && !(vpEnabled && array->a[VERT_ATTRIB_FOG].enabled)) + { + p = array->f.p + index * array->f.stride; + +#ifdef CR_ARB_vertex_buffer_object + if (array->f.buffer && array->f.buffer->data) + { + p = (unsigned char *)(array->f.buffer->data) + (uintptr_t)p; + } +#endif + crPackFogCoordfEXT( *((GLfloat *) p) ); + } +#endif /* CR_EXT_fog_coord */ + + for (unit = 0 ; unit < CR_MAX_TEXTURE_UNITS ; unit++) + { + if (array->t[unit].enabled && !(vpEnabled && array->a[VERT_ATTRIB_TEX0+unit].enabled)) + { + p = array->t[unit].p + index * array->t[unit].stride; + +#ifdef CR_ARB_vertex_buffer_object + if (array->t[unit].buffer && array->t[unit].buffer->data) + { + p = (unsigned char *)(array->t[unit].buffer->data) + (uintptr_t)p; + } +#endif + + switch (array->t[unit].type) + { + case GL_SHORT: + switch (array->t[unit].size) + { + case 1: crPackMultiTexCoord1svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break; + case 2: crPackMultiTexCoord2svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break; + case 3: crPackMultiTexCoord3svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break; + case 4: crPackMultiTexCoord4svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break; + } + break; + case GL_INT: + switch (array->t[unit].size) + { + case 1: crPackMultiTexCoord1ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break; + case 2: crPackMultiTexCoord2ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break; + case 3: crPackMultiTexCoord3ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break; + case 4: crPackMultiTexCoord4ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break; + } + break; + case GL_FLOAT: + switch (array->t[unit].size) + { + case 1: crPackMultiTexCoord1fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break; + case 2: crPackMultiTexCoord2fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break; + case 3: crPackMultiTexCoord3fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break; + case 4: crPackMultiTexCoord4fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break; + } + break; + case GL_DOUBLE: + switch (array->t[unit].size) + { + case 1: crPackMultiTexCoord1dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break; + case 2: crPackMultiTexCoord2dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break; + case 3: crPackMultiTexCoord3dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break; + case 4: crPackMultiTexCoord4dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break; + } + break; + default: + crWarning("Unhandled: crPackExpandArrayElement, array->t[%i].type 0x%x", unit, array->t[unit].type); + } + } + } + + if (array->i.enabled) + { + p = array->i.p + index * array->i.stride; + +#ifdef CR_ARB_vertex_buffer_object + if (array->i.buffer && array->i.buffer->data) + { + p = (unsigned char *)(array->i.buffer->data) + (uintptr_t)p; + } +#endif + + switch (array->i.type) + { + case GL_SHORT: crPackIndexsv((GLshort *)p); break; + case GL_INT: crPackIndexiv((GLint *)p); break; + case GL_FLOAT: crPackIndexfv((GLfloat *)p); break; + case GL_DOUBLE: crPackIndexdv((GLdouble *)p); break; + default: + crWarning("Unhandled: crPackExpandArrayElement, array->i.type 0x%x", array->i.type); + } + } + + if (array->e.enabled) + { + p = array->e.p + index * array->e.stride; + +#ifdef CR_ARB_vertex_buffer_object + if (array->e.buffer && array->e.buffer->data) + { + p = (unsigned char *)(array->e.buffer->data) + (uintptr_t)p; + } +#endif + + crPackEdgeFlagv(p); + } + + for (attr = 1; attr < VERT_ATTRIB_MAX; attr++) + { + if (array->a[attr].enabled) + { + crPackVertexAttrib(array, attr, index); + } + } + + if (array->a[VERT_ATTRIB_POS].enabled) + { + crPackVertexAttrib(array, VERT_ATTRIB_POS, index); + } + else if (pZva) + { + crPackVertexAttrib4fvARB(VERT_ATTRIB_POS, pZva); + } + else if (array->v.enabled) + { + p = array->v.p + index * array->v.stride; + +#ifdef CR_ARB_vertex_buffer_object + if (array->v.buffer && array->v.buffer->data) + { + p = (unsigned char *)(array->v.buffer->data) + (uintptr_t)p; + } +#endif + switch (array->v.type) + { + case GL_SHORT: + switch (c->array.v.size) + { + case 2: crPackVertex2sv((GLshort *)p); break; + case 3: crPackVertex3sv((GLshort *)p); break; + case 4: crPackVertex4sv((GLshort *)p); break; + } + break; + case GL_INT: + switch (c->array.v.size) + { + case 2: crPackVertex2iv((GLint *)p); break; + case 3: crPackVertex3iv((GLint *)p); break; + case 4: crPackVertex4iv((GLint *)p); break; + } + break; + case GL_FLOAT: + switch (c->array.v.size) + { + case 2: crPackVertex2fv((GLfloat *)p); break; + case 3: crPackVertex3fv((GLfloat *)p); break; + case 4: crPackVertex4fv((GLfloat *)p); break; + } + break; + case GL_DOUBLE: + switch (c->array.v.size) + { + case 2: crPackVertex2dv((GLdouble *)p); break; + case 3: crPackVertex3dv((GLdouble *)p); break; + case 4: crPackVertex4dv((GLdouble *)p); break; + } + break; + default: + crWarning("Unhandled: crPackExpandArrayElement, array->v.type 0x%x", array->v.type); + } + } +} + + +void +crPackExpandDrawArrays(GLenum mode, GLint first, GLsizei count, CRClientState *c, const GLfloat *pZva) +{ + int i; + + if (count < 0) + { + __PackError(__LINE__, __FILE__, GL_INVALID_VALUE, "crPackDrawArrays(negative count)"); + return; + } + + if (mode > GL_POLYGON) + { + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, "crPackDrawArrays(bad mode)"); + return; + } + + crPackBegin(mode); + for (i=0; i<count; i++) + { + crPackExpandArrayElement(first + i, c, pZva); + } + crPackEnd(); +} + +static GLsizei crPackElementsIndexSize(GLenum type) +{ + switch (type) + { + case GL_UNSIGNED_BYTE: + return sizeof(GLubyte); + case GL_UNSIGNED_SHORT: + return sizeof(GLushort); + case GL_UNSIGNED_INT: + return sizeof(GLuint); + default: + crError("Unknown type 0x%x in crPackElementsIndexSize", type); + return 0; + } +} + +void PACK_APIENTRY +crPackDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) +{ + unsigned char *data_ptr, *start_ptr; + int packet_length = sizeof(int) + sizeof(mode) + sizeof(count) + sizeof(type) + sizeof(GLuint); + GLsizei indexsize; +#ifdef CR_ARB_vertex_buffer_object + CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer; + packet_length += sizeof(GLint); + if (elementsBuffer && elementsBuffer->id) + { + /** @todo not sure it's possible, and not sure what to do*/ + if (!elementsBuffer->data) + { + crWarning("crPackDrawElements: trying to use bound but empty elements buffer, ignoring."); + return; + } + indexsize = 0; + } + else +#endif + { + indexsize = crPackElementsIndexSize(type); + } + + packet_length += count * indexsize; + + start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA_AI(GLenum, CR_DRAWELEMENTS_EXTEND_OPCODE ); + WRITE_DATA_AI(GLenum, mode ); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLenum, type); + WRITE_DATA_AI(GLuint, (GLuint) ((uintptr_t) indices) ); +#ifdef CR_ARB_vertex_buffer_object + WRITE_DATA_AI(GLint, (GLint)(indexsize>0)); +#endif + if (indexsize>0) + { + crMemcpy(data_ptr, indices, count * indexsize); + } + crHugePacket(CR_EXTEND_OPCODE, start_ptr); + crPackFree(start_ptr); +} + +void PACK_APIENTRY +crPackDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, + GLenum type, const GLvoid *indices) +{ + unsigned char *data_ptr, *start_ptr; + int packet_length = sizeof(int) + sizeof(mode) + sizeof(start) + + sizeof(end) + sizeof(count) + sizeof(type) + sizeof(GLuint); + GLsizei indexsize; + +#ifdef CR_ARB_vertex_buffer_object + CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer; + packet_length += sizeof(GLint); + if (elementsBuffer && elementsBuffer->id) + { + /** @todo not sure it's possible, and not sure what to do*/ + if (!elementsBuffer->data) + { + crWarning("crPackDrawElements: trying to use bound but empty elements buffer, ignoring."); + return; + } + indexsize = 0; + } + else +#endif + { + indexsize = crPackElementsIndexSize(type); + } + + packet_length += count * indexsize; + + start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA_AI(GLenum, CR_DRAWRANGEELEMENTS_EXTEND_OPCODE); + WRITE_DATA_AI(GLenum, mode); + WRITE_DATA_AI(GLuint, start); + WRITE_DATA_AI(GLuint, end); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLenum, type); + WRITE_DATA_AI(GLuint, (GLuint) ((uintptr_t) indices)); +#ifdef CR_ARB_vertex_buffer_object + WRITE_DATA_AI(GLint, (GLint) (indexsize>0)); +#endif + if (indexsize>0) + { + crMemcpy(data_ptr, indices, count * indexsize); + } + crHugePacket(CR_EXTEND_OPCODE, start_ptr); + crPackFree(start_ptr); +} + + +/** + * Expand glDrawElements into crPackBegin/Vertex/End, etc commands. + * Note: if mode==999, don't call glBegin/glEnd. + */ +void +crPackExpandDrawElements(GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices, CRClientState *c, const GLfloat *pZva) +{ + int i; + GLubyte *p = (GLubyte *)indices; +#ifdef CR_ARB_vertex_buffer_object + CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer; +#endif + + if (count < 0) + { + __PackError(__LINE__, __FILE__, GL_INVALID_VALUE, + "crPackDrawElements(negative count)"); + return; + } + + if (mode > GL_POLYGON && mode != 999) + { + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackDrawElements(bad mode)"); + return; + } + + if (type != GL_UNSIGNED_BYTE && + type != GL_UNSIGNED_SHORT && + type != GL_UNSIGNED_INT) + { + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackDrawElements(bad type)"); + return; + } + +#ifdef CR_ARB_vertex_buffer_object + if (elementsBuffer && elementsBuffer->data) + { + p = (unsigned char *)(elementsBuffer->data) + (uintptr_t)p; + } +#endif + + if (mode != 999) + crPackBegin(mode); + + /*crDebug("crPackExpandDrawElements mode:0x%x, count:%d, type:0x%x", mode, count, type);*/ + + switch (type) + { + case GL_UNSIGNED_BYTE: + for (i=0; i<count; i++) + { + crPackExpandArrayElement((GLint) *p++, c, pZva); + } + break; + case GL_UNSIGNED_SHORT: + for (i=0; i<count; i++) + { + crPackExpandArrayElement((GLint) * (GLushort *) p, c, pZva); + p+=sizeof (GLushort); + } + break; + case GL_UNSIGNED_INT: + for (i=0; i<count; i++) + { + crPackExpandArrayElement((GLint) * (GLuint *) p, c, pZva); + p+=sizeof (GLuint); + } + break; + default: + crError( "this can't happen: array_spu.self.DrawElements" ); + break; + } + + if (mode != 999) + crPackEnd(); +} + + +/** + * Convert a glDrawElements command into a sequence of ArrayElement() calls. + * NOTE: Caller must issue the glBegin/glEnd. + */ +void +crPackUnrollDrawElements(GLsizei count, GLenum type, + const GLvoid *indices) +{ + int i; + + switch (type) { + case GL_UNSIGNED_BYTE: + { + const GLubyte *p = (const GLubyte *) indices; + for (i = 0; i < count; i++) + crPackArrayElement(p[i]); + } + break; + case GL_UNSIGNED_SHORT: + { + const GLushort *p = (const GLushort *) indices; + for (i = 0; i < count; i++) + crPackArrayElement(p[i]); + } + break; + case GL_UNSIGNED_INT: + { + const GLuint *p = (const GLuint *) indices; + for (i = 0; i < count; i++) + crPackArrayElement(p[i]); + } + break; + default: + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackUnrollDrawElements(bad type)"); + } +} + + + +/* + * glDrawRangeElements, expanded into crPackBegin/Vertex/End/etc. + */ +void +crPackExpandDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva) +{ + if (start>end) + { + crWarning("crPackExpandDrawRangeElements start>end (%d>%d)", start, end); + return; + } + + crPackExpandDrawElements(mode, count, type, indices, c, pZva); +} + + +#ifdef CR_EXT_multi_draw_arrays +/* + * Pack real DrawArrays commands. + */ +void PACK_APIENTRY +crPackMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, + GLsizei primcount ) +{ + GLint i; + for (i = 0; i < primcount; i++) { + if (count[i] > 0) { + crPackDrawArrays(mode, first[i], count[i]); + } + } +} + + +/* + * Pack with crPackBegin/Vertex/End/etc. + */ +void +crPackExpandMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, + GLsizei primcount, CRClientState *c, const GLfloat *pZva ) +{ + GLint i; + for (i = 0; i < primcount; i++) { + if (count[i] > 0) { + crPackExpandDrawArrays(mode, first[i], count[i], c, pZva); + } + } +} + + +/* + * Pack real DrawElements commands. + */ +void PACK_APIENTRY +crPackMultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, + const GLvoid **indices, GLsizei primcount ) +{ + GLint i; + for (i = 0; i < primcount; i++) { + if (count[i] > 0) { + crPackDrawElements(mode, count[i], type, indices[i]); + } + } +} + + +/* + * Pack with crPackBegin/Vertex/End/etc. + */ +void +crPackExpandMultiDrawElementsEXT( GLenum mode, const GLsizei *count, + GLenum type, const GLvoid **indices, + GLsizei primcount, CRClientState *c, const GLfloat *pZva ) +{ + GLint i; + for (i = 0; i < primcount; i++) { + if (count[i] > 0) { + crPackExpandDrawElements(mode, count[i], type, indices[i], c, pZva); + } + } +} +#endif /* CR_EXT_multi_draw_arrays */ + +static int crPack_GetNumEnabledArrays(CRClientState *c, int *size) +{ + int i, count=0; + + *size = 0; + + if (c->array.v.enabled) + { + count++; + *size += c->array.v.bytesPerIndex; + } + + if (c->array.c.enabled) + { + count++; + *size += c->array.c.bytesPerIndex; + } + + if (c->array.f.enabled) + { + count++; + *size += c->array.f.bytesPerIndex; + } + + if (c->array.s.enabled) + { + count++; + *size += c->array.s.bytesPerIndex; + } + + if (c->array.e.enabled) + { + count++; + *size += c->array.e.bytesPerIndex; + } + + if (c->array.i.enabled) + { + count++; + *size += c->array.i.bytesPerIndex; + } + + if (c->array.n.enabled) + { + count++; + *size += c->array.n.bytesPerIndex; + } + + for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++) + { + if (c->array.t[i].enabled) + { + count++; + *size += c->array.t[i].bytesPerIndex; + } + } + + for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++) + { + if (c->array.a[i].enabled) + { + count++; + *size += c->array.a[i].bytesPerIndex; + } + } + + return count; +} + +static void crPackLockClientPointer(GLint first, GLint count, unsigned char **ppData, int index, CRClientState *c) +{ + CRClientPointer *cp; + unsigned char *data_ptr = *ppData, *cptr; + GLint i; + + cp = crStateGetClientPointerByIndex(index, &c->array); + + if (cp->enabled) + { + if (cp->buffer && cp->buffer->id) + { + crWarning("crPackLockClientPointer called when there's VBO enabled!"); + } + + WRITE_DATA_AI(int, index); + cptr = cp->p + first*cp->stride; + if (cp->bytesPerIndex==cp->stride) + { + crMemcpy(data_ptr, cptr, count*cp->bytesPerIndex); + data_ptr += count*cp->bytesPerIndex; + } + else + { + for (i=0; i<count; ++i) + { + crMemcpy(data_ptr, cptr, cp->bytesPerIndex); + data_ptr += cp->bytesPerIndex; + cptr += cp->stride; + } + } + *ppData = data_ptr; + } +} + +void PACK_APIENTRY crPackLockArraysEXT(GLint first, GLint count) +{ + CRContext *g = crStateGetCurrent(); + CRClientState *c = &g->client; + unsigned char *data_ptr, *start_ptr; + int packet_length = sizeof(int); /*extopcode*/ + int vertex_size, i, numenabled; + + packet_length += sizeof(first) + sizeof(count); /*params*/ + numenabled = crPack_GetNumEnabledArrays(c, &vertex_size); + packet_length += sizeof(int) + numenabled*sizeof(int); /*numenabled + indices*/ + packet_length += vertex_size * count; /*vertices data*/ + + start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA_AI(GLenum, CR_LOCKARRAYSEXT_EXTEND_OPCODE ); + WRITE_DATA_AI(GLint, first); + WRITE_DATA_AI(GLint, count); + WRITE_DATA_AI(int, numenabled); + for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i) + { + crPackLockClientPointer(first, count, &data_ptr, i, c); + } + crHugePacket(CR_EXTEND_OPCODE, start_ptr); + crPackFree(start_ptr); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_clipplane.c b/src/VBox/GuestHost/OpenGL/packer/pack_clipplane.c new file mode 100644 index 00000000..4ad8e040 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_clipplane.c @@ -0,0 +1,23 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" + +void PACK_APIENTRY crPackClipPlane( GLenum plane, const GLdouble *equation ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof( plane ) + 4*sizeof(*equation); + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, GLenum, plane ); + WRITE_DOUBLE( 4, equation[0] ); + WRITE_DOUBLE( 12, equation[1] ); + WRITE_DOUBLE( 20, equation[2] ); + WRITE_DOUBLE( 28, equation[3] ); + WRITE_OPCODE( pc, CR_CLIPPLANE_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_context.c b/src/VBox/GuestHost/OpenGL/packer/pack_context.c new file mode 100644 index 00000000..775a3d41 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_context.c @@ -0,0 +1,142 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_mem.h" +#include "cr_string.h" + + +/* XXX duplicated in unpack_context.c */ +#define DISPLAY_NAME_LEN 256 + +#define WRITE_BYTES( offset, data, len ) \ + crMemcpy( data_ptr + (offset), data, len ) + +void PACK_APIENTRY +crPackCreateContext( const char *dpyName, GLint visual, GLint shareCtx, + GLint *return_value, int *writeback ) +{ + char displayName[DISPLAY_NAME_LEN]; + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int len = DISPLAY_NAME_LEN + 32; + + /* clear the buffer, to silence valgrind */ + crMemZero(displayName, DISPLAY_NAME_LEN); + + if (dpyName) { + crStrncpy( displayName, dpyName, DISPLAY_NAME_LEN ); + displayName[DISPLAY_NAME_LEN - 1] = 0; + } + else { + displayName[0] = 0; + } + + CR_GET_BUFFERED_POINTER(pc, len); + WRITE_DATA( 0, GLint, len ); + WRITE_DATA( 4, GLenum, CR_CREATECONTEXT_EXTEND_OPCODE ); + WRITE_BYTES( 8, displayName, DISPLAY_NAME_LEN ); + WRITE_DATA( DISPLAY_NAME_LEN + 8, GLint, visual ); + WRITE_DATA( DISPLAY_NAME_LEN + 12, GLint, shareCtx ); + WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 16, (void *) return_value ); + WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 24, (void *) writeback ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY +crPackCreateContextSWAP( const char *dpyName, GLint visual, GLint shareCtx, + GLint *return_value, int *writeback ) +{ + char displayName[DISPLAY_NAME_LEN]; + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int len = DISPLAY_NAME_LEN + 32; + + /* clear the buffer, to silence valgrind */ + crMemZero(displayName, DISPLAY_NAME_LEN); + + if (dpyName) { + crStrncpy( displayName, dpyName, DISPLAY_NAME_LEN ); + displayName[DISPLAY_NAME_LEN - 1] = 0; + } + else { + displayName[0] = 0; + } + + CR_GET_BUFFERED_POINTER(pc, len); + WRITE_DATA( 0, GLint, SWAP32(len) ); + WRITE_DATA( 4, GLenum, SWAP32(CR_CREATECONTEXT_EXTEND_OPCODE) ); + WRITE_BYTES( 8, displayName, DISPLAY_NAME_LEN ); + WRITE_DATA( DISPLAY_NAME_LEN + 8, GLenum, SWAP32(visual) ); + WRITE_DATA( DISPLAY_NAME_LEN + 12, GLenum, SWAP32(shareCtx) ); + WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 16, (void *) return_value ); + WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 24, (void *) writeback ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void PACK_APIENTRY crPackWindowCreate( const char *dpyName, GLint visBits, GLint *return_value, int *writeback ) +{ + char displayName[DISPLAY_NAME_LEN]; + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + + /* clear the buffer, to silence valgrind */ + crMemZero(displayName, DISPLAY_NAME_LEN); + + if (dpyName) { + crStrncpy( displayName, dpyName, DISPLAY_NAME_LEN ); + displayName[DISPLAY_NAME_LEN - 1] = 0; + } + else { + displayName[0] = 0; + } + + CR_GET_BUFFERED_POINTER(pc, DISPLAY_NAME_LEN + 28 ); + WRITE_DATA( 0, GLint, 28 ); + WRITE_DATA( 4, GLenum, CR_WINDOWCREATE_EXTEND_OPCODE ); + WRITE_BYTES( 8, displayName, DISPLAY_NAME_LEN ); + WRITE_DATA( DISPLAY_NAME_LEN + 8, GLint, visBits ); + WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 12, (void *) return_value ); + WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 20, (void *) writeback ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackWindowCreateSWAP( const char *dpyName, GLint visBits, GLint *return_value, int *writeback ) +{ + char displayName[DISPLAY_NAME_LEN]; + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + + /* clear the buffer, to silence valgrind */ + crMemZero(displayName, DISPLAY_NAME_LEN); + + if (dpyName) { + crStrncpy( displayName, dpyName, DISPLAY_NAME_LEN ); + displayName[DISPLAY_NAME_LEN - 1] = 0; + } + else { + displayName[0] = 0; + } + + CR_GET_BUFFERED_POINTER(pc, DISPLAY_NAME_LEN + 28 ); + WRITE_DATA( 0, GLint, SWAP32(28) ); + WRITE_DATA( 4, GLenum, SWAP32(CR_WINDOWCREATE_EXTEND_OPCODE) ); + WRITE_BYTES( 8, displayName, DISPLAY_NAME_LEN ); + WRITE_DATA( DISPLAY_NAME_LEN + 8, GLint, SWAP32(visBits) ); + WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 12, (void *) return_value ); + WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 20, (void *) writeback ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_current.py b/src/VBox/GuestHost/OpenGL/packer/pack_current.py new file mode 100755 index 00000000..31d82f34 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_current.py @@ -0,0 +1,65 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +# This script generates the pack_current.c file. + +from __future__ import print_function +import sys +sys.path.append( "../glapi_parser" ) +import apiutil + +from pack_currenttypes import * + +apiutil.CopyrightC() + +print(""" +/* DO NOT EDIT - THIS FILE GENERATED BY THE pack_current.py SCRIPT */ + +#include <memory.h> +#include "packer.h" +#include "state/cr_currentpointers.h" + +#include <stdio.h> + +void crPackOffsetCurrentPointers( int offset ) +{ + CR_GET_PACKER_CONTEXT(pc); + GLnormal_p *normal = &(pc->current.c.normal); + GLcolor_p *color = &(pc->current.c.color); + GLsecondarycolor_p *secondaryColor = &(pc->current.c.secondaryColor); + GLtexcoord_p *texCoord = &(pc->current.c.texCoord); + GLindex_p *index = &(pc->current.c.index); + GLedgeflag_p *edgeFlag = &(pc->current.c.edgeFlag); + GLvertexattrib_p *vertexAttrib = &(pc->current.c.vertexAttrib); + GLfogcoord_p *fogCoord = &(pc->current.c.fogCoord); + int i; +""") + +for k in sorted(current_fns.keys()): + name = '%s%s' % (k[:1].lower(),k[1:]) + if 'array' in current_fns[k]: + print('\tfor (i = 0; i < %s; i++)' % current_fns[k]['array']) + print('\t{') + for type in current_fns[k]['types']: + for size in current_fns[k]['sizes']: + indent = "" + ptr = "%s->%s%d" % (name, type, size ) + if 'array' in current_fns[k]: + ptr += "[i]" + indent = "\t" + print("%s\tif (%s)" % (indent, ptr)) + print("%s\t\t%s += offset;" % (indent, ptr )) + if 'array' in current_fns[k]: + print('\t}') +print(""" +} + +void crPackNullCurrentPointers( void ) +{ + CR_GET_PACKER_CONTEXT(pc); + CRCurrentStateAttr *c = &(pc->current.c); +""") +print('\tmemset (c, 0, sizeof(CRCurrentStateAttr));') +print("}") diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_currentheader.py b/src/VBox/GuestHost/OpenGL/packer/pack_currentheader.py new file mode 100755 index 00000000..62a9912b --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_currentheader.py @@ -0,0 +1,66 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +# This script generates the include/state/cr_currentpointers.h file. + +from __future__ import print_function +import sys +sys.path.append( "../glapi_parser" ) +import apiutil + +from pack_currenttypes import * + +apiutil.CopyrightC() + +print(""" +/* DO NOT EDIT - THIS FILE GENERATED BY THE pack_currentheader.py SCRIPT */ + +#ifndef CR_CURRENT_H +#define CR_CURRENT_H + +#include "state/cr_limits.h" +""") + +sorted_keys = sorted(current_fns.keys()) + +for k in sorted_keys: + name = k.lower(); + print("typedef struct {") + if 'array' in current_fns[k]: + print("\tconst unsigned char *ptr[%s];" % current_fns[k]['array']) + else: + print("\tconst unsigned char *ptr;") + for type in current_fns[k]['types']: + for size in current_fns[k]['sizes']: + if 'array' in current_fns[k]: + print("\tconst unsigned char *%s%d[%s];" % (type, size, current_fns[k]['array'])) + else: + print("\tconst unsigned char *%s%d;" % (type, size)) + print("} GL%s_p;\n" % name) + +print("typedef struct attrs {") +for k in sorted_keys: + name = k.lower() + field = '%s%s' % (k[:1].lower(),k[1:]) + print("\tGL%s_p %s;" % (name,field)) +print(" } CRCurrentStateAttr;") + + +print("typedef struct {") +print(""" + CRCurrentStateAttr c; + unsigned char *vtx_op; + unsigned char *vtx_data; + unsigned char *begin_op; + unsigned char *begin_data; + unsigned int vtx_count; + unsigned int vtx_max; + unsigned int vtx_count_begin; + unsigned int attribsUsedMask; + unsigned int changedVertexAttrib; +} CRCurrentStatePointers; + +#endif /* CR_CURRENT_H */ +""") diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_currenttypes.py b/src/VBox/GuestHost/OpenGL/packer/pack_currenttypes.py new file mode 100644 index 00000000..5e02dc85 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_currenttypes.py @@ -0,0 +1,142 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +# This file is imported by several other Python scripts + +current_fns = { + 'Color': { + 'types': ['b','ub','s','us','i','ui','f','d'], + 'sizes': [3,4], + 'default': [0,0,0,1], + 'members': ['[0]', '[1]', '[2]', '[3]'] + }, + 'SecondaryColor': { + 'types': ['b','ub','s','us','i','ui','f','d'], + 'sizes': [3], + 'default': [0,0,0], + 'members': ['[0]', '[1]', '[2]'] + }, + 'Normal': { + 'types': ['b','s','i','f','d'], + 'sizes': [3], + 'default': [0,0,0], + 'members': ['[0]', '[1]', '[2]'] + }, + 'TexCoord': { + 'types': ['s','i','f','d'], + 'sizes': [1,2,3,4], + 'default': [0,0,0,1], + 'members': ['[0]', '[1]', '[2]', '[3]'], + 'array': 'CR_MAX_TEXTURE_UNITS' + }, + 'EdgeFlag': { + 'types': ['l'], + 'sizes': [1], + 'default': [1], + 'members': ['[0]'] + }, + 'Index': { + 'types': ['ub','s','i','f','d'], + 'sizes': [1], + 'default': [0], + 'members': ['[0]'] + }, + 'VertexAttrib': { + 'types': ['s','f','d','b','i','ub','ui','us','Nub','Nus','Nui','Nb','Ns','Ni'], + 'sizes': [1,2,3,4], + 'default': [0,0,0,1], + 'members': ['x', 'y', 'z', 'w'], + 'array': 'CR_MAX_VERTEX_ATTRIBS' + }, + 'FogCoord': { + 'types': ['f','d'], + 'sizes': [1], + 'default': [0], + 'members': [] + }, +} + +current_fns_new = { + 'VertexAttrib': { + 'types': ['s','f','d','b','i','ub','ui','us','Nub','Nus','Nui','Nb','Ns','Ni'], + 'sizes': [1,2,3,4], + 'default': [0,0,0,1], + 'members': ['x', 'y', 'z', 'w'], + 'array': 'CR_MAX_VERTEX_ATTRIBS' + }, +} + +current_vtx = { + 'Vertex': { + 'types': ['s','i','f','d'], + 'sizes': [2,3,4], + 'default': [0,0,0,1], + 'members': ['x', 'y', 'z', 'w'] + } +} + +gltypes = { + 'l': { + 'type': 'GLboolean', + 'size': 1 + }, + 'b': { + 'type': 'GLbyte', + 'size': 1 + }, + 'ub': { + 'type': 'GLubyte', + 'size': 1 + }, + 's': { + 'type': 'GLshort', + 'size': 2 + }, + 'us': { + 'type': 'GLushort', + 'size': 2 + }, + 'i': { + 'type': 'GLint', + 'size': 4 + }, + 'ui': { + 'type': 'GLuint', + 'size': 4 + }, + 'f': { + 'type': 'GLfloat', + 'size': 4 + }, + 'd': { + 'type': 'GLdouble', + 'size': 8 + }, + + 'Nb': { + 'type': 'GLbyte', + 'size': 1 + }, + 'Nub': { + 'type': 'GLubyte', + 'size': 1 + }, + 'Ns': { + 'type': 'GLshort', + 'size': 2 + }, + 'Nus': { + 'type': 'GLushort', + 'size': 2 + }, + 'Ni': { + 'type': 'GLint', + 'size': 4 + }, + 'Nui': { + 'type': 'GLuint', + 'size': 4 + } +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_error.c b/src/VBox/GuestHost/OpenGL/packer/pack_error.c new file mode 100644 index 00000000..bb189c9a --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_error.c @@ -0,0 +1,71 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved. + * + * See the file LICENSE.txt for information on redistributing this software. + */ + + +#include "cr_error.h" +#include "cr_environment.h" +#include "cr_pack.h" +#include "packer.h" + + +/* + * Set the error handler callback + */ +void crPackErrorFunction( CRPackContext *pc, CRPackErrorHandlerFunc function ) +{ + pc->Error = function; +} + + +/* + * This function is called by the packer functions when it detects and + * OpenGL error. + */ +void __PackError( int line, const char *file, GLenum error, const char *info) +{ + CR_GET_PACKER_CONTEXT(pc); + + if (pc->Error) + pc->Error( line, file, error, info ); + + if (crGetenv("CR_DEBUG")) + { + char *glerr; + + switch (error) { + case GL_NO_ERROR: + glerr = "GL_NO_ERROR"; + break; + case GL_INVALID_VALUE: + glerr = "GL_INVALID_VALUE"; + break; + case GL_INVALID_ENUM: + glerr = "GL_INVALID_ENUM"; + break; + case GL_INVALID_OPERATION: + glerr = "GL_INVALID_OPERATION"; + break; + case GL_STACK_OVERFLOW: + glerr = "GL_STACK_OVERFLOW"; + break; + case GL_STACK_UNDERFLOW: + glerr = "GL_STACK_UNDERFLOW"; + break; + case GL_OUT_OF_MEMORY: + glerr = "GL_OUT_OF_MEMORY"; + break; + case GL_TABLE_TOO_LARGE: + glerr = "GL_TABLE_TOO_LARGE"; + break; + default: + glerr = "unknown"; + break; + } + + crWarning( "GL error in packer: %s, line %d: %s: %s", + file, line, glerr, info ); + } +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_extensions.c b/src/VBox/GuestHost/OpenGL/packer/pack_extensions.c new file mode 100644 index 00000000..a8ae7fc4 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_extensions.c @@ -0,0 +1,37 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" + +int __packTexParameterNumParams( GLenum param ) +{ + switch( param ) + { +#ifdef CR_EXT_texture_filter_anisotropic + case GL_TEXTURE_MAX_ANISOTROPY_EXT: + return 1; +#endif + default: + break; + } + return 0; +} + +int __packFogParamsLength( GLenum param ) +{ + static int one_param = sizeof( GLfloat ); + (void) one_param; + switch( param ) + { +#ifdef CR_NV_fog_distance + case GL_FOG_DISTANCE_MODE_NV: + return one_param; +#endif + default: + break; + } + return 0; +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_feedback.c b/src/VBox/GuestHost/OpenGL/packer/pack_feedback.c new file mode 100644 index 00000000..159428ef --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_feedback.c @@ -0,0 +1,46 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_error.h" + +void PACK_APIENTRY crPackFeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer ) +{ + (void) size; + (void) type; + (void) buffer; + + crWarning("Packer wont pass FeedbackBuffer()\n"); + crWarning("Try using the feedbackspu\n"); +} + +void PACK_APIENTRY crPackFeedbackBufferSWAP( GLsizei size, GLenum type, GLfloat *buffer ) +{ + (void) size; + (void) type; + (void) buffer; + + crWarning("Packer wont pass FeedbackBuffer()\n"); + crWarning("Try using the feedbackspu\n"); +} + +void PACK_APIENTRY crPackSelectBuffer( GLsizei size, GLuint *buffer ) +{ + (void) size; + (void) buffer; + + crWarning("Packer wont pass SelectBuffer()\n"); + crWarning("Try using the feedbackspu\n"); +} + +void PACK_APIENTRY crPackSelectBufferSWAP( GLsizei size, GLuint *buffer ) +{ + (void) size; + (void) buffer; + + crWarning("Packer wont pass SelectBuffer()\n"); + crWarning("Try using the feedbackspu\n"); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_fence.c b/src/VBox/GuestHost/OpenGL/packer/pack_fence.c new file mode 100644 index 00000000..f42f1a06 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_fence.c @@ -0,0 +1,45 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" + +void PACK_APIENTRY +crPackDeleteFencesNV(GLsizei n, const GLuint * fences) +{ + unsigned char *data_ptr; + int packet_length = sizeof(GLenum) + sizeof(n) + n * sizeof(*fences); + + if( !fences ) + return; + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, CR_DELETEFENCESNV_EXTEND_OPCODE); + WRITE_DATA(4, GLsizei, n); + crMemcpy(data_ptr + 8, fences, n * sizeof(*fences)); + crHugePacket(CR_EXTEND_OPCODE, data_ptr); + crPackFree(data_ptr); +} + +void PACK_APIENTRY crPackDeleteFencesNVSWAP( GLsizei n, const GLuint *fences ) +{ + unsigned char *data_ptr; + int i; + int packet_length = sizeof(GLenum) + sizeof(n) + n * sizeof(*fences); + + if( !fences ) + return; + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA(0, GLenum, CR_DELETEFENCESNV_EXTEND_OPCODE); + WRITE_DATA(4, GLsizei, n); + for (i = 0 ; i < n ; i++) + { + WRITE_DATA(i*sizeof(GLuint) + 8, GLuint, SWAP32(fences[i])); + } + crHugePacket(CR_EXTEND_OPCODE, data_ptr); + crPackFree(data_ptr); +} + diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_fog.c b/src/VBox/GuestHost/OpenGL/packer/pack_fog.c new file mode 100644 index 00000000..376ef53a --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_fog.c @@ -0,0 +1,69 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" + +static GLboolean __handleFogData( GLenum pname, const GLfloat *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + int params_length = 0; + int packet_length = sizeof( int ) + sizeof( pname ); + unsigned char *data_ptr; + switch( pname ) + { + case GL_FOG_MODE: + case GL_FOG_DENSITY: + case GL_FOG_START: + case GL_FOG_END: + case GL_FOG_INDEX: + params_length = sizeof( *params ); + break; + case GL_FOG_COLOR: + params_length = 4*sizeof( *params ); + break; + default: + params_length = __packFogParamsLength( pname ); + if (!params_length) + { + char msg[100]; + sprintf(msg, "Invalid pname in Fog: %d", (int) pname ); + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, msg); + return GL_FALSE; + } + break; + } + packet_length += params_length; + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, int, packet_length ); + WRITE_DATA( 4, GLenum, pname ); + WRITE_DATA( 8, GLfloat, params[0] ); + if (packet_length > 12) + { + WRITE_DATA( 12, GLfloat, params[1] ); + WRITE_DATA( 16, GLfloat, params[2] ); + WRITE_DATA( 20, GLfloat, params[3] ); + } + return GL_TRUE; +} + +void PACK_APIENTRY crPackFogfv(GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handleFogData( pname, params )) + WRITE_OPCODE( pc, CR_FOGFV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackFogiv(GLenum pname, const GLint *params) +{ + CR_GET_PACKER_CONTEXT(pc); + /* floats and ints are the same size, so the packing should be the same */ + if (__handleFogData( pname, (const GLfloat *) params )) + WRITE_OPCODE( pc, CR_FOGIV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_framebuffer.c b/src/VBox/GuestHost/OpenGL/packer/pack_framebuffer.c new file mode 100644 index 00000000..7a578136 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_framebuffer.c @@ -0,0 +1,71 @@ +/* $Id: pack_framebuffer.c $ */ + +/** @file + * VBox OpenGL: EXT_framebuffer_object + */ + +/* + * Copyright (C) 2009-2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include "packer.h" +#include "cr_error.h" +#include "cr_string.h" + +void PACK_APIENTRY +crPackDeleteRenderbuffersEXT(GLsizei n, const GLuint * renderbuffers) +{ + unsigned char *data_ptr; + int packet_length = sizeof(GLenum) + sizeof(n) + n*sizeof(*renderbuffers); + + if (!renderbuffers) + return; + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, CR_DELETERENDERBUFFERSEXT_EXTEND_OPCODE); + WRITE_DATA(4, GLsizei, n); + crMemcpy(data_ptr + 8, renderbuffers, n* sizeof(*renderbuffers)); + crHugePacket(CR_EXTEND_OPCODE, data_ptr); + crPackFree(data_ptr); +} + +void PACK_APIENTRY +crPackDeleteFramebuffersEXT(GLsizei n, const GLuint * framebuffers) +{ + unsigned char *data_ptr; + int packet_length = sizeof(GLenum) + sizeof(n) + n*sizeof(*framebuffers); + + if (!framebuffers) + return; + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, CR_DELETEFRAMEBUFFERSEXT_EXTEND_OPCODE); + WRITE_DATA(4, GLsizei, n); + crMemcpy(data_ptr + 8, framebuffers, n* sizeof(*framebuffers)); + crHugePacket(CR_EXTEND_OPCODE, data_ptr); + crPackFree(data_ptr); +} + +void PACK_APIENTRY +crPackDeleteRenderbuffersEXTSWAP(GLsizei n, const GLuint * renderbuffers) +{ + (void) n; + (void) renderbuffers; + crError ("No swap version"); +} + +void PACK_APIENTRY +crPackDeleteFramebuffersEXTSWAP(GLsizei n, const GLuint * framebuffers) +{ + (void) n; + (void) framebuffers; + crError ("No swap version"); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_header.py b/src/VBox/GuestHost/OpenGL/packer/pack_header.py new file mode 100755 index 00000000..d86d0789 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_header.py @@ -0,0 +1,91 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +# This script generates the cr/include/cr_packfunctions.h file from the +# gl_header.parsed file. + +from __future__ import print_function +import sys +import string + +import apiutil + + +apiutil.CopyrightC() + +print("""#ifndef CR_PACKFUNCTIONS_H +#define CR_PACKFUNCTIONS_H + +/* DO NOT EDIT - THIS FILE GENERATED BY THE pack_header.py SCRIPT */ + +/* Prototypes for the OpenGL packer functions in packer.c and pack_bbox.c */ + +#include "chromium.h" +#include "state/cr_client.h" +#include "cr_pack.h" + +#ifdef WINDOWS +#define PACK_APIENTRY __stdcall +#else +#define PACK_APIENTRY +#endif + +#ifdef __cplusplus +extern "C" { +#endif +""") + +keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") + + +for func_name in keys: + if ("pack" in apiutil.ChromiumProps(func_name) or + "extpack" in apiutil.ChromiumProps(func_name) or + apiutil.NonVectorFunction(func_name) != '' or + apiutil.FindSpecial('packer', func_name)): + + # OK, generate a crPackFooBar() prototype for this function + return_type = apiutil.ReturnType(func_name) + args = apiutil.Parameters(func_name) + if return_type != 'void': + if apiutil.IsPointer(return_type): + args.append(("return_value", return_type, 0)) + else: + args.append(("return_value", return_type + "*", 0)) + elif "pixelstore" in apiutil.Properties(func_name): + args.append(("packstate", "const CRPixelPackState *", 0)) + + if "get" in apiutil.Properties(func_name): + args.append(("writeback", "int *", 0)) + + print('void PACK_APIENTRY crPack%s(%s);' % (func_name, apiutil.MakeDeclarationStringWithContext('CR_PACKER_CONTEXT', args))) + print('void PACK_APIENTRY crPack%sSWAP(%s);' % (func_name, apiutil.MakeDeclarationStringWithContext('CR_PACKER_CONTEXT', args))) + + + +# Now generate special BBOX, COUNT, SWAP variations on the glVertex and +# glVertexAttrib functions. +for func_name in keys: + if (func_name[0:6] == "Vertex" and + "pervertex" in apiutil.Properties(func_name) and + ("pack" in apiutil.ChromiumProps(func_name) or + apiutil.NonVectorFunction(func_name) != '')): + + assert apiutil.ReturnType(func_name) == "void" + + args = apiutil.Parameters(func_name) + print('void PACK_APIENTRY crPack%sBBOX(%s);' % (func_name, apiutil.MakeDeclarationString(args))) + print('void PACK_APIENTRY crPack%sBBOX_COUNT(%s);' % (func_name, apiutil.MakeDeclarationString(args))) + print('void PACK_APIENTRY crPack%sBBOXSWAP(%s);' % (func_name, apiutil.MakeDeclarationString(args))) + print('void PACK_APIENTRY crPack%sBBOX_COUNTSWAP(%s);' % (func_name, apiutil.MakeDeclarationString(args))) + + +print(""" +#ifdef __cplusplus +} +#endif + +#endif /* CR_PACKFUNCTIONS_H */ +""") diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_init.c b/src/VBox/GuestHost/OpenGL/packer/pack_init.c new file mode 100644 index 00000000..8332a5c3 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_init.c @@ -0,0 +1,74 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "cr_error.h" +#include "cr_mem.h" +#include "packer.h" +#include <stdio.h> + +#ifdef CHROMIUM_THREADSAFE +CRtsd _PackerTSD; +int cr_packer_globals; /* dummy - for the sake of packer.def */ +#else +int _PackerTSD; /* dummy - for the sake of packer.def */ /* drm1 */ +DLLDATA(CRPackContext) cr_packer_globals; +#endif + +uint32_t cr_packer_cmd_blocks_enabled = 0; + +CRPackContext *crPackNewContext( int swapping ) +{ +#ifdef CHROMIUM_THREADSAFE + CRPackContext *pc = crCalloc(sizeof(CRPackContext)); + if (!pc) + return NULL; + crInitMutex(&pc->mutex); +#else + GET_PACKER_CONTEXT(pc); + crMemZero( pc, sizeof(CRPackContext)); +#endif + pc->u32CmdBlockState = 0; + pc->swapping = swapping; + pc->Flush = NULL; + pc->SendHuge = NULL; + pc->updateBBOX = 0; + return pc; +} + +void crPackDeleteContext(CRPackContext *pc) +{ +#ifdef CHROMIUM_THREADSAFE + crFreeMutex(&pc->mutex); + crFree(pc); +#endif +} + +/* Set packing context for the calling thread */ +void crPackSetContext( CRPackContext *pc ) +{ +#ifdef CHROMIUM_THREADSAFE + crSetTSD( &_PackerTSD, pc ); +#else + CRASSERT( pc == &cr_packer_globals ); + (void)pc; +#endif +} + + +/* Return packing context for the calling thread */ +CRPackContext *crPackGetContext( void ) +{ +#ifdef CHROMIUM_THREADSAFE + return (CRPackContext *) crGetTSD( &_PackerTSD ); +#else + return &cr_packer_globals; +#endif +} + +void crPackCapsSet(uint32_t u32Caps) +{ + cr_packer_cmd_blocks_enabled = (u32Caps & (CR_VBOX_CAP_CMDBLOCKS_FLUSH | CR_VBOX_CAP_CMDBLOCKS)); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_lights.c b/src/VBox/GuestHost/OpenGL/packer/pack_lights.c new file mode 100644 index 00000000..a2c88f9e --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_lights.c @@ -0,0 +1,123 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_error.h" + +static GLboolean __handleLightData(GLenum light, GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned int packet_length = sizeof(int) + sizeof(light) + sizeof(pname); + unsigned int params_length = 0; + unsigned char *data_ptr; + switch(pname) + { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_POSITION: + params_length = 4*sizeof(*params); + break; + case GL_SPOT_DIRECTION: + params_length = 3*sizeof(*params); + break; + case GL_SPOT_EXPONENT: + case GL_SPOT_CUTOFF: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: + params_length = sizeof(*params); + break; + default: + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackLight(bad pname)"); + return GL_FALSE; + } + packet_length += params_length; + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(sizeof(int) + 0, GLenum, light); + WRITE_DATA(sizeof(int) + 4, GLenum, pname); + WRITE_DATA(sizeof(int) + 8, GLfloat, params[0]); + if (params_length > sizeof(*params)) + { + WRITE_DATA(sizeof(int) + 12, GLfloat, params[1]); + WRITE_DATA(sizeof(int) + 16, GLfloat, params[2]); + } + if (params_length > 3*sizeof(*params)) + { + WRITE_DATA(sizeof(int) + 20, GLfloat, params[3]); + } + return GL_TRUE; +} + +void PACK_APIENTRY crPackLightfv (GLenum light, GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handleLightData(light, pname, params)) + WRITE_OPCODE(pc, CR_LIGHTFV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackLightiv (GLenum light, GLenum pname, const GLint *params) +{ + /* floats and ints are the same size, so the packing should be the same */ + CR_GET_PACKER_CONTEXT(pc); + if (__handleLightData(light, pname, (const GLfloat *) params)) + WRITE_OPCODE(pc, CR_LIGHTIV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +static GLboolean __handleLightModelData(GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned int packet_length = sizeof(int) + sizeof(pname); + unsigned int params_length = 0; + unsigned char *data_ptr; + switch(pname) + { + case GL_LIGHT_MODEL_AMBIENT: + params_length = 4*sizeof(*params); + break; + case GL_LIGHT_MODEL_TWO_SIDE: + case GL_LIGHT_MODEL_LOCAL_VIEWER: + params_length = sizeof(*params); + break; + default: + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackLightModel(bad pname)"); + return GL_FALSE; + } + packet_length += params_length; + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(sizeof(int) + 0, GLenum, pname); + WRITE_DATA(sizeof(int) + 4, GLfloat, params[0]); + if (params_length > sizeof(*params)) + { + WRITE_DATA(sizeof(int) + 8, GLfloat, params[1]); + WRITE_DATA(sizeof(int) + 12, GLfloat, params[2]); + WRITE_DATA(sizeof(int) + 16, GLfloat, params[3]); + } + return GL_TRUE; +} + +void PACK_APIENTRY crPackLightModelfv (GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handleLightModelData(pname, params)) + WRITE_OPCODE(pc, CR_LIGHTMODELFV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackLightModeliv (GLenum pname, const GLint *params) +{ + /* floats and ints are the same size, so the packing should be the same */ + CR_GET_PACKER_CONTEXT(pc); + if (__handleLightModelData(pname, (const GLfloat *) params)) + WRITE_OPCODE(pc, CR_LIGHTMODELIV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_lists.c b/src/VBox/GuestHost/OpenGL/packer/pack_lists.c new file mode 100644 index 00000000..f3519014 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_lists.c @@ -0,0 +1,96 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_error.h" +#include "cr_mem.h" + +static int __gl_CallListsNumBytes( GLenum type ) +{ + switch( type ) + { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_2_BYTES: + return 1; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_3_BYTES: + return 2; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_4_BYTES: + return 4; + default: + return -1; + } +} + +void PACK_APIENTRY crPackCallLists(GLint n, GLenum type, + const GLvoid *lists ) +{ + unsigned char *data_ptr; + int packet_length; + + int num_bytes = __gl_CallListsNumBytes( type ) * n; + if (num_bytes < 0) + { + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackCallLists(bad type)" ); + return; + } + + packet_length = + sizeof( n ) + + sizeof( type ) + + num_bytes; + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLint, n ); + WRITE_DATA( 4, GLenum, type ); + crMemcpy( data_ptr + 8, lists, num_bytes ); + + crHugePacket( CR_CALLLISTS_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackNewList( GLuint list, GLenum mode ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + + if (CR_CMDBLOCK_IS_STARTED(pc, CRPACKBLOCKSTATE_OP_NEWLIST)) + { + WARN(("recursive NewList?")); + return; + } + + CR_CMDBLOCK_BEGIN( pc, CRPACKBLOCKSTATE_OP_NEWLIST ); + CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, 16, GL_FALSE ); + WRITE_DATA( 0, GLint, 16 ); + WRITE_DATA( 4, GLenum, CR_NEWLIST_EXTEND_OPCODE ); + WRITE_DATA( 8, GLuint, list ); + WRITE_DATA( 12, GLenum, mode ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + pc->buffer.in_List = GL_TRUE; + pc->buffer.holds_List = GL_TRUE; + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackEndList( void ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + CR_GET_BUFFERED_POINTER( pc, 8 ); + WRITE_DATA( 0, GLint, 8 ); + WRITE_DATA( 4, GLenum, CR_ENDLIST_EXTEND_OPCODE ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + pc->buffer.in_List = GL_FALSE; + CR_CMDBLOCK_END( pc, CRPACKBLOCKSTATE_OP_NEWLIST ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_map.c b/src/VBox/GuestHost/OpenGL/packer/pack_map.c new file mode 100644 index 00000000..67ca330b --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_map.c @@ -0,0 +1,294 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_error.h" +#include "cr_mem.h" + +/* Note -- for these packets, the ustride and vstride are implicit, + * and are computed into the packet instead of copied. + */ + +static int __gl_Map2NumComponents( GLenum target ) +{ + switch( target ) + { + case GL_MAP2_VERTEX_3: + case GL_MAP2_NORMAL: + case GL_MAP2_TEXTURE_COORD_3: + return 3; + case GL_MAP2_VERTEX_4: + case GL_MAP2_COLOR_4: + case GL_MAP2_TEXTURE_COORD_4: + case GL_MAP1_VERTEX_ATTRIB0_4_NV: + case GL_MAP1_VERTEX_ATTRIB1_4_NV: + case GL_MAP1_VERTEX_ATTRIB2_4_NV: + case GL_MAP1_VERTEX_ATTRIB3_4_NV: + case GL_MAP1_VERTEX_ATTRIB4_4_NV: + case GL_MAP1_VERTEX_ATTRIB5_4_NV: + case GL_MAP1_VERTEX_ATTRIB6_4_NV: + case GL_MAP1_VERTEX_ATTRIB7_4_NV: + case GL_MAP1_VERTEX_ATTRIB8_4_NV: + case GL_MAP1_VERTEX_ATTRIB9_4_NV: + case GL_MAP1_VERTEX_ATTRIB10_4_NV: + case GL_MAP1_VERTEX_ATTRIB11_4_NV: + case GL_MAP1_VERTEX_ATTRIB12_4_NV: + case GL_MAP1_VERTEX_ATTRIB13_4_NV: + case GL_MAP1_VERTEX_ATTRIB14_4_NV: + case GL_MAP1_VERTEX_ATTRIB15_4_NV: + case GL_MAP2_VERTEX_ATTRIB0_4_NV: + case GL_MAP2_VERTEX_ATTRIB1_4_NV: + case GL_MAP2_VERTEX_ATTRIB2_4_NV: + case GL_MAP2_VERTEX_ATTRIB3_4_NV: + case GL_MAP2_VERTEX_ATTRIB4_4_NV: + case GL_MAP2_VERTEX_ATTRIB5_4_NV: + case GL_MAP2_VERTEX_ATTRIB6_4_NV: + case GL_MAP2_VERTEX_ATTRIB7_4_NV: + case GL_MAP2_VERTEX_ATTRIB8_4_NV: + case GL_MAP2_VERTEX_ATTRIB9_4_NV: + case GL_MAP2_VERTEX_ATTRIB10_4_NV: + case GL_MAP2_VERTEX_ATTRIB11_4_NV: + case GL_MAP2_VERTEX_ATTRIB12_4_NV: + case GL_MAP2_VERTEX_ATTRIB13_4_NV: + case GL_MAP2_VERTEX_ATTRIB14_4_NV: + case GL_MAP2_VERTEX_ATTRIB15_4_NV: + return 4; + case GL_MAP2_INDEX: + case GL_MAP2_TEXTURE_COORD_1: + return 1; + case GL_MAP2_TEXTURE_COORD_2: + return 2; + default: + return -1; + } +} + +static int __gl_Map1NumComponents( GLenum target ) +{ + switch( target ) + { + case GL_MAP1_VERTEX_3: + case GL_MAP1_NORMAL: + case GL_MAP1_TEXTURE_COORD_3: + return 3; + case GL_MAP1_VERTEX_4: + case GL_MAP1_COLOR_4: + case GL_MAP1_TEXTURE_COORD_4: + return 4; + case GL_MAP1_INDEX: + case GL_MAP1_TEXTURE_COORD_1: + return 1; + case GL_MAP1_TEXTURE_COORD_2: + return 2; + default: + return -1; + } +} + +void PACK_APIENTRY crPackMap2d(GLenum target, GLdouble u1, + GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, + GLint vstride, GLint vorder, const GLdouble *points) +{ + unsigned char *data_ptr; + int u,v; + GLdouble *dest_data, *src_data; + int packet_length = + sizeof( target ) + + sizeof( u1 ) + + sizeof( u2 ) + + sizeof( uorder ) + + sizeof( ustride ) + + sizeof( v1 ) + + sizeof( v2 ) + + sizeof( vorder ) + + sizeof( vstride ); + + int num_components = __gl_Map2NumComponents( target ); + if (num_components < 0) + { + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackMap2d(bad target)" ); + return; + } + + packet_length += num_components*uorder*vorder*sizeof( *points ); + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + + WRITE_DATA( 0, GLenum, target ); + WRITE_DOUBLE( 4, u1 ); + WRITE_DOUBLE( 12, u2 ); + WRITE_DATA( 20, GLint, num_components ); + WRITE_DATA( 24, GLint, uorder ); + WRITE_DOUBLE( 28, v1 ); + WRITE_DOUBLE( 36, v2 ); + WRITE_DATA( 44, GLint, num_components*uorder ); + WRITE_DATA( 48, GLint, vorder ); + + dest_data = (GLdouble *) (data_ptr + 52); + src_data = (GLdouble *) points; + for (v = 0 ; v < vorder ; v++) + { + for (u = 0 ; u < uorder ; u++) + { + crMemcpy( dest_data, src_data, num_components * sizeof( *points ) ); + dest_data += num_components; + src_data += ustride; + } + src_data += vstride - ustride*uorder; + } + + crHugePacket( CR_MAP2D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackMap2f(GLenum target, GLfloat u1, + GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, + GLint vstride, GLint vorder, const GLfloat *points) +{ + unsigned char *data_ptr; + int u,v; + GLfloat *dest_data, *src_data; + int packet_length = + sizeof( target ) + + sizeof( u1 ) + + sizeof( u2 ) + + sizeof( uorder ) + + sizeof( ustride ) + + sizeof( v1 ) + + sizeof( v2 ) + + sizeof( vorder ) + + sizeof( vstride ); + + int num_components = __gl_Map2NumComponents( target ); + if (num_components < 0) + { + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackMap2f(bad target)" ); + return; + } + + packet_length += num_components*uorder*vorder*sizeof( *points ); + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + + WRITE_DATA( 0, GLenum, target ); + WRITE_DATA( 4, GLfloat, u1 ); + WRITE_DATA( 8, GLfloat, u2 ); + WRITE_DATA( 12, GLint, num_components ); + WRITE_DATA( 16, GLint, uorder ); + WRITE_DATA( 20, GLfloat, v1 ); + WRITE_DATA( 24, GLfloat, v2 ); + WRITE_DATA( 28, GLint, num_components*uorder ); + WRITE_DATA( 32, GLint, vorder ); + + dest_data = (GLfloat *) (data_ptr + 36); + src_data = (GLfloat *) points; + for (v = 0 ; v < vorder ; v++) + { + for (u = 0 ; u < uorder ; u++) + { + crMemcpy( dest_data, src_data, num_components * sizeof( *points ) ); + dest_data += num_components; + src_data += ustride; + } + src_data += vstride - ustride*uorder; + } + + crHugePacket( CR_MAP2F_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackMap1d( GLenum target, GLdouble u1, + GLdouble u2, GLint stride, GLint order, const GLdouble *points ) +{ + unsigned char *data_ptr; + int packet_length = + sizeof( target ) + + sizeof( u1 ) + + sizeof( u2 ) + + sizeof( stride ) + + sizeof( order ); + + int num_components = __gl_Map1NumComponents( target ); + GLdouble *src_data, *dest_data; + int u; + + if (num_components < 0) + { + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackMap1d(bad target)" ); + return; + } + + packet_length += num_components * order * sizeof( *points ); + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + + WRITE_DATA( 0, GLenum, target ); + WRITE_DOUBLE( 4, u1 ); + WRITE_DOUBLE( 12, u2 ); + WRITE_DATA( 20, GLint, num_components ); + WRITE_DATA( 24, GLint, order ); + + dest_data = (GLdouble *) (data_ptr + 28); + src_data = (GLdouble *) points; + for (u = 0 ; u < order ; u++) + { + crMemcpy( dest_data, src_data, num_components * sizeof( *points ) ); + dest_data += num_components; + src_data += stride; + } + + crHugePacket( CR_MAP1D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackMap1f( GLenum target, GLfloat u1, + GLfloat u2, GLint stride, GLint order, const GLfloat *points ) +{ + unsigned char *data_ptr; + int packet_length = + sizeof( target ) + + sizeof( u1 ) + + sizeof( u2 ) + + sizeof( stride ) + + sizeof( order ); + + int num_components = __gl_Map1NumComponents( target ); + GLfloat *src_data, *dest_data; + int u; + + if (num_components < 0) + { + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackMap1f(bad target)" ); + return; + } + + packet_length += num_components * order * sizeof( *points ); + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + + WRITE_DATA( 0, GLenum, target ); + WRITE_DATA( 4, GLfloat, u1 ); + WRITE_DATA( 8, GLfloat, u2 ); + WRITE_DATA( 12, GLint, num_components ); + WRITE_DATA( 16, GLint, order ); + + dest_data = (GLfloat *) (data_ptr + 20); + src_data = (GLfloat *) points; + for (u = 0 ; u < order ; u++) + { + crMemcpy( dest_data, src_data, num_components * sizeof( *points ) ); + dest_data += num_components; + src_data += stride; + } + + crHugePacket( CR_MAP1F_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_materials.c b/src/VBox/GuestHost/OpenGL/packer/pack_materials.c new file mode 100644 index 00000000..e7a027d4 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_materials.c @@ -0,0 +1,68 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_error.h" + +static void __handleMaterialData( GLenum face, GLenum pname, const GLfloat *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned int packet_length = sizeof( int ) + sizeof( face ) + sizeof( pname ); + unsigned int params_length = 0; + unsigned char *data_ptr; + switch( pname ) + { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_EMISSION: + case GL_AMBIENT_AND_DIFFUSE: + params_length = 4*sizeof( *params ); + break; + case GL_COLOR_INDEXES: + params_length = 3*sizeof( *params ); + break; + case GL_SHININESS: + params_length = sizeof( *params ); + break; + default: + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMaterial(pname)"); + return; + } + packet_length += params_length; + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, int, packet_length ); + WRITE_DATA( sizeof( int ) + 0, GLenum, face ); + WRITE_DATA( sizeof( int ) + 4, GLenum, pname ); + WRITE_DATA( sizeof( int ) + 8, GLfloat, params[0] ); + if (params_length > sizeof( *params )) + { + WRITE_DATA( sizeof( int ) + 12, GLfloat, params[1] ); + WRITE_DATA( sizeof( int ) + 16, GLfloat, params[2] ); + } + if (packet_length > 3*sizeof( *params ) ) + { + WRITE_DATA( sizeof( int ) + 20, GLfloat, params[3] ); + } +} + +void PACK_APIENTRY crPackMaterialfv(GLenum face, GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleMaterialData( face, pname, params ); + WRITE_OPCODE( pc, CR_MATERIALFV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackMaterialiv(GLenum face, GLenum pname, const GLint *params) +{ + /* floats and ints are the same size, so the packing should be the same */ + CR_GET_PACKER_CONTEXT(pc); + __handleMaterialData( face, pname, (const GLfloat *) params ); + WRITE_OPCODE( pc, CR_MATERIALIV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_matrices.c b/src/VBox/GuestHost/OpenGL/packer/pack_matrices.c new file mode 100644 index 00000000..b16857ae --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_matrices.c @@ -0,0 +1,224 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" + +void PACK_APIENTRY crPackMultMatrixd(const GLdouble *m) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16*sizeof(*m); + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DOUBLE(0*sizeof(double), m[ 0]); + WRITE_DOUBLE(1*sizeof(double), m[ 1]); + WRITE_DOUBLE(2*sizeof(double), m[ 2]); + WRITE_DOUBLE(3*sizeof(double), m[ 3]); + WRITE_DOUBLE(4*sizeof(double), m[ 4]); + WRITE_DOUBLE(5*sizeof(double), m[ 5]); + WRITE_DOUBLE(6*sizeof(double), m[ 6]); + WRITE_DOUBLE(7*sizeof(double), m[ 7]); + WRITE_DOUBLE(8*sizeof(double), m[ 8]); + WRITE_DOUBLE(9*sizeof(double), m[ 9]); + WRITE_DOUBLE(10*sizeof(double), m[10]); + WRITE_DOUBLE(11*sizeof(double), m[11]); + WRITE_DOUBLE(12*sizeof(double), m[12]); + WRITE_DOUBLE(13*sizeof(double), m[13]); + WRITE_DOUBLE(14*sizeof(double), m[14]); + WRITE_DOUBLE(15*sizeof(double), m[15]); + WRITE_OPCODE(pc, CR_MULTMATRIXD_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackMultMatrixf(const GLfloat *m) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16*sizeof(*m); + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0*sizeof(GLfloat), GLfloat, m[ 0]); + WRITE_DATA(1*sizeof(GLfloat), GLfloat, m[ 1]); + WRITE_DATA(2*sizeof(GLfloat), GLfloat, m[ 2]); + WRITE_DATA(3*sizeof(GLfloat), GLfloat, m[ 3]); + WRITE_DATA(4*sizeof(GLfloat), GLfloat, m[ 4]); + WRITE_DATA(5*sizeof(GLfloat), GLfloat, m[ 5]); + WRITE_DATA(6*sizeof(GLfloat), GLfloat, m[ 6]); + WRITE_DATA(7*sizeof(GLfloat), GLfloat, m[ 7]); + WRITE_DATA(8*sizeof(GLfloat), GLfloat, m[ 8]); + WRITE_DATA(9*sizeof(GLfloat), GLfloat, m[ 9]); + WRITE_DATA(10*sizeof(GLfloat), GLfloat, m[10]); + WRITE_DATA(11*sizeof(GLfloat), GLfloat, m[11]); + WRITE_DATA(12*sizeof(GLfloat), GLfloat, m[12]); + WRITE_DATA(13*sizeof(GLfloat), GLfloat, m[13]); + WRITE_DATA(14*sizeof(GLfloat), GLfloat, m[14]); + WRITE_DATA(15*sizeof(GLfloat), GLfloat, m[15]); + WRITE_OPCODE(pc, CR_MULTMATRIXF_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackLoadMatrixd(const GLdouble *m) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16*sizeof(*m); + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DOUBLE(0*sizeof(double), m[ 0]); + WRITE_DOUBLE(1*sizeof(double), m[ 1]); + WRITE_DOUBLE(2*sizeof(double), m[ 2]); + WRITE_DOUBLE(3*sizeof(double), m[ 3]); + WRITE_DOUBLE(4*sizeof(double), m[ 4]); + WRITE_DOUBLE(5*sizeof(double), m[ 5]); + WRITE_DOUBLE(6*sizeof(double), m[ 6]); + WRITE_DOUBLE(7*sizeof(double), m[ 7]); + WRITE_DOUBLE(8*sizeof(double), m[ 8]); + WRITE_DOUBLE(9*sizeof(double), m[ 9]); + WRITE_DOUBLE(10*sizeof(double), m[10]); + WRITE_DOUBLE(11*sizeof(double), m[11]); + WRITE_DOUBLE(12*sizeof(double), m[12]); + WRITE_DOUBLE(13*sizeof(double), m[13]); + WRITE_DOUBLE(14*sizeof(double), m[14]); + WRITE_DOUBLE(15*sizeof(double), m[15]); + WRITE_OPCODE(pc, CR_LOADMATRIXD_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackLoadMatrixf(const GLfloat *m) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16*sizeof(*m); + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0*sizeof(GLfloat), GLfloat, m[ 0]); + WRITE_DATA(1*sizeof(GLfloat), GLfloat, m[ 1]); + WRITE_DATA(2*sizeof(GLfloat), GLfloat, m[ 2]); + WRITE_DATA(3*sizeof(GLfloat), GLfloat, m[ 3]); + WRITE_DATA(4*sizeof(GLfloat), GLfloat, m[ 4]); + WRITE_DATA(5*sizeof(GLfloat), GLfloat, m[ 5]); + WRITE_DATA(6*sizeof(GLfloat), GLfloat, m[ 6]); + WRITE_DATA(7*sizeof(GLfloat), GLfloat, m[ 7]); + WRITE_DATA(8*sizeof(GLfloat), GLfloat, m[ 8]); + WRITE_DATA(9*sizeof(GLfloat), GLfloat, m[ 9]); + WRITE_DATA(10*sizeof(GLfloat), GLfloat, m[10]); + WRITE_DATA(11*sizeof(GLfloat), GLfloat, m[11]); + WRITE_DATA(12*sizeof(GLfloat), GLfloat, m[12]); + WRITE_DATA(13*sizeof(GLfloat), GLfloat, m[13]); + WRITE_DATA(14*sizeof(GLfloat), GLfloat, m[14]); + WRITE_DATA(15*sizeof(GLfloat), GLfloat, m[15]); + WRITE_OPCODE(pc, CR_LOADMATRIXF_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackMultTransposeMatrixdARB(const GLdouble *m) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16*sizeof(*m) + sizeof(GLint) + sizeof(GLenum); + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, GLint, packet_length); + WRITE_DATA(4, GLenum, CR_MULTTRANSPOSEMATRIXDARB_EXTEND_OPCODE); + WRITE_DOUBLE(8 + 0*sizeof(double), m[ 0]); + WRITE_DOUBLE(8 + 1*sizeof(double), m[ 1]); + WRITE_DOUBLE(8 + 2*sizeof(double), m[ 2]); + WRITE_DOUBLE(8 + 3*sizeof(double), m[ 3]); + WRITE_DOUBLE(8 + 4*sizeof(double), m[ 4]); + WRITE_DOUBLE(8 + 5*sizeof(double), m[ 5]); + WRITE_DOUBLE(8 + 6*sizeof(double), m[ 6]); + WRITE_DOUBLE(8 + 7*sizeof(double), m[ 7]); + WRITE_DOUBLE(8 + 8*sizeof(double), m[ 8]); + WRITE_DOUBLE(8 + 9*sizeof(double), m[ 9]); + WRITE_DOUBLE(8 + 10*sizeof(double), m[10]); + WRITE_DOUBLE(8 + 11*sizeof(double), m[11]); + WRITE_DOUBLE(8 + 12*sizeof(double), m[12]); + WRITE_DOUBLE(8 + 13*sizeof(double), m[13]); + WRITE_DOUBLE(8 + 14*sizeof(double), m[14]); + WRITE_DOUBLE(8 + 15*sizeof(double), m[15]); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackMultTransposeMatrixfARB(const GLfloat *m) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16*sizeof(*m) + sizeof(GLint) + sizeof(GLenum); + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, GLint, packet_length); + WRITE_DATA(4, GLenum, CR_MULTTRANSPOSEMATRIXFARB_EXTEND_OPCODE); + WRITE_DATA(8 + 0*sizeof(GLfloat), GLfloat, m[ 0]); + WRITE_DATA(8 + 1*sizeof(GLfloat), GLfloat, m[ 1]); + WRITE_DATA(8 + 2*sizeof(GLfloat), GLfloat, m[ 2]); + WRITE_DATA(8 + 3*sizeof(GLfloat), GLfloat, m[ 3]); + WRITE_DATA(8 + 4*sizeof(GLfloat), GLfloat, m[ 4]); + WRITE_DATA(8 + 5*sizeof(GLfloat), GLfloat, m[ 5]); + WRITE_DATA(8 + 6*sizeof(GLfloat), GLfloat, m[ 6]); + WRITE_DATA(8 + 7*sizeof(GLfloat), GLfloat, m[ 7]); + WRITE_DATA(8 + 8*sizeof(GLfloat), GLfloat, m[ 8]); + WRITE_DATA(8 + 9*sizeof(GLfloat), GLfloat, m[ 9]); + WRITE_DATA(8 + 10*sizeof(GLfloat), GLfloat, m[10]); + WRITE_DATA(8 + 11*sizeof(GLfloat), GLfloat, m[11]); + WRITE_DATA(8 + 12*sizeof(GLfloat), GLfloat, m[12]); + WRITE_DATA(8 + 13*sizeof(GLfloat), GLfloat, m[13]); + WRITE_DATA(8 + 14*sizeof(GLfloat), GLfloat, m[14]); + WRITE_DATA(8 + 15*sizeof(GLfloat), GLfloat, m[15]); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackLoadTransposeMatrixdARB(const GLdouble *m) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16*sizeof(*m) + sizeof(GLint) + sizeof(GLenum); + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, GLint, packet_length); + WRITE_DATA(4, GLenum, CR_LOADTRANSPOSEMATRIXDARB_EXTEND_OPCODE); + WRITE_DOUBLE(8 + 0*sizeof(double), m[ 0]); + WRITE_DOUBLE(8 + 1*sizeof(double), m[ 1]); + WRITE_DOUBLE(8 + 2*sizeof(double), m[ 2]); + WRITE_DOUBLE(8 + 3*sizeof(double), m[ 3]); + WRITE_DOUBLE(8 + 4*sizeof(double), m[ 4]); + WRITE_DOUBLE(8 + 5*sizeof(double), m[ 5]); + WRITE_DOUBLE(8 + 6*sizeof(double), m[ 6]); + WRITE_DOUBLE(8 + 7*sizeof(double), m[ 7]); + WRITE_DOUBLE(8 + 8*sizeof(double), m[ 8]); + WRITE_DOUBLE(8 + 9*sizeof(double), m[ 9]); + WRITE_DOUBLE(8 + 10*sizeof(double), m[10]); + WRITE_DOUBLE(8 + 11*sizeof(double), m[11]); + WRITE_DOUBLE(8 + 12*sizeof(double), m[12]); + WRITE_DOUBLE(8 + 13*sizeof(double), m[13]); + WRITE_DOUBLE(8 + 14*sizeof(double), m[14]); + WRITE_DOUBLE(8 + 15*sizeof(double), m[15]); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackLoadTransposeMatrixfARB(const GLfloat *m) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = 16*sizeof(*m) + sizeof(GLint) + sizeof(GLenum); + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, GLint, packet_length); + WRITE_DATA(4, GLenum, CR_LOADTRANSPOSEMATRIXFARB_EXTEND_OPCODE); + WRITE_DATA(8 + 0*sizeof(GLfloat), GLfloat, m[ 0]); + WRITE_DATA(8 + 1*sizeof(GLfloat), GLfloat, m[ 1]); + WRITE_DATA(8 + 2*sizeof(GLfloat), GLfloat, m[ 2]); + WRITE_DATA(8 + 3*sizeof(GLfloat), GLfloat, m[ 3]); + WRITE_DATA(8 + 4*sizeof(GLfloat), GLfloat, m[ 4]); + WRITE_DATA(8 + 5*sizeof(GLfloat), GLfloat, m[ 5]); + WRITE_DATA(8 + 6*sizeof(GLfloat), GLfloat, m[ 6]); + WRITE_DATA(8 + 7*sizeof(GLfloat), GLfloat, m[ 7]); + WRITE_DATA(8 + 8*sizeof(GLfloat), GLfloat, m[ 8]); + WRITE_DATA(8 + 9*sizeof(GLfloat), GLfloat, m[ 9]); + WRITE_DATA(8 + 10*sizeof(GLfloat), GLfloat, m[10]); + WRITE_DATA(8 + 11*sizeof(GLfloat), GLfloat, m[11]); + WRITE_DATA(8 + 12*sizeof(GLfloat), GLfloat, m[12]); + WRITE_DATA(8 + 13*sizeof(GLfloat), GLfloat, m[13]); + WRITE_DATA(8 + 14*sizeof(GLfloat), GLfloat, m[14]); + WRITE_DATA(8 + 15*sizeof(GLfloat), GLfloat, m[15]); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_misc.c b/src/VBox/GuestHost/OpenGL/packer/pack_misc.c new file mode 100644 index 00000000..17d643cc --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_misc.c @@ -0,0 +1,216 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_error.h" + +void PACK_APIENTRY crPackChromiumParametervCR(CR_PACKER_CONTEXT_ARGDECL GLenum target, GLenum type, GLsizei count, const GLvoid *values) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned int header_length = 2 * sizeof(int) + sizeof(target) + sizeof(type) + sizeof(count); + unsigned int packet_length; + unsigned int params_length = 0; + unsigned char *data_ptr; + int i, pos; + + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + params_length = sizeof(GLbyte) * count; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + params_length = sizeof(GLshort) * count; + break; + case GL_INT: + case GL_UNSIGNED_INT: + params_length = sizeof(GLint) * count; + break; +#ifndef IN_RING0 + case GL_FLOAT: + params_length = sizeof(GLfloat) * count; + break; +#endif +#if 0 + case GL_DOUBLE: + params_length = sizeof(GLdouble) * count; + break; +#endif + default: + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackChromiumParametervCR(bad type)" ); + return; + } + + packet_length = header_length + params_length; + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_CHROMIUMPARAMETERVCR_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, target ); + WRITE_DATA( 12, GLenum, type ); + WRITE_DATA( 16, GLsizei, count ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + + pos = header_length; + + switch (type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + for (i = 0; i < count; i++, pos += sizeof(GLbyte)) { + WRITE_DATA( pos, GLbyte, ((GLbyte *) values)[i]); + } + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + for (i = 0; i < count; i++, pos += sizeof(GLshort)) { + WRITE_DATA( pos, GLshort, ((GLshort *) values)[i]); + } + break; + case GL_INT: + case GL_UNSIGNED_INT: + for (i = 0; i < count; i++, pos += sizeof(GLint)) { + WRITE_DATA( pos, GLint, ((GLint *) values)[i]); + } + break; +#ifndef IN_RING0 + case GL_FLOAT: + for (i = 0; i < count; i++, pos += sizeof(GLfloat)) { + WRITE_DATA( pos, GLfloat, ((GLfloat *) values)[i]); + } + break; +#endif +#if 0 + case GL_DOUBLE: + for (i = 0; i < count; i++) { + WRITE_foo_DATA( sizeof(int) + 12, GLdouble, ((GLdouble *) values)[i]); + } + break; +#endif + default: + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackChromiumParametervCR(bad type)" ); + CR_UNLOCK_PACKER_CONTEXT(pc); + return; + } + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +#ifndef IN_RING0 +void PACK_APIENTRY crPackDeleteQueriesARB(CR_PACKER_CONTEXT_ARGDECL GLsizei n, const GLuint * ids) +{ + unsigned char *data_ptr; + int packet_length = sizeof(GLenum)+sizeof(n)+n*sizeof(*ids); + if (!ids) return; + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, CR_DELETEQUERIESARB_EXTEND_OPCODE); + WRITE_DATA(4, GLsizei, n); + crMemcpy(data_ptr + 8, ids, n*sizeof(*ids)); + crHugePacket(CR_EXTEND_OPCODE, data_ptr); + crPackFree(data_ptr); +} +#endif + +void PACK_APIENTRY crPackVBoxTexPresent( CR_PACKER_CONTEXT_ARGDECL GLuint texture, GLuint cfg, GLint xPos, GLint yPos, GLint cRects, const GLint * pRects ) +{ + GLint i, size, cnt; + + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + size = 28 + cRects * 4 * sizeof(GLint); + CR_GET_BUFFERED_POINTER( pc, size ); + WRITE_DATA( 0, GLint, size ); + WRITE_DATA( 4, GLenum, CR_VBOXTEXPRESENT_EXTEND_OPCODE ); + WRITE_DATA( 8, GLuint, texture ); + WRITE_DATA( 12, GLuint, cfg ); + WRITE_DATA( 16, GLint, xPos ); + WRITE_DATA( 20, GLint, yPos ); + WRITE_DATA( 24, GLint, cRects ); + + cnt = 28; + for (i=0; i<cRects; ++i) + { + WRITE_DATA(cnt, GLint, (GLint) pRects[4*i+0]); + WRITE_DATA(cnt+4, GLint, (GLint) pRects[4*i+1]); + WRITE_DATA(cnt+8, GLint, (GLint) pRects[4*i+2]); + WRITE_DATA(cnt+12, GLint, (GLint) pRects[4*i+3]); + cnt += 16; + } + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackWindowPosition( CR_PACKER_CONTEXT_ARGDECL GLint window, GLint x, GLint y ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER( pc, 20 ); + WRITE_DATA( 0, GLint, 20 ); + WRITE_DATA( 4, GLenum, CR_WINDOWPOSITION_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, window ); + WRITE_DATA( 12, GLint, x ); + WRITE_DATA( 16, GLint, y ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackWindowShow( CR_PACKER_CONTEXT_ARGDECL GLint window, GLint flag ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER( pc, 16 ); + WRITE_DATA( 0, GLint, 16 ); + WRITE_DATA( 4, GLenum, CR_WINDOWSHOW_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, window ); + WRITE_DATA( 12, GLint, flag ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackWindowSize( CR_PACKER_CONTEXT_ARGDECL GLint window, GLint w, GLint h ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER( pc, 20 ); + WRITE_DATA( 0, GLint, 20 ); + WRITE_DATA( 4, GLenum, CR_WINDOWSIZE_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, window ); + WRITE_DATA( 12, GLint, w ); + WRITE_DATA( 16, GLint, h ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackBeginQueryARB( CR_PACKER_CONTEXT_ARGDECL GLenum target, GLuint id ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER( pc, 16 ); + WRITE_DATA( 0, GLint, 16 ); + WRITE_DATA( 4, GLenum, CR_BEGINQUERYARB_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, target ); + WRITE_DATA( 12, GLuint, id ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackEndQueryARB( CR_PACKER_CONTEXT_ARGDECL GLenum target ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER( pc, 12 ); + WRITE_DATA( 0, GLint, 12 ); + WRITE_DATA( 4, GLenum, CR_ENDQUERYARB_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, target ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_pica.c b/src/VBox/GuestHost/OpenGL/packer/pack_pica.c new file mode 100644 index 00000000..0319d967 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_pica.c @@ -0,0 +1,650 @@ +/* Copyright (c) 2003, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_error.h" +#include "cr_string.h" + +void PACK_APIENTRY crPackPicaListCompositors(const PICAuint *config, + PICAint *numResults, + PICAcompItem *results, PICAerror *return_value, int* writeback ) +{ + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) config; + (void) numResults; + (void) results; + (void) writeback; +} +void PACK_APIENTRY crPackPicaListCompositorsSWAP(const PICAuint *config, + PICAint *numResults, + PICAcompItem *results, PICAerror *return_value, int* writeback ) +{ + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) config; + (void) numResults; + (void) results; + (void) writeback; +} +void PACK_APIENTRY crPackPicaGetCompositorParamiv(PICAcompID compositor, + PICAparam pname, + PICAint *params, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) compositor; + (void) pname; + (void) params; +} +void PACK_APIENTRY crPackPicaGetCompositorParamivSWAP(PICAcompID compositor, + PICAparam pname, + PICAint *params, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) compositor; + (void) pname; + (void) params; +} +void PACK_APIENTRY crPackPicaGetCompositorParamfv(PICAcompID compositor, + PICAparam pname, + PICAfloat *params, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) compositor; + (void) pname; + (void) params; +} +void PACK_APIENTRY crPackPicaGetCompositorParamfvSWAP(PICAcompID compositor, + PICAparam pname, + PICAfloat *params, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) compositor; + (void) pname; + (void) params; +} +void PACK_APIENTRY crPackPicaGetCompositorParamcv(PICAcompID compositor, + PICAparam pname, + PICAchar **params, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) compositor; + (void) pname; + (void) params; +} +void PACK_APIENTRY crPackPicaGetCompositorParamcvSWAP(PICAcompID compositor, + PICAparam pname, + PICAchar **params, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) compositor; + (void) pname; + (void) params; +} +void PACK_APIENTRY crPackPicaListNodes(PICAcompID compositor, + PICAint *num, + PICAnodeItem *results, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) compositor; + (void) num; + (void) results; +} +void PACK_APIENTRY crPackPicaListNodesSWAP(PICAcompID compositor, + PICAint *num, + PICAnodeItem *results, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) compositor; + (void) num; + (void) results; +} + +void PACK_APIENTRY crPackPicaCreateContext(const PICAuint *config, + const PICAnodeID *nodes, + PICAuint numNodes, PICAcontextID *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = (PICAcontextID) -1; + (void) writeback; + (void) config; + (void) nodes; + (void) numNodes; +} +void PACK_APIENTRY crPackPicaCreateContextSWAP(const PICAuint *config, + const PICAnodeID *nodes, + PICAuint numNodes, PICAcontextID *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = (PICAcontextID) -1; + (void) writeback; + (void) config; + (void) nodes; + (void) numNodes; +} +void PACK_APIENTRY crPackPicaDestroyContext(PICAcontextID ctx, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; +} +void PACK_APIENTRY crPackPicaDestroyContextSWAP(PICAcontextID ctx, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; +} + +void PACK_APIENTRY crPackPicaSetContextParami(PICAcontextID ctx, + PICAparam pname, + PICAint param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamiSWAP(PICAcontextID ctx, + PICAparam pname, + PICAint param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamiv(PICAcontextID ctx, + PICAparam pname, + const PICAint *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamivSWAP(PICAcontextID ctx, + PICAparam pname, + const PICAint *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamf(PICAcontextID ctx, + PICAparam pname, + PICAfloat param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamfSWAP(PICAcontextID ctx, + PICAparam pname, + PICAfloat param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamfv(PICAcontextID ctx, + PICAparam pname, + const PICAfloat *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamfvSWAP(PICAcontextID ctx, + PICAparam pname, + const PICAfloat *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamv(PICAcontextID ctx, + PICAparam pname, + const PICAvoid *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaSetContextParamvSWAP(PICAcontextID ctx, + PICAparam pname, + const PICAvoid *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} + +void PACK_APIENTRY crPackPicaGetContextParamiv(PICAcontextID ctx, + PICAparam pname, + PICAint *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} + +void PACK_APIENTRY crPackPicaGetContextParamivSWAP(PICAcontextID ctx, + PICAparam pname, + PICAint *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaGetContextParamfv(PICAcontextID ctx, + PICAparam pname, + PICAfloat *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaGetContextParamfvSWAP(PICAcontextID ctx, + PICAparam pname, + PICAfloat *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaGetContextParamcv(PICAcontextID ctx, + PICAparam pname, + PICAchar **param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaGetContextParamcvSWAP(PICAcontextID ctx, + PICAparam pname, + PICAchar **param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaGetContextParamv(PICAcontextID ctx, + PICAparam pname, + PICAvoid *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} +void PACK_APIENTRY crPackPicaGetContextParamvSWAP(PICAcontextID ctx, + PICAparam pname, + PICAvoid *param, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) pname; + (void) param; +} + +void PACK_APIENTRY crPackPicaBindLocalContext(PICAcontextID globalCtx, + PICAnodeID node, PICAcontextID *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = (PICAcontextID) -1; + (void) writeback; + (void) globalCtx; + (void) node; +} + +void PACK_APIENTRY crPackPicaBindLocalContextSWAP(PICAcontextID globalCtx, + PICAnodeID node, PICAcontextID *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = (PICAcontextID) -1; + (void) writeback; + (void) globalCtx; + (void) node; +} +void PACK_APIENTRY crPackPicaDestroyLocalContext(PICAcontextID lctx, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) lctx; +} +void PACK_APIENTRY crPackPicaDestroyLocalContextSWAP(PICAcontextID lctx, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) lctx; +} + +void PACK_APIENTRY crPackPicaStartFrame(PICAcontextID lctx, + const PICAframeID *frameID, + PICAuint numLocalFramelets, + PICAuint numOrders, + const PICAuint *orderList, + const PICArect *srcRectList, + const PICApoint *dstList, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) lctx; + (void) frameID; + (void) numLocalFramelets; + (void) numOrders; + (void) orderList; + (void) srcRectList; + (void) dstList; +} + +void PACK_APIENTRY crPackPicaStartFrameSWAP(PICAcontextID lctx, + const PICAframeID *frameID, + PICAuint numLocalFramelets, + PICAuint numOrders, + const PICAuint *orderList, + const PICArect *srcRectList, + const PICApoint *dstList, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) lctx; + (void) frameID; + (void) numLocalFramelets; + (void) numOrders; + (void) orderList; + (void) srcRectList; + (void) dstList; +} +void PACK_APIENTRY crPackPicaEndFrame(PICAcontextID lctx, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) lctx; +} +void PACK_APIENTRY crPackPicaEndFrameSWAP(PICAcontextID lctx, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) lctx; +} +void PACK_APIENTRY crPackPicaCancelFrame(PICAcontextID ctx, + PICAframeID frameID, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) frameID; +} +void PACK_APIENTRY crPackPicaCancelFrameSWAP(PICAcontextID ctx, + PICAframeID frameID, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) ctx; + (void) frameID; +} +void PACK_APIENTRY crPackPicaQueryFrame(PICAcontextID ctx, + PICAframeID frameID, + PICAnodeID nodeID, + PICAfloat timeout, PICAstatus *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) ctx; + (void) writeback; + (void) frameID; + (void) nodeID; + (void) timeout; +} +void PACK_APIENTRY crPackPicaQueryFrameSWAP(PICAcontextID ctx, + PICAframeID frameID, + PICAnodeID nodeID, + PICAfloat timeout, PICAstatus *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) ctx; + (void) writeback; + (void) frameID; + (void) nodeID; + (void) timeout; +} +void PACK_APIENTRY crPackPicaAddGfxFramelet(PICAcontextID lctx, + const PICArect *srcRect, + const PICApoint *dstPos, + PICAuint order, + PICAint iVolatile, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) lctx; + (void) writeback; + (void) srcRect; + (void) dstPos; + (void) order; + (void) iVolatile; +} +void PACK_APIENTRY crPackPicaAddGfxFrameletSWAP(PICAcontextID lctx, + const PICArect *srcRect, + const PICApoint *dstPos, + PICAuint order, + PICAint iVolatile, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) lctx; + (void) writeback; + (void) srcRect; + (void) dstPos; + (void) order; + (void) iVolatile; +} +void PACK_APIENTRY crPackPicaAddMemFramelet(PICAcontextID lctx, + const PICAvoid *colorBuffer, + const PICAvoid *depthBuffer, + PICAuint span_x, + const PICArect *srcRect, + const PICApoint *dstPos, + PICAuint order, + PICAint iVolatile, PICAerror *return_value, int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) lctx; + (void) writeback; + (void) colorBuffer; + (void) depthBuffer; + (void) span_x; + (void) srcRect; + (void) dstPos; + (void) order; + (void) iVolatile; +} +void PACK_APIENTRY crPackPicaAddMemFrameletSWAP(PICAcontextID lctx, + const PICAvoid *colorBuffer, + const PICAvoid *depthBuffer, + PICAuint span_x, + const PICArect *srcRect, + const PICApoint *dstPos, + PICAuint order, + PICAint iVolatile, + PICAerror *return_value, + int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) lctx; + (void) writeback; + (void) colorBuffer; + (void) depthBuffer; + (void) span_x; + (void) srcRect; + (void) dstPos; + (void) order; + (void) iVolatile; +} +void PACK_APIENTRY crPackPicaReadFrame(PICAcontextID lctx, + PICAframeID frameID, + PICAuint format, + PICAvoid *colorbuffer, + PICAvoid *depthbuffer, + const PICArect *rect, + PICAerror *return_value, + int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) lctx; + (void) frameID; + (void) format; + (void) colorbuffer; + (void) depthbuffer; + (void) rect; +} +void PACK_APIENTRY crPackPicaReadFrameSWAP(PICAcontextID lctx, + PICAframeID frameID, + PICAuint format, + PICAvoid *colorbuffer, + PICAvoid *depthbuffer, + const PICArect *rect, + PICAerror *return_value, + int* writeback ) +{ + + crWarning("You can't really pack PICA calls!"); + *return_value = -1; + (void) writeback; + (void) lctx; + (void) frameID; + (void) format; + (void) colorbuffer; + (void) depthbuffer; + (void) rect; +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_pixelmap.c b/src/VBox/GuestHost/OpenGL/packer/pack_pixelmap.c new file mode 100644 index 00000000..399a0cd2 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_pixelmap.c @@ -0,0 +1,64 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_mem.h" +#include "cr_glstate.h" + +static unsigned char * __gl_HandlePixelMapData(GLenum map, GLsizei mapsize, int size_of_value, const GLvoid *values) +{ + int nodata = (values == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + int packet_length = + sizeof( map ) + + sizeof( mapsize ) + sizeof(int) + sizeof(GLint); + unsigned char *data_ptr; + + if (!nodata) + { + packet_length += mapsize*size_of_value; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + + WRITE_DATA( 0, GLenum, map ); + WRITE_DATA( 4, GLsizei, mapsize ); + WRITE_DATA( 8, int, nodata); + WRITE_DATA( 12, GLint, (GLint)(uintptr_t)values); + + if (!nodata) + { + crMemcpy( data_ptr + 16, values, mapsize*size_of_value ); + } + + return data_ptr; +} + +void PACK_APIENTRY crPackPixelMapfv(GLenum map, GLsizei mapsize, + const GLfloat *values) +{ + unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values ); + + crHugePacket( CR_PIXELMAPFV_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackPixelMapuiv(GLenum map, GLsizei mapsize, + const GLuint *values) +{ + unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values ); + + crHugePacket( CR_PIXELMAPUIV_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackPixelMapusv(GLenum map, GLsizei mapsize, + const GLushort *values) +{ + unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values ); + + crHugePacket( CR_PIXELMAPUSV_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c b/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c new file mode 100644 index 00000000..4c09006d --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c @@ -0,0 +1,225 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_pixeldata.h" +#include "cr_error.h" +#include "cr_mem.h" +#include "cr_version.h" + + +void PACK_APIENTRY crPackDrawPixels(GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length, imagesize; + int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + packet_length = + sizeof( width ) + + sizeof( height ) + + sizeof( format ) + + sizeof( type ) + sizeof(int) + sizeof(GLint); + + if (!noimagedata) + { + imagesize = crImageSize( format, type, width, height ); + + if (imagesize<=0) + { + crDebug("crPackDrawPixels: 0 image size, ignoring"); + return; + } + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLsizei, width ); + WRITE_DATA( 4, GLsizei, height ); + WRITE_DATA( 8, GLenum, format ); + WRITE_DATA( 12, GLenum, type ); + WRITE_DATA( 16, GLint, noimagedata ); + WRITE_DATA( 20, GLint, (GLint) (uintptr_t) pixels ); + + if (!noimagedata) + { + crPixelCopy2D(width, height, + (void *) (data_ptr + 24), format, type, NULL, /* dst */ + pixels, format, type, unpackstate); /* src */ + } + + crHugePacket( CR_DRAWPIXELS_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackReadPixels(GLint x, GLint y, GLsizei width, + GLsizei height, GLenum format, + GLenum type, GLvoid *pixels, + const CRPixelPackState *packstate, + int *writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + GLint stride = 0; + GLint bytes_per_row; + int bytes_per_pixel; + *writeback = 0; + + bytes_per_pixel = crPixelSize(format, type); + if (bytes_per_pixel <= 0) { + char string[80]; + sprintf(string, "crPackReadPixels(format 0x%x or type 0x%x)", format, type); + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, string); + return; + } + + /* default bytes_per_row so crserver can allocate memory */ + bytes_per_row = width * bytes_per_pixel; + + stride = bytes_per_row; + if (packstate->alignment != 1) { + GLint remainder = bytes_per_row % packstate->alignment; + if (remainder) + stride = bytes_per_row + (packstate->alignment - remainder); + } + + CR_GET_BUFFERED_POINTER(pc, 48 + sizeof(CRNetworkPointer) ); + WRITE_DATA( 0, GLint, x ); + WRITE_DATA( 4, GLint, y ); + WRITE_DATA( 8, GLsizei, width ); + WRITE_DATA( 12, GLsizei, height ); + WRITE_DATA( 16, GLenum, format ); + WRITE_DATA( 20, GLenum, type ); + WRITE_DATA( 24, GLint, stride ); /* XXX not really used! */ + WRITE_DATA( 28, GLint, packstate->alignment ); + WRITE_DATA( 32, GLint, packstate->skipRows ); + WRITE_DATA( 36, GLint, packstate->skipPixels ); + WRITE_DATA( 40, GLint, bytes_per_row ); + WRITE_DATA( 44, GLint, packstate->rowLength ); + WRITE_NETWORK_POINTER( 48, (char *) pixels ); + WRITE_OPCODE( pc, CR_READPIXELS_OPCODE ); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +/* Round N up to the next multiple of 8 */ +#define CEIL8(N) (((N) + 7) & ~0x7) + +void PACK_APIENTRY crPackBitmap(GLsizei width, GLsizei height, + GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, + const GLubyte *bitmap, const CRPixelPackState *unpack ) +{ + const int noimagedata = (bitmap == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + unsigned char *data_ptr; + int data_length = 0; + /*GLubyte *destBitmap = NULL; - unused */ + int packet_length = + sizeof( width ) + + sizeof( height ) + + sizeof( xorig ) + + sizeof( yorig ) + + sizeof( xmove ) + + sizeof( ymove ) + + sizeof( GLuint ) + sizeof(GLint); + + if (!noimagedata) + { + data_length = CEIL8(width) * height / 8; + packet_length += data_length; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + + WRITE_DATA( 0, GLsizei, width ); + WRITE_DATA( 4, GLsizei, height ); + WRITE_DATA( 8, GLfloat, xorig ); + WRITE_DATA( 12, GLfloat, yorig ); + WRITE_DATA( 16, GLfloat, xmove ); + WRITE_DATA( 20, GLfloat, ymove ); + WRITE_DATA( 24, GLuint, noimagedata ); + WRITE_DATA( 28, GLint, (GLint) (uintptr_t) bitmap); + + if (!noimagedata) + crBitmapCopy(width, height, (GLubyte *)(data_ptr + 32), bitmap, unpack); + + crHugePacket( CR_BITMAP_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} +/* + ZPix - compressed DrawPixels +*/ +void PACK_APIENTRY crPackZPixCR( GLsizei width, GLsizei height, + GLenum format, GLenum type, + GLenum ztype, GLint zparm, GLint length, + const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + (void)unpackstate; + + if (pixels == NULL) + { + return; + } + + packet_length = + sizeof( int ) + /* packet size */ + sizeof( GLenum ) + /* extended opcode */ + sizeof( width ) + + sizeof( height ) + + sizeof( format ) + + sizeof( type ) + + sizeof( ztype ) + + sizeof( zparm ) + + sizeof( length ); + + packet_length += length; + +/* XXX JAG + crDebug("PackZPixCR: fb %d x %d, state %d, zlen = %d, plen = %d", + width, height, ztype, length, packet_length); +*/ + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum , CR_ZPIXCR_EXTEND_OPCODE ); + WRITE_DATA( 4, GLsizei, width ); + WRITE_DATA( 8, GLsizei, height ); + WRITE_DATA( 12, GLenum, format ); + WRITE_DATA( 16, GLenum, type ); + WRITE_DATA( 20, GLenum, ztype ); + WRITE_DATA( 24, GLint, zparm ); + WRITE_DATA( 28, GLint, length ); + + crMemcpy((void *) (data_ptr+32), pixels, length); + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + + +void PACK_APIENTRY +crPackGetTexImage( GLenum target, GLint level, GLenum format, GLenum type, + GLvoid * pixels, const CRPixelPackState * packstate, + int * writeback ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; (void) packstate; + CR_GET_BUFFERED_POINTER( pc, 40 ); + WRITE_DATA( 0, GLint, 40 ); + WRITE_DATA( 4, GLenum, CR_GETTEXIMAGE_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, target ); + WRITE_DATA( 12, GLint, level ); + WRITE_DATA( 16, GLenum, format ); + WRITE_DATA( 20, GLenum, type ); + WRITE_NETWORK_POINTER( 24, (void *) pixels ); + WRITE_NETWORK_POINTER( 32, (void *) writeback ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_point.c b/src/VBox/GuestHost/OpenGL/packer/pack_point.c new file mode 100644 index 00000000..3df4ddb8 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_point.c @@ -0,0 +1,107 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_version.h" + +#ifdef CR_ARB_point_parameters + +static GLboolean __handlePointDataf( GLenum pname, const GLfloat *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + int params_length = 0; + int packet_length = 2 * sizeof( int ) + sizeof( pname ); + unsigned char *data_ptr; + switch( pname ) + { + case GL_POINT_SIZE_MIN_ARB: + case GL_POINT_SIZE_MAX_ARB: + case GL_POINT_FADE_THRESHOLD_SIZE_ARB: + params_length = sizeof( *params ); + break; + case GL_POINT_DISTANCE_ATTENUATION_ARB: + params_length = 3 * sizeof( *params ); + break; + default: + { + char msg[100]; + sprintf(msg, "Invalid pname in PointParameter: %d", (int) pname ); + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, msg); + } + return GL_FALSE; + } + packet_length += params_length; + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_POINTPARAMETERFVARB_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, pname ); + WRITE_DATA( 12, GLfloat, params[0] ); + if (packet_length > 16) + { + WRITE_DATA( 16, GLfloat, params[1] ); + WRITE_DATA( 20, GLfloat, params[2] ); + } + return GL_TRUE; +} + +void PACK_APIENTRY crPackPointParameterfvARB(GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handlePointDataf( pname, params )) + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +#endif + +static GLboolean __handlePointDatai( GLenum pname, const GLint *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + int params_length = 0; + int packet_length = 2 * sizeof( int ) + sizeof( pname ); + unsigned char *data_ptr; + switch( pname ) + { + case GL_POINT_SIZE_MIN_ARB: + case GL_POINT_SIZE_MAX_ARB: + case GL_POINT_FADE_THRESHOLD_SIZE_ARB: + params_length = sizeof( *params ); + break; + case GL_POINT_DISTANCE_ATTENUATION_ARB: + params_length = 3 * sizeof( *params ); + break; + default: + { + char msg[100]; + sprintf(msg, "Invalid pname in PointParameter: %d", (int) pname ); + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, msg); + } + return GL_FALSE; + } + packet_length += params_length; + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, GLint, packet_length ); + WRITE_DATA( 4, GLenum, CR_POINTPARAMETERIV_EXTEND_OPCODE ); + WRITE_DATA( 8, GLenum, pname ); + WRITE_DATA( 12, GLint, params[0] ); + if (packet_length > 16) + { + WRITE_DATA( 16, GLint, params[1] ); + WRITE_DATA( 20, GLint, params[2] ); + } + return GL_TRUE; +} + +void PACK_APIENTRY crPackPointParameteriv(GLenum pname, const GLint *params) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handlePointDatai( pname, params )) + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_program.c b/src/VBox/GuestHost/OpenGL/packer/pack_program.c new file mode 100644 index 00000000..8a62e01b --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_program.c @@ -0,0 +1,542 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +/* + * Packer functions for GL_NV_vertex_program extension. + * XXX: Quite a few of these functions are unfinished. + */ + + +#include "packer.h" +#include "cr_error.h" + + +void PACK_APIENTRY crPackProgramParameters4dvNV(GLenum target, GLuint index, GLuint num, const GLdouble * params) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + int packet_length = sizeof(int) + sizeof(target) + sizeof(index) + sizeof(num) + num * 4 * sizeof(GLdouble); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(sizeof(int) + 0, GLenum, target); + WRITE_DATA(sizeof(int) + 4, GLuint, index); + WRITE_DATA(sizeof(int) + 8, GLuint, num); + crMemcpy(data_ptr + sizeof(int) + 12, params, num * 4 * sizeof(GLdouble)); + + WRITE_OPCODE(pc, CR_PROGRAMPARAMETERS4DVNV_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void PACK_APIENTRY crPackProgramParameters4fvNV(GLenum target, GLuint index, GLuint num, const GLfloat * params) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + int packet_length = sizeof(int) + sizeof(target) + sizeof(index) + sizeof(num) + num * 4 * sizeof(GLfloat); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(sizeof(int) + 0, GLenum, target); + WRITE_DATA(sizeof(int) + 4, GLuint, index); + WRITE_DATA(sizeof(int) + 8, GLuint, num); + crMemcpy(data_ptr + sizeof(int) + 12, params, num * 4 * sizeof(GLfloat)); + + WRITE_OPCODE(pc, CR_PROGRAMPARAMETERS4FVNV_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void PACK_APIENTRY crPackVertexAttribs1dvNV(GLuint index, GLsizei n, const GLdouble *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib1dvARB(index + i, v + i); +} + + +void PACK_APIENTRY crPackVertexAttribs1fvNV(GLuint index, GLsizei n, const GLfloat *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib1fvARB(index + i, v + i); +} + + +void PACK_APIENTRY crPackVertexAttribs1svNV(GLuint index, GLsizei n, const GLshort *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib1svARB(index + i, v + i); +} + + +void PACK_APIENTRY crPackVertexAttribs2dvNV(GLuint index, GLsizei n, const GLdouble *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib2dvARB(index + i, v + 2 * i); +} + +void PACK_APIENTRY crPackVertexAttribs2fvNV(GLuint index, GLsizei n, const GLfloat *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib2fvARB(index + i, v + 2 * i); +} + +void PACK_APIENTRY crPackVertexAttribs2svNV(GLuint index, GLsizei n, const GLshort *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib2svARB(index + i, v + 2 * i); +} + +void PACK_APIENTRY crPackVertexAttribs3dvNV(GLuint index, GLsizei n, const GLdouble *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib3dvARB(index + i, v + 3 * i); +} + +void PACK_APIENTRY crPackVertexAttribs3fvNV(GLuint index, GLsizei n, const GLfloat *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib3fvARB(index + i, v + 3 * i); +} + +void PACK_APIENTRY crPackVertexAttribs3svNV(GLuint index, GLsizei n, const GLshort *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib3svARB(index + i, v + 3 * i); +} + +void PACK_APIENTRY crPackVertexAttribs4dvNV(GLuint index, GLsizei n, const GLdouble *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib4dvARB(index + i, v + 4 * i); +} + +void PACK_APIENTRY crPackVertexAttribs4fvNV(GLuint index, GLsizei n, const GLfloat *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib4fvARB(index + i, v + 4 * i); +} + +void PACK_APIENTRY crPackVertexAttribs4svNV(GLuint index, GLsizei n, const GLshort *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib4svARB(index + i, v + 4 * i); +} + +void PACK_APIENTRY crPackVertexAttribs4ubvNV(GLuint index, GLsizei n, const GLubyte *v) +{ + GLint i; + /* reverse order so we hit index 0 last (provoking glVertex) */ + for (i = n - 1; i >= 0; i--) + crPackVertexAttrib4ubvARB(index + i, v + 4 * i); +} + + +void PACK_APIENTRY crPackExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params) +{ + const int packet_length = 32; + unsigned char *data_ptr = NULL; + CR_GET_PACKER_CONTEXT(pc); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(4, GLenum, CR_EXECUTEPROGRAMNV_EXTEND_OPCODE); + WRITE_DATA(8, GLenum, target); + WRITE_DATA(12, GLuint, id); + WRITE_DATA(16, GLfloat, params[0]); + WRITE_DATA(20, GLfloat, params[1]); + WRITE_DATA(24, GLfloat, params[2]); + WRITE_DATA(28, GLfloat, params[3]); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackLoadProgramNV(GLenum target, GLuint id, GLsizei len, const GLubyte *program) +{ + const int packet_length = 20 + len; + unsigned char *data_ptr = NULL; + CR_GET_PACKER_CONTEXT(pc); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(4, GLenum, CR_LOADPROGRAMNV_EXTEND_OPCODE); + WRITE_DATA(8, GLenum, target); + WRITE_DATA(12, GLuint, id); + WRITE_DATA(16, GLsizei, len); + crMemcpy((void *) (data_ptr + 20), program, len); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackRequestResidentProgramsNV(GLsizei n, const GLuint *ids) +{ + CR_GET_PACKER_CONTEXT(pc); + (void) pc; + (void) n; + (void) ids; + /* We're no-op'ing this function for now. */ +} + + +void PACK_APIENTRY crPackProgramNamedParameter4fNV (GLuint id, GLsizei len, const GLubyte * name, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + int packet_length = 32 + len; + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, GLint, packet_length); + WRITE_DATA(4, GLenum, CR_PROGRAMNAMEDPARAMETER4FNV_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, id); + WRITE_DATA(12, GLsizei, len); + WRITE_DATA(16, GLfloat, x); + WRITE_DATA(20, GLfloat, y); + WRITE_DATA(24, GLfloat, z); + WRITE_DATA(28, GLfloat, w); + crMemcpy((void *) (data_ptr + 32), name, len); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackProgramNamedParameter4dNV (GLuint id, GLsizei len, const GLubyte * name, GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + int packet_length = 48 + len; + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, GLint, packet_length); + WRITE_DATA(4, GLenum, CR_PROGRAMNAMEDPARAMETER4DNV_EXTEND_OPCODE); + WRITE_DATA(8, GLenum, id); + WRITE_DATA(12, GLuint, len); + WRITE_DOUBLE(16, x); + WRITE_DOUBLE(24, y); + WRITE_DOUBLE(32, z); + WRITE_DOUBLE(40, w); + crMemcpy((void *) (data_ptr + 48), name, len); + + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackProgramNamedParameter4fvNV (GLuint id, GLsizei len, const GLubyte * name, const GLfloat * v) +{ + crPackProgramNamedParameter4fNV(id, len, name, v[0], v[1], v[2], v[3]); +} + +void PACK_APIENTRY crPackProgramNamedParameter4dvNV (GLuint id, GLsizei len, const GLubyte * name, const GLdouble * v) +{ + crPackProgramNamedParameter4dNV(id, len, name, v[0], v[1], v[2], v[3]); +} + + +void PACK_APIENTRY +crPackAreProgramsResidentNV(GLsizei n, const GLuint * programs, + GLboolean *residences, GLboolean *return_val, + int *writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + int packet_length; + + (void) return_val; /* Caller must compute this from residences!!! */ + + packet_length = sizeof(int) + /* packet length */ + sizeof(GLenum) + /* extend opcode */ + sizeof(n) + /* num programs */ + n * sizeof(*programs) + /* programs */ + 8 + 8; + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(4, GLenum, CR_AREPROGRAMSRESIDENTNV_EXTEND_OPCODE); + WRITE_DATA(8, GLsizei, n); + crMemcpy(data_ptr + 12, programs, n * sizeof(*programs)); + WRITE_NETWORK_POINTER(12 + n * sizeof(*programs), (void *) residences); + WRITE_NETWORK_POINTER(20 + n * sizeof(*programs), (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void PACK_APIENTRY crPackGetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name, GLfloat *params, int *writeback) +{ + int packet_length = 32 + len; + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, GLint, packet_length); + WRITE_DATA(4, GLenum, CR_GETPROGRAMNAMEDPARAMETERFVNV_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, id); + WRITE_DATA(12, GLsizei, len); + crMemcpy(data_ptr + 16, name, len); + WRITE_NETWORK_POINTER(16 + len, (void *) params); + WRITE_NETWORK_POINTER(16 + len + 8, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte *name, GLdouble *params, int *writeback) +{ + int packet_length = 32 + len; + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, GLint, packet_length); + WRITE_DATA(4, GLenum, CR_GETPROGRAMNAMEDPARAMETERDVNV_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, id); + WRITE_DATA(12, GLsizei, len); + crMemcpy(data_ptr + 16, name, len); + WRITE_NETWORK_POINTER(16 + len, (void *) params); + WRITE_NETWORK_POINTER(16 + len + 8, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void PACK_APIENTRY crPackDeleteProgramsARB(GLsizei n, const GLuint *ids) +{ + unsigned char *data_ptr = NULL; + int packet_length = sizeof(GLenum) + sizeof(n) + n * sizeof(*ids); + + if (!ids) + return; + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, CR_DELETEPROGRAMSARB_EXTEND_OPCODE); + WRITE_DATA(4, GLsizei, n); + crMemcpy(data_ptr + 8, ids, n * sizeof(*ids)); + crHugePacket(CR_EXTEND_OPCODE, data_ptr); + crPackFree(data_ptr); +} + + +void PACK_APIENTRY crPackProgramStringARB(GLenum target, GLenum format, GLsizei len, const void *string) +{ + const int packet_length = 20 + len; + unsigned char *data_ptr = NULL; + CR_GET_PACKER_CONTEXT(pc); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(4, GLenum, CR_PROGRAMSTRINGARB_EXTEND_OPCODE); + WRITE_DATA(8, GLenum, target); + WRITE_DATA(12, GLuint, format); + WRITE_DATA(16, GLsizei, len); + crMemcpy((void *) (data_ptr + 20), string, len); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +/* + * Can't easily auto-generate these functions since there aren't + * non-vector versions. + */ + +void PACK_APIENTRY crPackVertexAttrib4NbvARB(GLuint index, const GLbyte *v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 8); + pc->current.c.vertexAttrib.b4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLbyte, v[0]); + WRITE_DATA(5, GLbyte, v[1]); + WRITE_DATA(6, GLbyte, v[2]); + WRITE_DATA(7, GLbyte, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4NBVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4NivARB(GLuint index, const GLint *v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 20); + pc->current.c.vertexAttrib.i4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLint, v[0]); + WRITE_DATA(8, GLint, v[1]); + WRITE_DATA(12, GLint, v[2]); + WRITE_DATA(16, GLint, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4NIVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4NsvARB(GLuint index, const GLshort *v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 12); + pc->current.c.vertexAttrib.s4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLshort, v[0]); + WRITE_DATA(6, GLshort, v[1]); + WRITE_DATA(8, GLshort, v[2]); + WRITE_DATA(10, GLshort, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4NSVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4NubvARB(GLuint index, const GLubyte * v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 8); + pc->current.c.vertexAttrib.ub4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLubyte, v[0]); + WRITE_DATA(5, GLubyte, v[1]); + WRITE_DATA(6, GLubyte, v[2]); + WRITE_DATA(7, GLubyte, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4NUBVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4NuivARB(GLuint index, const GLuint * v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 20); + pc->current.c.vertexAttrib.ui4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLuint, v[0]); + WRITE_DATA(8, GLuint, v[1]); + WRITE_DATA(12, GLuint, v[2]); + WRITE_DATA(16, GLuint, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4NUIVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4NusvARB(GLuint index, const GLushort * v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 12); + pc->current.c.vertexAttrib.s4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLushort, v[0]); + WRITE_DATA(6, GLushort, v[1]); + WRITE_DATA(8, GLushort, v[2]); + WRITE_DATA(10, GLushort, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4NUSVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4bvARB(GLuint index, const GLbyte * v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 8); + pc->current.c.vertexAttrib.b4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLbyte, v[0]); + WRITE_DATA(5, GLbyte, v[1]); + WRITE_DATA(6, GLbyte, v[2]); + WRITE_DATA(7, GLbyte, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4BVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4ivARB(GLuint index, const GLint * v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 20); + pc->current.c.vertexAttrib.i4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLint, v[0]); + WRITE_DATA(8, GLint, v[1]); + WRITE_DATA(12, GLint, v[2]); + WRITE_DATA(16, GLint, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4IVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4uivARB(GLuint index, const GLuint * v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 20); + pc->current.c.vertexAttrib.ui4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLuint, v[0]); + WRITE_DATA(8, GLuint, v[1]); + WRITE_DATA(12, GLuint, v[2]); + WRITE_DATA(16, GLuint, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4UIVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackVertexAttrib4usvARB(GLuint index, const GLushort * v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 12); + pc->current.c.vertexAttrib.s4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLushort, v[0]); + WRITE_DATA(6, GLushort, v[1]); + WRITE_DATA(8, GLushort, v[2]); + WRITE_DATA(10, GLushort, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4USVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void PACK_APIENTRY crPackVertexAttrib4ubvARB(GLuint index, const GLubyte * v) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr = NULL; + CR_GET_BUFFERED_POINTER(pc, 8); + pc->current.c.vertexAttrib.ub4[index] = data_ptr + 4; + pc->current.attribsUsedMask |= (1 << index); + WRITE_DATA(0, GLuint, index); + WRITE_DATA(4, GLubyte, v[0]); + WRITE_DATA(5, GLubyte, v[1]); + WRITE_DATA(6, GLubyte, v[2]); + WRITE_DATA(7, GLubyte, v[3]); + WRITE_OPCODE(pc, CR_VERTEXATTRIB4UBVARB_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_regcombiner.c b/src/VBox/GuestHost/OpenGL/packer/pack_regcombiner.c new file mode 100644 index 00000000..ddfff764 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_regcombiner.c @@ -0,0 +1,82 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" + +static GLboolean __handleCombinerParameterData(GLenum pname, const GLfloat *params, GLenum extended_opcode) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned int params_length = 0; + unsigned int packet_length = sizeof(int) + sizeof(extended_opcode) + sizeof(pname); + unsigned char *data_ptr; + + switch(pname) + { + case GL_CONSTANT_COLOR0_NV: + case GL_CONSTANT_COLOR1_NV: + params_length = 4 * sizeof(*params); + break; + case GL_NUM_GENERAL_COMBINERS_NV: + case GL_COLOR_SUM_CLAMP_NV: + params_length = sizeof(*params); + break; + default: + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackCombinerParameter(bad pname)"); + CRASSERT(0); + return GL_FALSE; + } + packet_length += params_length; + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(sizeof(int) + 0, GLenum, extended_opcode); + WRITE_DATA(sizeof(int) + 4, GLenum, pname); + WRITE_DATA(sizeof(int) + 8, GLfloat, params[0]); + if (params_length > sizeof(*params)) + { + WRITE_DATA(sizeof(int) + 12, GLfloat, params[1]); + WRITE_DATA(sizeof(int) + 16, GLfloat, params[2]); + WRITE_DATA(sizeof(int) + 20, GLfloat, params[3]); + CRASSERT(packet_length == sizeof(int) + 20 + 4); + } + return GL_TRUE; +} + +void PACK_APIENTRY crPackCombinerParameterfvNV(GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handleCombinerParameterData(pname, params, CR_COMBINERPARAMETERFVNV_EXTEND_OPCODE)) + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackCombinerParameterivNV(GLenum pname, const GLint *params) +{ + /* floats and ints are the same size, so the packing should be the same */ + CR_GET_PACKER_CONTEXT(pc); + if (__handleCombinerParameterData(pname, (const GLfloat *) params, CR_COMBINERPARAMETERIVNV_EXTEND_OPCODE)) + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackCombinerStageParameterfvNV(GLenum stage, GLenum pname, const GLfloat *params) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_COMBINERSTAGEPARAMETERFVNV_EXTEND_OPCODE); + WRITE_DATA(8, GLenum, stage); + WRITE_DATA(12, GLenum, pname); + WRITE_DATA(16, GLfloat, params[0]); + WRITE_DATA(20, GLfloat, params[1]); + WRITE_DATA(24, GLfloat, params[2]); + WRITE_DATA(28, GLfloat, params[3]); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_shaders.c b/src/VBox/GuestHost/OpenGL/packer/pack_shaders.c new file mode 100644 index 00000000..77114118 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_shaders.c @@ -0,0 +1,866 @@ +/* $Id: pack_shaders.c $ */ + +/** @file + * VBox OpenGL DRI driver functions + */ + +/* + * Copyright (C) 2009-2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include "packer.h" +#include "cr_error.h" +#include "cr_string.h" + +void PACK_APIENTRY crPackBindAttribLocation(GLuint program, GLuint index, const char *name) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int cbName = crStrlen(name)+1; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(program)+sizeof(index) + cbName*sizeof(*name); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_BINDATTRIBLOCATION_EXTEND_OPCODE); + WRITE_DATA_AI(GLuint, program); + WRITE_DATA_AI(GLuint, index); + crMemcpy(data_ptr, name, cbName*sizeof(*name)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackShaderSource(GLuint shader, GLsizei count, const char **string, const GLint *length) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + GLint *pLocalLength; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(shader)+sizeof(count)+sizeof(GLint)+count*sizeof(*pLocalLength); + GLsizei i; + + if ((0==count) || (!string)) return; + + pLocalLength = crAlloc(count*sizeof(*length)); + if (!pLocalLength) return; + + for (i=0; i<count; ++i) + { + pLocalLength[i] = ((length && (length[i]>=0)) ? length[i] : crStrlen(string[i]))+1; + packet_length += pLocalLength[i]; + } + + if (length) + { + packet_length += count*sizeof(*length); + } + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_SHADERSOURCE_EXTEND_OPCODE); + WRITE_DATA_AI(GLuint, shader); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLint, (GLint)(length ? 1:0)); + crMemcpy(data_ptr, pLocalLength, count*sizeof(*pLocalLength)); + data_ptr += count*sizeof(*pLocalLength); + + if (length) + { + crMemcpy(data_ptr, length, count*sizeof(*length)); + data_ptr += count*sizeof(*length); + } + + for (i=0; i<count; ++i) + { + if (string[i]) + { + if (length && (length[i]>=0)) + { + /* include \0 in the string to make intel drivers happy */ + crMemcpy(data_ptr, string[i], pLocalLength[i] - 1); + data_ptr[pLocalLength[i] - 1] = '\0'; + } + else + { + /* the \0 s already in the string */ + crMemcpy(data_ptr, string[i], pLocalLength[i]); + } + } + else + { + CRASSERT(pLocalLength[i]==1); + *data_ptr = 0; + } + data_ptr += pLocalLength[i]; + } + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); + + crFree(pLocalLength); +} + +void PACK_APIENTRY crPackUniform1fv(GLint location, GLsizei count, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count) + count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORM1FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + crMemcpy(data_ptr, value, count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniform1iv(GLint location, GLsizei count, const GLint *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count) + count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORM1IV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + crMemcpy(data_ptr, value, count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniform2fv(GLint location, GLsizei count, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count) + 2*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORM2FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + crMemcpy(data_ptr, value, 2*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniform2iv(GLint location, GLsizei count, const GLint *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count) + 2*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORM2IV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + crMemcpy(data_ptr, value, 2*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniform3fv(GLint location, GLsizei count, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count) + 3*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORM3FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + crMemcpy(data_ptr, value, 3*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniform3iv(GLint location, GLsizei count, const GLint *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count) + 3*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORM3IV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + crMemcpy(data_ptr, value, 3*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniform4fv(GLint location, GLsizei count, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count) + 4*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORM4FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + crMemcpy(data_ptr, value, 4*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniform4iv(GLint location, GLsizei count, const GLint *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count) + 4*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORM4IV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + crMemcpy(data_ptr, value, 4*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + 2*2*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX2FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 2*2*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + 3*3*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX3FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 3*3*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + 4*4*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX4FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 4*4*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + + 2*3*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX2X3FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 2*3*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + + 3*2*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX3X2FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 3*2*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + + 2*4*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX2X4FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 2*4*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + + 4*2*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX4X2FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 4*2*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + + 3*4*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX3X4FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 3*4*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(location)+sizeof(count)+sizeof(transpose) + + 4*3*count*sizeof(*value); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_UNIFORMMATRIX4X3FV_EXTEND_OPCODE); + WRITE_DATA_AI(GLint, location); + WRITE_DATA_AI(GLsizei, count); + WRITE_DATA_AI(GLboolean, transpose); + crMemcpy(data_ptr, value, 4*3*count*sizeof(*value)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackDrawBuffers(GLsizei n, const GLenum *bufs) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(n) + n*sizeof(*bufs); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_DRAWBUFFERS_EXTEND_OPCODE); + WRITE_DATA_AI(GLsizei, n); + crMemcpy(data_ptr, bufs, n*sizeof(*bufs)); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +/** @todo next 8 functions are bit hacky, + * we expect packspu to pass a single structure with all output parameters via first output pointer. + * it'd be better to add CRMessageMultiReadback one day. + */ +void PACK_APIENTRY crPackGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, char * name, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + (void) size; + (void) type; + (void) name; + CR_GET_BUFFERED_POINTER(pc, 36); + WRITE_DATA(0, GLint, 36); + WRITE_DATA(4, GLenum, CR_GETACTIVEATTRIB_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, program); + WRITE_DATA(12, GLuint, index); + WRITE_DATA(16, GLsizei, bufSize); + WRITE_NETWORK_POINTER(20, (void *) length); + WRITE_NETWORK_POINTER(28, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, char * name, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + (void) size; + (void) type; + (void) name; + CR_GET_BUFFERED_POINTER(pc, 36); + WRITE_DATA(0, GLint, 36); + WRITE_DATA(4, GLenum, CR_GETACTIVEUNIFORM_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, program); + WRITE_DATA(12, GLuint, index); + WRITE_DATA(16, GLsizei, bufSize); + WRITE_NETWORK_POINTER(20, (void *) length); + WRITE_NETWORK_POINTER(28, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei * count, GLuint * shaders, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + (void) shaders; + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_GETATTACHEDSHADERS_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, program); + WRITE_DATA(12, GLsizei, maxCount); + WRITE_NETWORK_POINTER(16, (void *) count); + WRITE_NETWORK_POINTER(24, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetAttachedObjectsARB(VBoxGLhandleARB containerObj, GLsizei maxCount, GLsizei * count, VBoxGLhandleARB * obj, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; (void) obj; + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_GETATTACHEDOBJECTSARB_EXTEND_OPCODE); + WRITE_DATA(8, VBoxGLhandleARB, containerObj); + WRITE_DATA(12, GLsizei, maxCount); + WRITE_NETWORK_POINTER(16, (void *) count); + WRITE_NETWORK_POINTER(24, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetInfoLogARB(VBoxGLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; (void) infoLog; + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_GETINFOLOGARB_EXTEND_OPCODE); + WRITE_DATA(8, VBoxGLhandleARB, obj); + WRITE_DATA(12, GLsizei, maxLength); + WRITE_NETWORK_POINTER(16, (void *) length); + WRITE_NETWORK_POINTER(24, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei * length, char * infoLog, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + (void) infoLog; + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_GETPROGRAMINFOLOG_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, program); + WRITE_DATA(12, GLsizei, bufSize); + WRITE_NETWORK_POINTER(16, (void *) length); + WRITE_NETWORK_POINTER(24, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei * length, char * infoLog, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + (void) infoLog; + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_GETSHADERINFOLOG_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, shader); + WRITE_DATA(12, GLsizei, bufSize); + WRITE_NETWORK_POINTER(16, (void *) length); + WRITE_NETWORK_POINTER(24, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei * length, char * source, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + (void) source; + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_GETSHADERSOURCE_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, shader); + WRITE_DATA(12, GLsizei, bufSize); + WRITE_NETWORK_POINTER(16, (void *) length); + WRITE_NETWORK_POINTER(24, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetUniformsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pData; + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_GETUNIFORMSLOCATIONS_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, program); + WRITE_DATA(12, GLsizei, maxcbData); + WRITE_NETWORK_POINTER(16, (void *) cbData); + WRITE_NETWORK_POINTER(24, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetAttribsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pData; + CR_GET_BUFFERED_POINTER(pc, 32); + WRITE_DATA(0, GLint, 32); + WRITE_DATA(4, GLenum, CR_GETATTRIBSLOCATIONS_EXTEND_OPCODE); + WRITE_DATA(8, GLuint, program); + WRITE_DATA(12, GLsizei, maxcbData); + WRITE_NETWORK_POINTER(16, (void *) cbData); + WRITE_NETWORK_POINTER(24, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetAttribLocation(GLuint program, const char * name, GLint * return_value, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int cbName = crStrlen(name)+1; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(program)+cbName*sizeof(*name)+16; + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_GETATTRIBLOCATION_EXTEND_OPCODE); + WRITE_DATA_AI(GLuint, program); + crMemcpy(data_ptr, name, cbName*sizeof(*name)); + data_ptr += cbName*sizeof(*name); + WRITE_NETWORK_POINTER(0, (void *) return_value); + WRITE_NETWORK_POINTER(8, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackGetUniformLocation(GLuint program, const char * name, GLint * return_value, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int cbName = crStrlen(name)+1; + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(program)+cbName*sizeof(*name)+16; + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_GETUNIFORMLOCATION_EXTEND_OPCODE); + WRITE_DATA_AI(GLuint, program); + crMemcpy(data_ptr, name, cbName*sizeof(*name)); + data_ptr += cbName*sizeof(*name); + WRITE_NETWORK_POINTER(0, (void *) return_value); + WRITE_NETWORK_POINTER(8, (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackBindAttribLocationSWAP(GLuint program, GLuint index, const char *name) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)program; + (void)index; + (void)name; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackShaderSourceSWAP(GLuint shader, GLsizei count, const char **string, const GLint *length) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)shader; + (void)count; + (void)string; + (void)length; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniform1fvSWAP(GLint location, GLsizei count, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)value; + (void)pc; + crError ("No swap version"); +} + + +void PACK_APIENTRY crPackUniform1ivSWAP(GLint location, GLsizei count, const GLint *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniform2fvSWAP(GLint location, GLsizei count, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniform2ivSWAP(GLint location, GLsizei count, const GLint * value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniform3fvSWAP(GLint location, GLsizei count, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniform3ivSWAP(GLint location, GLsizei count, const GLint *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniform4fvSWAP(GLint location, GLsizei count, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniform4ivSWAP(GLint location, GLsizei count, const GLint *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix2fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix3fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix4fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix2x3fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix3x2fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix2x4fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix4x2fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix3x4fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackUniformMatrix4x3fvSWAP(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)location; + (void)count; + (void)transpose; + (void)value; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackDrawBuffersSWAP(GLsizei n, const GLenum *bufs) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)n; + (void)bufs; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackGetAttribLocationSWAP(GLuint program, const char * name, GLint * return_value, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)program; + (void)name; + (void)return_value; + (void)writeback; + (void)pc; + crError ("No swap version"); +} + +void PACK_APIENTRY crPackGetUniformLocationSWAP(GLuint program, const char * name, GLint * return_value, int * writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + (void)program; + (void)name; + (void)return_value; + (void)writeback; + (void)pc; + crError ("No swap version"); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_stipple.c b/src/VBox/GuestHost/OpenGL/packer/pack_stipple.c new file mode 100644 index 00000000..8d3e59dd --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_stipple.c @@ -0,0 +1,36 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_mem.h" +#include "cr_glstate.h" + +void PACK_APIENTRY crPackPolygonStipple( const GLubyte *mask ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int nodata = crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + int packet_length = sizeof(int); + + if (nodata) + packet_length += sizeof(GLint); + else + packet_length += 32*32/8; + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA_AI(int, nodata); + if (nodata) + { + WRITE_DATA_AI(GLint, (GLint)(uintptr_t)mask); + } + else + { + crMemcpy( data_ptr, mask, 32*32/8 ); + } + WRITE_OPCODE( pc, CR_POLYGONSTIPPLE_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_swap.py b/src/VBox/GuestHost/OpenGL/packer/pack_swap.py new file mode 100755 index 00000000..763f04eb --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_swap.py @@ -0,0 +1,74 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +from __future__ import print_function +import sys, string + +sys.path.append( "../glapi_parser" ) +import apiutil + + +if len(sys.argv) != 2: + print >> sys.stderr, "Usage: %s <filename>" % sys.argv[0] + sys.exit(-1) + +file = open(sys.argv[1]) + +print("/* THIS FILE IS AUTOGENERATED FROM %s BY pack_swap.py */\n\n" % sys.argv[1]) + +for line in file.readlines(): + line = line.rstrip() + if line.find( "crPackAlloc" ) != -1 or line.find( "crPackFree" ) != -1: + print(line) + continue + elif line.find( "crPack" ) != -1: + fun_index = line.find( "crPack" ) + paren_index = line.find( "(", fun_index ) + space_index = line.find( " ", fun_index ) + quote_index = line.find( '"', fun_index ) + if paren_index == -1: + paren_index = 1000000; # HACK HACK + if space_index == -1: + space_index = 1000000; # HACK HACK + if quote_index == -1: + quote_index = 1000000; # HACK HACK + the_index = min( min( paren_index, space_index ), quote_index ) + print("%sSWAP%s" % (line[:the_index], line[the_index:])) + elif line.find("WRITE_DATA_AI") != -1: + lparen_index = line.find( "(" ) + rparen_index = line.rfind( ")" ) + args = list(map( str.strip, line[lparen_index+1:rparen_index].split( "," ) )) + indentation = line[:line.find( "WRITE_DATA_AI" )] + if apiutil.sizeof(args[0]) == 1: + print("%sWRITE_DATA_AI(%s, %s);" % (indentation, args[0], args[1])) + elif apiutil.sizeof(args[0]) == 2: + print("%sWRITE_DATA_AI(%s, SWAP16(%s) );" % (indentation, args[0], args[1])) + elif args[0] == 'GLfloat' or args[0] == 'GLclampf': + print("%sWRITE_DATA_AI(GLuint, SWAPFLOAT(%s) );" % (indentation, args[0])) + elif apiutil.sizeof(args[0]) == 4: + print("%sWRITE_DATA_AI(%s, SWAP32(%s));" % (indentation, args[0], args[1])) + else: + print >> sys.stderr, "UNKNOWN TYPE FOR WRITE_DATA: %s" % args[1] + sys.exit(-1) + elif line.find( "WRITE_DATA" ) != -1: + lparen_index = line.find( "(" ) + rparen_index = line.rfind( ")" ) + args = list(map( str.strip, line[lparen_index+1:rparen_index].split( "," ) )) + indentation = line[:line.find( "WRITE_DATA" )] + if apiutil.sizeof(args[1]) == 1: + print("%sWRITE_DATA(%s, %s, %s);" % (indentation, args[0], args[1], args[2])) + elif apiutil.sizeof(args[1]) == 2: + print("%sWRITE_DATA(%s, %s, SWAP16(%s));" % (indentation, args[0], args[1], args[2])) + elif args[1] == 'GLfloat' or args[1] == 'GLclampf': + print("%sWRITE_DATA(%s, GLuint, SWAPFLOAT(%s));" % (indentation, args[0], args[2])) + elif apiutil.sizeof(args[1]) == 4: + print("%sWRITE_DATA(%s, %s, SWAP32(%s));" % (indentation, args[0], args[1], args[2])) + else: + print >> sys.stderr, "UNKNOWN TYPE FOR WRITE_DATA: %s" % args[1] + sys.exit(-1) + elif line.find( "WRITE_DOUBLE" ) != -1: + print(line.replace( "WRITE_DOUBLE", "WRITE_SWAPPED_DOUBLE" )) + else: + print(line) diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_swap_lists.c b/src/VBox/GuestHost/OpenGL/packer/pack_swap_lists.c new file mode 100644 index 00000000..aa99db5b --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_swap_lists.c @@ -0,0 +1,117 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_error.h" +#include "cr_mem.h" + +static int __gl_CallListsNumBytes( GLenum type ) +{ + switch( type ) + { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_2_BYTES: + return 1; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_3_BYTES: + return 2; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_4_BYTES: + return 4; + default: + return -1; + } +} + +void PACK_APIENTRY crPackCallListsSWAP(GLint n, GLenum type, + const GLvoid *lists ) +{ + unsigned char *data_ptr; + int packet_length; + GLshort *shortPtr; + GLint *intPtr; + int i; + + int bytesPerList = __gl_CallListsNumBytes( type ); + int numBytes = bytesPerList * n; + + if (numBytes < 0) + { + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackCallLists(bad type)" ); + return; + } + + packet_length = sizeof( n ) + + sizeof( type ) + + numBytes; + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLint, SWAP32(n) ); + WRITE_DATA( 4, GLenum, SWAP32(type) ); + + crMemcpy( data_ptr + 8, lists, numBytes ); + shortPtr = (GLshort *) (data_ptr + 8); + intPtr = (GLint *) (data_ptr + 8); + + if (bytesPerList > 1) + { + for ( i = 0 ; i < n ; i++) + { + switch( bytesPerList ) + { + case 2: + *shortPtr = SWAP16(*shortPtr); + shortPtr+=1; + break; + case 4: + *intPtr = SWAP32(*intPtr); + intPtr+=1; + break; + } + } + } + + crHugePacket( CR_CALLLISTS_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + + +void PACK_APIENTRY crPackNewListSWAP( GLuint list, GLenum mode ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_CMDBLOCK_BEGIN( pc, CRPACKBLOCKSTATE_OP_NEWLIST ); + CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, 16, GL_FALSE ); + WRITE_DATA( 0, GLint, SWAP32(16) ); + WRITE_DATA( 4, GLenum, SWAP32(CR_NEWLIST_EXTEND_OPCODE) ); + WRITE_DATA( 8, GLuint, SWAP32(list) ); + WRITE_DATA( 12, GLenum, SWAP32(mode) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + pc->buffer.in_List = GL_TRUE; + pc->buffer.holds_List = GL_TRUE; + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +void PACK_APIENTRY crPackEndListSWAP( void ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + CR_GET_BUFFERED_POINTER( pc, 8 ); + WRITE_DATA( 0, GLint, SWAP32(8) ); + WRITE_DATA( 4, GLenum, SWAP32(CR_ENDLIST_EXTEND_OPCODE) ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + pc->buffer.in_List = GL_FALSE; + CR_CMDBLOCK_END( pc, CRPACKBLOCKSTATE_OP_NEWLIST ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_swap_map.c b/src/VBox/GuestHost/OpenGL/packer/pack_swap_map.c new file mode 100644 index 00000000..241f899e --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_swap_map.c @@ -0,0 +1,278 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_error.h" + + +/* Note -- for these packets, the ustride and vstride are implicit, + * and are computed into the packet instead of copied. + */ + +static int __gl_Map2NumComponents(GLenum target) +{ + switch(target) + { + case GL_MAP2_VERTEX_3: + case GL_MAP2_NORMAL: + case GL_MAP2_TEXTURE_COORD_3: + return 3; + case GL_MAP2_VERTEX_4: + case GL_MAP2_COLOR_4: + case GL_MAP2_TEXTURE_COORD_4: + return 4; + case GL_MAP2_INDEX: + case GL_MAP2_TEXTURE_COORD_1: + return 1; + case GL_MAP2_TEXTURE_COORD_2: + return 2; + default: + return -1; + } +} + +static int __gl_Map1NumComponents(GLenum target) +{ + switch(target) + { + case GL_MAP1_VERTEX_3: + case GL_MAP1_NORMAL: + case GL_MAP1_TEXTURE_COORD_3: + return 3; + case GL_MAP1_VERTEX_4: + case GL_MAP1_COLOR_4: + case GL_MAP1_TEXTURE_COORD_4: + return 4; + case GL_MAP1_INDEX: + case GL_MAP1_TEXTURE_COORD_1: + return 1; + case GL_MAP1_TEXTURE_COORD_2: + return 2; + default: + return -1; + } +} + +void PACK_APIENTRY crPackMap2dSWAP(GLenum target, GLdouble u1, + GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, + GLint vstride, GLint vorder, const GLdouble *points) +{ + unsigned char *data_ptr; + int u,v; + int comp; + GLdouble *dest_data, *src_data; + int packet_length = + sizeof(target) + + sizeof(u1) + + sizeof(u2) + + sizeof(uorder) + + sizeof(ustride) + + sizeof(v1) + + sizeof(v2) + + sizeof(vorder) + + sizeof(vstride); + + int num_components = __gl_Map2NumComponents(target); + if (num_components < 0) + { + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackMap2d(bad target)"); + return; + } + + packet_length += num_components*uorder*vorder*sizeof(*points); + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + + WRITE_DATA(0, GLenum, SWAP32(target)); + WRITE_SWAPPED_DOUBLE(4, u1); + WRITE_SWAPPED_DOUBLE(12, u2); + WRITE_DATA(20, GLint, SWAP32(num_components)); + WRITE_DATA(24, GLint, SWAP32(uorder)); + WRITE_SWAPPED_DOUBLE(28, v1); + WRITE_SWAPPED_DOUBLE(36, v2); + WRITE_DATA(44, GLint, SWAP32(num_components*uorder)); + WRITE_DATA(48, GLint, SWAP32(vorder)); + + dest_data = (GLdouble *) (data_ptr + 52); + src_data = (GLdouble *) points; + for (v = 0 ; v < vorder ; v++) + { + for (u = 0 ; u < uorder ; u++) + { + for (comp = 0 ; comp < num_components ; comp++) + { + WRITE_SWAPPED_DOUBLE(((unsigned char *) dest_data + comp*sizeof(*points)) - data_ptr, *(src_data + comp)); + } + dest_data += num_components; + src_data += ustride; + } + src_data += vstride - ustride*uorder; + } + + crHugePacket(CR_MAP2D_OPCODE, data_ptr); + crPackFree(data_ptr); +} + +void PACK_APIENTRY crPackMap2fSWAP(GLenum target, GLfloat u1, + GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, + GLint vstride, GLint vorder, const GLfloat *points) +{ + unsigned char *data_ptr; + int u,v; + int comp; + GLfloat *dest_data, *src_data; + int packet_length = + sizeof(target) + + sizeof(u1) + + sizeof(u2) + + sizeof(uorder) + + sizeof(ustride) + + sizeof(v1) + + sizeof(v2) + + sizeof(vorder) + + sizeof(vstride); + + int num_components = __gl_Map2NumComponents(target); + if (num_components < 0) + { + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackMap2f(bad target)"); + return; + } + + packet_length += num_components*uorder*vorder*sizeof(*points); + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + + WRITE_DATA(0, GLenum, SWAP32(target)); + WRITE_DATA(4, GLuint, SWAPFLOAT(u1)); + WRITE_DATA(8, GLuint, SWAPFLOAT(u2)); + WRITE_DATA(12, GLint, SWAP32(num_components)); + WRITE_DATA(16, GLint, SWAP32(uorder)); + WRITE_DATA(20, GLuint, SWAPFLOAT(v1)); + WRITE_DATA(24, GLuint, SWAPFLOAT(v2)); + WRITE_DATA(28, GLint, SWAP32(num_components*uorder)); + WRITE_DATA(32, GLint, SWAP32(vorder)); + + dest_data = (GLfloat *) (data_ptr + 36); + src_data = (GLfloat *) points; + for (v = 0 ; v < vorder ; v++) + { + for (u = 0 ; u < uorder ; u++) + { + for (comp = 0 ; comp < num_components ; comp++) + { + WRITE_DATA((unsigned char *) dest_data + comp*sizeof(*points) - data_ptr, GLuint, SWAPFLOAT(*(src_data + comp))); + } + dest_data += num_components; + src_data += ustride; + } + src_data += vstride - ustride*uorder; + } + + crHugePacket(CR_MAP2F_OPCODE, data_ptr); + crPackFree(data_ptr); +} + +void PACK_APIENTRY crPackMap1dSWAP(GLenum target, GLdouble u1, + GLdouble u2, GLint stride, GLint order, const GLdouble *points) +{ + unsigned char *data_ptr; + int packet_length = + sizeof(target) + + sizeof(u1) + + sizeof(u2) + + sizeof(stride) + + sizeof(order); + + int num_components = __gl_Map1NumComponents(target); + GLdouble *src_data, *dest_data; + int u; + int comp; + + if (num_components < 0) + { + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackMap1d(bad target)"); + return; + } + + packet_length += num_components * order * sizeof(*points); + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + + WRITE_DATA(0, GLenum, SWAP32(target)); + WRITE_SWAPPED_DOUBLE(4, u1); + WRITE_SWAPPED_DOUBLE(12, u2); + WRITE_DATA(20, GLint, SWAP32(num_components)); + WRITE_DATA(24, GLint, SWAP32(order)); + + dest_data = (GLdouble *) (data_ptr + 28); + src_data = (GLdouble *) points; + for (u = 0 ; u < order ; u++) + { + for (comp = 0 ; comp < num_components ; comp++) + { + WRITE_SWAPPED_DOUBLE((unsigned char *) dest_data + comp*sizeof(*points) - data_ptr, *(src_data + comp)); + } + dest_data += num_components; + src_data += stride; + } + + crHugePacket(CR_MAP1D_OPCODE, data_ptr); + crPackFree(data_ptr); +} + +void PACK_APIENTRY crPackMap1fSWAP(GLenum target, GLfloat u1, + GLfloat u2, GLint stride, GLint order, const GLfloat *points) +{ + unsigned char *data_ptr; + int packet_length = + sizeof(target) + + sizeof(u1) + + sizeof(u2) + + sizeof(stride) + + sizeof(order); + + int num_components = __gl_Map1NumComponents(target); + GLfloat *src_data, *dest_data; + int u; + int comp; + + if (num_components < 0) + { + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackMap1f(bad target)"); + return; + } + + packet_length += num_components * order * sizeof(*points); + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + + WRITE_DATA(0, GLenum, SWAP32(target)); + WRITE_DATA(4, GLuint, SWAPFLOAT(u1)); + WRITE_DATA(8, GLuint, SWAPFLOAT(u2)); + WRITE_DATA(12, GLint, SWAP32(num_components)); + WRITE_DATA(16, GLint, SWAP32(order)); + + dest_data = (GLfloat *) (data_ptr + 20); + src_data = (GLfloat *) points; + for (u = 0 ; u < order ; u++) + { + for (comp = 0 ; comp < num_components ; comp++) + { + WRITE_DATA((unsigned char *) dest_data + comp*sizeof(*points) - data_ptr, GLuint, SWAPFLOAT(*(src_data + comp))); + } + dest_data += num_components; + src_data += stride; + } + + crHugePacket(CR_MAP1F_OPCODE, data_ptr); + crPackFree(data_ptr); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_swap_pixelmap.c b/src/VBox/GuestHost/OpenGL/packer/pack_swap_pixelmap.c new file mode 100644 index 00000000..2336e8f8 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_swap_pixelmap.c @@ -0,0 +1,62 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" + +static unsigned char * __gl_HandlePixelMapData( GLenum map, GLsizei mapsize, int size_of_value, const GLvoid *values ) +{ + int i; + + int packet_length = + sizeof( map ) + + sizeof( mapsize ) + + mapsize*size_of_value; + unsigned char *data_ptr = (unsigned char *) crPackAlloc( packet_length ); + + WRITE_DATA( 0, GLenum, SWAP32(map) ); + WRITE_DATA( 4, GLsizei, SWAP32(mapsize) ); + + for (i = 0 ; i < mapsize ; i++) + { + switch( size_of_value ) + { + case 2: + WRITE_DATA( 8 + i*sizeof(GLshort), GLshort, SWAP16(*((GLshort *)values + i) )); + break; + case 4: + WRITE_DATA( 8 + i*sizeof(GLint), GLint, SWAP32(*((GLint *)values + i) )); + break; + } + } + return data_ptr; +} + +void PACK_APIENTRY crPackPixelMapfvSWAP(GLenum map, GLsizei mapsize, + const GLfloat *values ) +{ + unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values ); + + crHugePacket( CR_PIXELMAPFV_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackPixelMapuivSWAP(GLenum map, GLsizei mapsize, + const GLuint *values ) +{ + unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values ); + + crHugePacket( CR_PIXELMAPUIV_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackPixelMapusvSWAP(GLenum map, GLsizei mapsize, + const GLushort *values ) +{ + unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values ); + + crHugePacket( CR_PIXELMAPUSV_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_swap_texture.c b/src/VBox/GuestHost/OpenGL/packer/pack_swap_texture.c new file mode 100644 index 00000000..4fd59ed6 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_swap_texture.c @@ -0,0 +1,981 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_pixeldata.h" +#include "cr_error.h" +#include "cr_string.h" +#include "cr_version.h" + +void PACK_APIENTRY crPackTexImage1DSWAP(GLenum target, GLint level, + GLint internalformat, GLsizei width, GLint border, GLenum format, + GLenum type, const GLvoid *pixels, const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (pixels == NULL); + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( border ) + + sizeof( format ) + + sizeof( type ) + + sizeof( int ); + + if (pixels) + { + packet_length += crImageSize( format, type, width, 1 ); + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(target) ); + WRITE_DATA( 4, GLint, SWAP32(level) ); + WRITE_DATA( 8, GLint, SWAP32(internalformat) ); + WRITE_DATA( 12, GLsizei, SWAP32(width) ); + WRITE_DATA( 16, GLint, SWAP32(border) ); + WRITE_DATA( 20, GLenum, SWAP32(format) ); + WRITE_DATA( 24, GLenum, SWAP32(type) ); + WRITE_DATA( 28, int, SWAP32(isnull) ); + + if (pixels) { + CRPixelPackState tmpUnpackState = *unpackstate; + /* flip application-requested swapBytes state */ + tmpUnpackState.swapBytes = unpackstate->swapBytes ? GL_FALSE : GL_TRUE; + + crPixelCopy1D( (void *)(data_ptr + 32), format, type, + pixels, format, type, width, &tmpUnpackState ); + } + + crHugePacket( CR_TEXIMAGE1D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackTexImage2DSWAP(GLenum target, GLint level, + GLint internalformat, GLsizei width, GLsizei height, GLint border, + GLenum format, GLenum type, const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (pixels == NULL); + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( border ) + + sizeof( format ) + + sizeof( type ) + + sizeof( int ); + + if (pixels) + { + packet_length += crImageSize( format, type, width, height ); + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(target) ); + WRITE_DATA( 4, GLint, SWAP32(level) ); + WRITE_DATA( 8, GLint, SWAP32(internalformat) ); + WRITE_DATA( 12, GLsizei, SWAP32(width) ); + WRITE_DATA( 16, GLsizei, SWAP32(height) ); + WRITE_DATA( 20, GLint, SWAP32(border) ); + WRITE_DATA( 24, GLenum, SWAP32(format) ); + WRITE_DATA( 28, GLenum, SWAP32(type) ); + WRITE_DATA( 32, int, SWAP32(isnull) ); + + if (pixels) + { + CRPixelPackState tmpUnpackState = *unpackstate; + /* flip application-requested swapBytes state */ + tmpUnpackState.swapBytes = unpackstate->swapBytes ? GL_FALSE : GL_TRUE; + + crPixelCopy2D( width, height, + (void *)(data_ptr + 36), format, type, NULL, /* dst */ + pixels, format, type, &tmpUnpackState ); /* src */ + } + + crHugePacket( CR_TEXIMAGE2D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +#if defined( GL_EXT_texture3D ) +void PACK_APIENTRY crPackTexImage3DEXTSWAP(GLenum target, GLint level, + GLenum internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLint border, + GLenum format, GLenum type, const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (pixels == NULL); + int is_distrib = ( (type == GL_TRUE) || (type == GL_FALSE) ) ; + int distrib_buf_len = 0; + int tex_size = 0; + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( border ) + + sizeof( format ) + + sizeof( type ) + + sizeof( int ); + + if (pixels) + { + if ( is_distrib ) + { + distrib_buf_len = crStrlen( pixels ) + 1 + + ( (type == GL_TRUE) ? width*height*3 : 0 ) ; + packet_length += distrib_buf_len ; + } + else + { + tex_size = crTextureSize( format, type, width, height, depth ); + packet_length += tex_size; + } + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32( target ) ); + WRITE_DATA( 4, GLint, SWAP32( level ) ); + WRITE_DATA( 8, GLint, SWAP32( internalformat ) ); + WRITE_DATA( 12, GLsizei, SWAP32( width ) ); + WRITE_DATA( 16, GLsizei, SWAP32( height ) ); + WRITE_DATA( 20, GLsizei, SWAP32( depth ) ); + WRITE_DATA( 24, GLint, SWAP32( border ) ); + WRITE_DATA( 28, GLenum, SWAP32( format ) ); + WRITE_DATA( 32, GLenum, SWAP32( type ) ); + WRITE_DATA( 36, int, SWAP32( isnull ) ); + + if (pixels) + { + if ( is_distrib ) + { + crMemcpy( (void*)(data_ptr + 40), pixels, distrib_buf_len ) ; + } + else + { + CRPixelPackState tmpUnpackState = *unpackstate; + /* flip application-requested swapBytes state */ + tmpUnpackState.swapBytes = unpackstate->swapBytes ? GL_FALSE : GL_TRUE; + + crPixelCopy3D( width, height, depth, + (void *)(data_ptr + 40), format, type, NULL, + pixels, format, type, &tmpUnpackState ); + } + } + + crHugePacket( CR_TEXIMAGE3DEXT_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} +#endif /* GL_EXT_texture3D */ + +#ifdef CR_OPENGL_VERSION_1_2 +void PACK_APIENTRY crPackTexImage3DSWAP(GLenum target, GLint level, + GLint internalformat, + GLsizei width, GLsizei height, + GLsizei depth, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (pixels == NULL); + int is_distrib = ( (type == GL_TRUE) || (type == GL_FALSE) ) ; + int distrib_buf_len = 0; + int tex_size = 0; + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( border ) + + sizeof( format ) + + sizeof( type ) + + sizeof( int ); + + if (pixels) + { + if ( is_distrib ) + { + distrib_buf_len = crStrlen( pixels ) + 1 + + ( (type == GL_TRUE) ? width*height*3 : 0 ) ; + packet_length += distrib_buf_len ; + } + else + { + tex_size = crTextureSize( format, type, width, height, depth ); + packet_length += tex_size; + } + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32( target ) ); + WRITE_DATA( 4, GLint, SWAP32( level ) ); + WRITE_DATA( 8, GLint, SWAP32( internalformat ) ); + WRITE_DATA( 12, GLsizei, SWAP32( width ) ); + WRITE_DATA( 16, GLsizei, SWAP32( height ) ); + WRITE_DATA( 20, GLsizei, SWAP32( depth ) ); + WRITE_DATA( 24, GLint, SWAP32( border ) ); + WRITE_DATA( 28, GLenum, SWAP32( format ) ); + WRITE_DATA( 32, GLenum, SWAP32( type ) ); + WRITE_DATA( 36, int, SWAP32( isnull ) ); + + if (pixels) + { + if ( is_distrib ) + { + crMemcpy( (void*)(data_ptr + 40), pixels, distrib_buf_len ) ; + } + else + { + CRPixelPackState tmpUnpackState = *unpackstate; + /* flip application-requested swapBytes state */ + tmpUnpackState.swapBytes = unpackstate->swapBytes ? GL_FALSE : GL_TRUE; + + crPixelCopy3D( width, height, depth, + (void *)(data_ptr + 40), format, type, NULL, + pixels, format, type, &tmpUnpackState ); + } + } + + crHugePacket( CR_TEXIMAGE3D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} +#endif /* CR_OPENGL_VERSION_1_2 */ + + +void PACK_APIENTRY crPackDeleteTexturesSWAP( GLsizei n, const GLuint *textures ) +{ + unsigned char *data_ptr; + int i; + + int packet_length = + sizeof( n ) + + n*sizeof( *textures ); + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLsizei, SWAP32(n) ); + + for ( i = 0 ; i < n ; i++) + { + WRITE_DATA( i*sizeof(int) + 4, GLint, SWAP32(textures[i]) ); + } + crHugePacket( CR_DELETETEXTURES_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +static void __handleTexEnvData( GLenum target, GLenum pname, const GLfloat *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int num_params; + int i; + + int packet_length = + sizeof( int ) + + sizeof( target ) + + sizeof( pname ); + + num_params = 1; + if ( pname == GL_TEXTURE_ENV_COLOR ) + { + num_params = 4; + } + + packet_length += num_params*sizeof(*params); + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, int, SWAP32(packet_length) ); + WRITE_DATA( sizeof( int ) + 0, GLenum, SWAP32(target) ); + WRITE_DATA( sizeof( int ) + 4, GLenum, SWAP32(pname) ); + for ( i = 0 ; i < num_params ; i++) + { + WRITE_DATA( (i+1)*sizeof( int ) + 8, GLuint, SWAPFLOAT( params[i] ) ); + } +} + + +void PACK_APIENTRY crPackTexEnvfvSWAP( GLenum target, GLenum pname, + const GLfloat *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleTexEnvData( target, pname, params ); + WRITE_OPCODE( pc, CR_TEXENVFV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackTexEnvivSWAP( GLenum target, GLenum pname, + const GLint *params ) +{ + /* floats and ints are the same size, so the packing should be the same */ + CR_GET_PACKER_CONTEXT(pc); + __handleTexEnvData( target, pname, (const GLfloat *) params ); + WRITE_OPCODE( pc, CR_TEXENVIV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackTexEnviSWAP( GLenum target, GLenum pname, GLint param ) +{ + crPackTexEnvivSWAP( target, pname, ¶m ); +} + +void PACK_APIENTRY crPackTexEnvfSWAP( GLenum target, GLenum pname, GLfloat param ) +{ + crPackTexEnvfvSWAP( target, pname, ¶m ); +} + +void PACK_APIENTRY crPackPrioritizeTexturesSWAP( GLsizei n, + const GLuint *textures, const GLclampf *priorities ) +{ + unsigned char *data_ptr; + int packet_length = + sizeof( n ) + + n*sizeof( *textures ) + + n*sizeof( *priorities ); + int i; + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLsizei, SWAP32(n) ); + for ( i = 0 ; i < n ; i++) + { + WRITE_DATA( i*sizeof(int) + 4, GLint, SWAP32(textures[i])); + } + for ( i = 0 ; i < n ; i++) + { + WRITE_DATA( i*sizeof(int) + 4 + n*sizeof( *textures ), + GLuint, SWAPFLOAT(priorities[i])); + } + + crHugePacket( CR_PRIORITIZETEXTURES_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +static void __handleTexGenData( GLenum coord, GLenum pname, + int sizeof_param, const GLvoid *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof( int ) + sizeof( coord ) + sizeof( pname ); + int num_params = 1; + int i; + if (pname == GL_OBJECT_PLANE || pname == GL_EYE_PLANE) + { + num_params = 4; + } + packet_length += num_params * sizeof_param; + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, int, SWAP32(packet_length) ); + WRITE_DATA( sizeof( int ) + 0, GLenum, SWAP32(coord) ); + WRITE_DATA( sizeof( int ) + 4, GLenum, SWAP32(pname) ); + for ( i = 0 ; i < num_params ; i++) + { + WRITE_DATA( (i+1)*sizeof( int ) + 8, GLint, SWAP32(((GLint *)params)[i]) ); + } +} + +void PACK_APIENTRY crPackTexGendvSWAP( GLenum coord, GLenum pname, + const GLdouble *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleTexGenData( coord, pname, sizeof( *params ), params ); + WRITE_OPCODE( pc, CR_TEXGENDV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackTexGenfvSWAP( GLenum coord, GLenum pname, + const GLfloat *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleTexGenData( coord, pname, sizeof( *params ), params ); + WRITE_OPCODE( pc, CR_TEXGENFV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackTexGenivSWAP( GLenum coord, GLenum pname, + const GLint *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleTexGenData( coord, pname, sizeof( *params ), params ); + WRITE_OPCODE( pc, CR_TEXGENIV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackTexGendSWAP( GLenum coord, GLenum pname, GLdouble param ) +{ + crPackTexGendvSWAP( coord, pname, ¶m ); +} + +void PACK_APIENTRY crPackTexGenfSWAP( GLenum coord, GLenum pname, GLfloat param ) +{ + crPackTexGenfvSWAP( coord, pname, ¶m ); +} + +void PACK_APIENTRY crPackTexGeniSWAP( GLenum coord, GLenum pname, GLint param ) +{ + crPackTexGenivSWAP( coord, pname, ¶m ); +} + +static GLboolean __handleTexParameterData( GLenum target, GLenum pname, const GLfloat *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof( int ) + sizeof( target ) + sizeof( pname ); + int num_params = 0; + int i; + + switch( pname ) + { + + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_WRAP_R: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: +#ifdef GL_TEXTURE_PRIORITY + case GL_TEXTURE_PRIORITY: +#endif + num_params = 1; + break; + case GL_TEXTURE_MAX_ANISOTROPY_EXT: + num_params = 1; + break; + case GL_TEXTURE_MIN_LOD: + case GL_TEXTURE_MAX_LOD: + case GL_TEXTURE_BASE_LEVEL: + case GL_TEXTURE_MAX_LEVEL: + num_params = 1; + break; + case GL_TEXTURE_BORDER_COLOR: + num_params = 4; + break; +#ifdef CR_ARB_shadow + case GL_TEXTURE_COMPARE_MODE_ARB: + case GL_TEXTURE_COMPARE_FUNC_ARB: + num_params = 1; + break; +#endif +#ifdef CR_ARB_shadow_ambient + case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB: + num_params = 1; + break; +#endif +#ifdef CR_ARB_depth_texture + case GL_DEPTH_TEXTURE_MODE_ARB: + num_params = 1; + break; +#endif +#ifdef CR_SGIS_generate_mipmap + case GL_GENERATE_MIPMAP_SGIS: + num_params = 1; + break; +#endif + default: + num_params = __packTexParameterNumParams( pname ); + if (!num_params) + { + __PackError( __LINE__, __FILE__, GL_INVALID_ENUM, + "crPackTexParameter(bad pname)" ); + return GL_FALSE; + } + } + packet_length += num_params * sizeof(*params); + + CR_GET_BUFFERED_POINTER(pc, packet_length ); + WRITE_DATA( 0, int, SWAP32(packet_length) ); + WRITE_DATA( sizeof( int ) + 0, GLenum, SWAP32(target) ); + WRITE_DATA( sizeof( int ) + 4, GLenum, SWAP32(pname) ); + for ( i = 0 ; i < num_params ; i++) + { + WRITE_DATA( (i+1)*sizeof( int ) + 8, GLuint, SWAPFLOAT(params[i]) ); + } + return GL_TRUE; +} + +void PACK_APIENTRY crPackTexParameterfvSWAP( GLenum target, GLenum pname, + const GLfloat *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handleTexParameterData( target, pname, params )) + WRITE_OPCODE( pc, CR_TEXPARAMETERFV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackTexParameterivSWAP( GLenum target, GLenum pname, + const GLint *params ) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handleTexParameterData( target, pname, (GLfloat *) params )) + WRITE_OPCODE( pc, CR_TEXPARAMETERIV_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackTexParameterfSWAP( GLenum target, GLenum pname, GLfloat param ) +{ + crPackTexParameterfvSWAP( target, pname, ¶m ); +} + +void PACK_APIENTRY crPackTexParameteriSWAP( GLenum target, GLenum pname, GLint param ) +{ + crPackTexParameterivSWAP( target, pname, ¶m ); +} + +#ifdef CR_OPENGL_VERSION_1_2 +void PACK_APIENTRY crPackTexSubImage3DSWAP (GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( yoffset ) + + sizeof( zoffset ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( format ) + + sizeof( type ) + + crTextureSize( format, type, width, height, depth ); + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(target) ); + WRITE_DATA( 4, GLint, SWAP32(level) ); + WRITE_DATA( 8, GLint, SWAP32(xoffset) ); + WRITE_DATA( 12, GLint, SWAP32(yoffset) ); + WRITE_DATA( 16, GLint, SWAP32(zoffset) ); + WRITE_DATA( 20, GLsizei, SWAP32(width) ); + WRITE_DATA( 24, GLsizei, SWAP32(height) ); + WRITE_DATA( 28, GLsizei, SWAP32(depth) ); + WRITE_DATA( 32, GLenum, SWAP32(format) ); + WRITE_DATA( 36, GLenum, SWAP32(type) ); + + crPixelCopy3D( width, height, depth, + (GLvoid *) (data_ptr + 36), format, type, NULL, /* dst */ + pixels, format, type, unpackstate ); /* src */ + + crHugePacket( CR_TEXSUBIMAGE3D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} +#endif /* CR_OPENGL_VERSION_1_2 */ + +void PACK_APIENTRY crPackTexSubImage2DSWAP (GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, + GLenum format, GLenum type, const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + + CRPixelPackState tmpUnpackState = *unpackstate; + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( yoffset ) + + sizeof( width ) + + sizeof( height ) + + sizeof( format ) + + sizeof( type ) + + crImageSize( format, type, width, height ); + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(target) ); + WRITE_DATA( 4, GLint, SWAP32(level) ); + WRITE_DATA( 8, GLint, SWAP32(xoffset) ); + WRITE_DATA( 12, GLint, SWAP32(yoffset) ); + WRITE_DATA( 16, GLsizei, SWAP32(width) ); + WRITE_DATA( 20, GLsizei, SWAP32(height) ); + WRITE_DATA( 24, GLenum, SWAP32(format) ); + WRITE_DATA( 28, GLenum, SWAP32(type) ); + + /* flip application-requested swapBytes state */ + tmpUnpackState.swapBytes = unpackstate->swapBytes ? GL_FALSE : GL_TRUE; + + crPixelCopy2D( width, height, + (GLvoid *) (data_ptr + 32), format, type, NULL, /* dst */ + pixels, format, type, &tmpUnpackState ); /* src */ + + crHugePacket( CR_TEXSUBIMAGE2D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackTexSubImage1DSWAP (GLenum target, GLint level, + GLint xoffset, GLsizei width, GLenum format, GLenum type, + const GLvoid *pixels, const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + CRPixelPackState tmpUnpackState = *unpackstate; + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( width ) + + sizeof( format ) + + sizeof( type ) + + crImageSize( format, type, width, 1 ); + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(target) ); + WRITE_DATA( 4, GLint, SWAP32(level) ); + WRITE_DATA( 8, GLint, SWAP32(xoffset) ); + WRITE_DATA( 12, GLsizei, SWAP32(width) ); + WRITE_DATA( 16, GLenum, SWAP32(format) ); + WRITE_DATA( 20, GLenum, SWAP32(type) ); + + /* flip application-requested swapBytes state */ + tmpUnpackState.swapBytes = unpackstate->swapBytes ? GL_FALSE : GL_TRUE; + + crPixelCopy1D((GLvoid *) (data_ptr + 24), format, type, + pixels, format, type, width, &tmpUnpackState ); + + crHugePacket( CR_TEXSUBIMAGE1D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackAreTexturesResidentSWAP( GLsizei n, const GLuint *textures, GLboolean *residences, GLboolean *return_val, int *writeback ) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length; + int i; + + packet_length = + sizeof( int ) + /* packet length */ + sizeof( GLenum ) + /* extend-o opcode */ + sizeof( n ) + /* num_textures */ + n*sizeof( *textures ) + /* textures */ + 8 + 8 + 8; /* return pointers */ + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA( 0, int, SWAP32(packet_length) ); + WRITE_DATA( sizeof( int ) + 0, GLenum, SWAP32(CR_ARETEXTURESRESIDENT_EXTEND_OPCODE) ); + WRITE_DATA( sizeof( int ) + 4, GLsizei, SWAP32(n) ); + for (i = 0 ; i < n ; i++) + { + WRITE_DATA( (i+1)*sizeof( int ) + 8, GLuint, SWAP32(textures[i]) ); + } + WRITE_NETWORK_POINTER( sizeof( int ) + 8 + n*sizeof( *textures ), (void *) residences ); + WRITE_NETWORK_POINTER( sizeof( int ) + 16 + n*sizeof( *textures ), (void *) return_val ); + WRITE_NETWORK_POINTER( sizeof( int ) + 24 + n*sizeof( *textures ), (void *) writeback ); + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +/********************************************************************** + * Texture compression + */ + +void PACK_APIENTRY crPackCompressedTexImage1DARBSWAP( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (data == NULL); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( border ) + + sizeof( imagesize ) + + sizeof( int ); + + if (data) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(CR_COMPRESSEDTEXIMAGE1DARB_EXTEND_OPCODE) ); + WRITE_DATA( 4, GLenum, SWAP32(target) ); + WRITE_DATA( 8, GLint, SWAP32(level) ); + WRITE_DATA( 12, GLint, SWAP32(internalformat) ); + WRITE_DATA( 16, GLsizei, SWAP32(width) ); + WRITE_DATA( 20, GLint, SWAP32(border) ); + WRITE_DATA( 24, GLsizei, SWAP32(imagesize) ); + WRITE_DATA( 28, int, SWAP32(isnull) ); + + if (data) { + crMemcpy( (void *)(data_ptr + 32), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexImage2DARBSWAP( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (data == NULL); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( border ) + + sizeof( imagesize ) + + sizeof( int ); /* isnull */ + + if (data) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(CR_COMPRESSEDTEXIMAGE2DARB_EXTEND_OPCODE) ); + WRITE_DATA( 4, GLenum, SWAP32(target) ); + WRITE_DATA( 8, GLint, SWAP32(level) ); + WRITE_DATA( 12, GLint, SWAP32(internalformat) ); + WRITE_DATA( 16, GLsizei, SWAP32(width) ); + WRITE_DATA( 20, GLsizei, SWAP32(height) ); + WRITE_DATA( 24, GLint, SWAP32(border) ); + WRITE_DATA( 28, GLsizei, SWAP32(imagesize) ); + WRITE_DATA( 32, int, SWAP32(isnull) ); + + if (data) { + crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexImage3DARBSWAP( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (data == NULL); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( border ) + + sizeof( imagesize ) + + sizeof( int ); /* isnull */ + + if (data) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(CR_COMPRESSEDTEXIMAGE3DARB_EXTEND_OPCODE) ); + WRITE_DATA( 4, GLenum, SWAP32(target) ); + WRITE_DATA( 8, GLint, SWAP32(level) ); + WRITE_DATA( 12, GLint, SWAP32(internalformat) ); + WRITE_DATA( 16, GLsizei, SWAP32(width) ); + WRITE_DATA( 20, GLsizei, SWAP32(height) ); + WRITE_DATA( 24, GLsizei, SWAP32(depth) ); + WRITE_DATA( 28, GLint, SWAP32(border) ); + WRITE_DATA( 32, GLsizei, SWAP32(imagesize) ); + WRITE_DATA( 36, int, SWAP32(isnull) ); + + if (data) { + crMemcpy( (void *)(data_ptr + 40), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexSubImage1DARBSWAP( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (data == NULL); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( width ) + + sizeof( format ) + + sizeof( imagesize ) + + sizeof( int ); /* isnull */ + + if (data) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(CR_COMPRESSEDTEXSUBIMAGE1DARB_EXTEND_OPCODE) ); + WRITE_DATA( 4, GLenum, SWAP32(target) ); + WRITE_DATA( 8, GLint, SWAP32(level) ); + WRITE_DATA( 12, GLint, SWAP32(xoffset) ); + WRITE_DATA( 16, GLsizei, SWAP32(width) ); + WRITE_DATA( 20, GLenum, SWAP32(format) ); + WRITE_DATA( 24, GLsizei, SWAP32(imagesize) ); + WRITE_DATA( 28, int, SWAP32(isnull) ); + + if (data) { + crMemcpy( (void *)(data_ptr + 32), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexSubImage2DARBSWAP( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (data == NULL); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( yoffset ) + + sizeof( width ) + + sizeof( height ) + + sizeof( format ) + + sizeof( imagesize ) + + sizeof( int ); /* isnull */ + + if (data) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(CR_COMPRESSEDTEXSUBIMAGE2DARB_EXTEND_OPCODE) ); + WRITE_DATA( 4, GLenum, SWAP32(target) ); + WRITE_DATA( 8, GLint, SWAP32(level) ); + WRITE_DATA( 12, GLint, SWAP32(xoffset) ); + WRITE_DATA( 16, GLint, SWAP32(yoffset) ); + WRITE_DATA( 20, GLsizei, SWAP32(width) ); + WRITE_DATA( 24, GLsizei, SWAP32(height) ); + WRITE_DATA( 28, GLenum, SWAP32(format) ); + WRITE_DATA( 32, GLsizei, SWAP32(imagesize) ); + WRITE_DATA( 36, int, SWAP32(isnull) ); + + if (data) { + crMemcpy( (void *)(data_ptr + 40), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexSubImage3DARBSWAP( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int isnull = (data == NULL); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( yoffset ) + + sizeof( zoffset ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( format ) + + sizeof( imagesize ) + + sizeof( int ); /* isnull */ + + if (data) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, SWAP32(CR_COMPRESSEDTEXSUBIMAGE3DARB_EXTEND_OPCODE) ); + WRITE_DATA( 4, GLenum, SWAP32(target) ); + WRITE_DATA( 8, GLint, SWAP32(level) ); + WRITE_DATA( 12, GLint, SWAP32(xoffset) ); + WRITE_DATA( 16, GLint, SWAP32(yoffset) ); + WRITE_DATA( 20, GLint, SWAP32(zoffset) ); + WRITE_DATA( 24, GLsizei, SWAP32(width) ); + WRITE_DATA( 28, GLsizei, SWAP32(height) ); + WRITE_DATA( 32, GLsizei, SWAP32(depth) ); + WRITE_DATA( 36, GLenum, SWAP32(format) ); + WRITE_DATA( 40, GLsizei, SWAP32(imagesize) ); + WRITE_DATA( 44, int, SWAP32(isnull) ); + + if (data) { + crMemcpy( (void *)(data_ptr + 48), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackGetCompressedTexImageARBSWAP( GLenum target, GLint level, GLvoid *img, int *writeback ) +{ + CR_GET_PACKER_CONTEXT(pc); + crError ( "GetCompressedTexImageARB needs to be special cased!"); + (void) pc; + (void) target; + (void) level; + (void) img; + (void) writeback; +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_texture.c b/src/VBox/GuestHost/OpenGL/packer/pack_texture.c new file mode 100644 index 00000000..6b33b1c4 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_texture.c @@ -0,0 +1,1030 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#include "packer.h" +#include "cr_pixeldata.h" +#include "cr_error.h" +#include "cr_string.h" +#include "cr_version.h" +#include "cr_glstate.h" + +void PACK_APIENTRY +crPackTexImage1D(GLenum target, GLint level, + GLint internalformat, GLsizei width, GLint border, + GLenum format, GLenum type, const GLvoid * pixels, + const CRPixelPackState * unpackstate) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + packet_length = + sizeof(target) + + sizeof(level) + + sizeof(internalformat) + + sizeof(width) + + sizeof(border) + sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += crImageSize(format, type, width, 1); + } + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, target); + WRITE_DATA(4, GLint, level); + WRITE_DATA(8, GLint, internalformat); + WRITE_DATA(12, GLsizei, width); + WRITE_DATA(16, GLint, border); + WRITE_DATA(20, GLenum, format); + WRITE_DATA(24, GLenum, type); + WRITE_DATA(28, int, noimagedata); + WRITE_DATA(32, GLint, (GLint)(uintptr_t) pixels); + + if (!noimagedata) + { + crPixelCopy1D((void *) (data_ptr + 36), format, type, + pixels, format, type, width, unpackstate); + } + + crHugePacket(CR_TEXIMAGE1D_OPCODE, data_ptr); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY +crPackTexImage2D(GLenum target, GLint level, + GLint internalformat, GLsizei width, GLsizei height, + GLint border, GLenum format, GLenum type, + const GLvoid * pixels, const CRPixelPackState * unpackstate) +{ + unsigned char *data_ptr; + int packet_length; + const int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + const int is_distrib = ((type == GL_TRUE) || (type == GL_FALSE)); + int distrib_buf_len = 0; + + packet_length = + sizeof(target) + + sizeof(level) + + sizeof(internalformat) + + sizeof(width) + + sizeof(height) + + sizeof(border) + sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint); + + if (!noimagedata) + { + if (is_distrib) + { + /* Pixels is a zero-terminated filename, followed by the usual image + * data if type == GL_TRUE. + * Also note that the image data can't have any unusual pixel packing + * parameters. + */ + CRASSERT(format == GL_RGB); + distrib_buf_len = crStrlen(pixels) + 1 + + ((type == GL_TRUE) ? width * height * 3 : 0); + packet_length += distrib_buf_len; + } + else + { + packet_length += crImageSize(format, type, width, height); + } + } + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, target); + WRITE_DATA(4, GLint, level); + WRITE_DATA(8, GLint, internalformat); + WRITE_DATA(12, GLsizei, width); + WRITE_DATA(16, GLsizei, height); + WRITE_DATA(20, GLint, border); + WRITE_DATA(24, GLenum, format); + WRITE_DATA(28, GLenum, type); + WRITE_DATA(32, int, noimagedata); + WRITE_DATA(36, GLint, (GLint)(uintptr_t) pixels); + + if (!noimagedata) + { + if (is_distrib) + { + crMemcpy((void *) (data_ptr + 40), pixels, distrib_buf_len); + } + else + { + crPixelCopy2D(width, height, + (void *) (data_ptr + 40), /* dest image addr */ + format, type, /* dest image format/type */ + NULL, /* dst packing (use default params) */ + pixels, /* src image addr */ + format, type, /* src image format/type */ + unpackstate); /* src packing */ + } + } + + crHugePacket(CR_TEXIMAGE2D_OPCODE, data_ptr); + crPackFree( data_ptr ); +} + +#if defined( GL_EXT_texture3D ) +void PACK_APIENTRY +crPackTexImage3DEXT(GLenum target, GLint level, + GLenum internalformat, + GLsizei width, GLsizei height, GLsizei depth, GLint border, + GLenum format, GLenum type, const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + int is_distrib = ( (type == GL_TRUE) || (type == GL_FALSE) ) ; + int distrib_buf_len = 0; + int tex_size = 0; + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( border ) + + sizeof( format ) + + sizeof( type ) + + sizeof( int ) + sizeof(GLint); + + if (!noimagedata) + { + if ( is_distrib ) + { + distrib_buf_len = crStrlen( pixels ) + 1 + + ( (type == GL_TRUE) ? width*height*3 : 0 ) ; + packet_length += distrib_buf_len ; + } + else + { + tex_size = crTextureSize( format, type, width, height, depth ); + packet_length += tex_size; + } + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, target ); + WRITE_DATA( 4, GLint, level ); + WRITE_DATA( 8, GLint, internalformat ); + WRITE_DATA( 12, GLsizei, width ); + WRITE_DATA( 16, GLsizei, height ); + WRITE_DATA( 20, GLsizei, depth ); + WRITE_DATA( 24, GLint, border ); + WRITE_DATA( 28, GLenum, format ); + WRITE_DATA( 32, GLenum, type ); + WRITE_DATA( 36, int, noimagedata ); + WRITE_DATA( 40, GLint, (GLint)(uintptr_t) pixels); + + if (!noimagedata) + { + if ( is_distrib ) + { + crMemcpy( (void*)(data_ptr + 44), pixels, distrib_buf_len ) ; + } + else + { + crPixelCopy3D( width, height, depth, + (void *)(data_ptr + 44), format, type, NULL, + pixels, format, type, unpackstate ); + } + } + + crHugePacket( CR_TEXIMAGE3DEXT_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} +#endif /* GL_EXT_texture3D */ + +#ifdef CR_OPENGL_VERSION_1_2 +void PACK_APIENTRY +crPackTexImage3D(GLenum target, GLint level, + GLint internalformat, + GLsizei width, GLsizei height, + GLsizei depth, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels, + const CRPixelPackState *unpackstate ) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + int is_distrib = ( (type == GL_TRUE) || (type == GL_FALSE) ) ; + int distrib_buf_len = 0; + int tex_size = 0; + + packet_length = + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( border ) + + sizeof( format ) + + sizeof( type ) + + sizeof( int ) + sizeof(GLint); + + if (!noimagedata) + { + if ( is_distrib ) + { + distrib_buf_len = crStrlen( pixels ) + 1 + + ( (type == GL_TRUE) ? width*height*3 : 0 ) ; + packet_length += distrib_buf_len ; + } + else + { + tex_size = crTextureSize( format, type, width, height, depth ); + packet_length += tex_size; + } + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, target ); + WRITE_DATA( 4, GLint, level ); + WRITE_DATA( 8, GLint, internalformat ); + WRITE_DATA( 12, GLsizei, width ); + WRITE_DATA( 16, GLsizei, height ); + WRITE_DATA( 20, GLsizei, depth ); + WRITE_DATA( 24, GLint, border ); + WRITE_DATA( 28, GLenum, format ); + WRITE_DATA( 32, GLenum, type ); + WRITE_DATA( 36, int, noimagedata ); + WRITE_DATA( 40, GLint, (GLint)(uintptr_t) pixels); + + if (!noimagedata) + { + if ( is_distrib ) + { + crMemcpy( (void*)(data_ptr + 44), pixels, distrib_buf_len ) ; + } + else + { + crPixelCopy3D( width, height, depth, + (void *)(data_ptr + 44), format, type, NULL, + pixels, format, type, unpackstate ); + } + } + + crHugePacket( CR_TEXIMAGE3D_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} +#endif /* CR_OPENGL_VERSION_1_2 */ + + +void PACK_APIENTRY +crPackDeleteTextures(GLsizei n, const GLuint * textures) +{ + unsigned char *data_ptr; + int packet_length = + sizeof( n ) + + n * sizeof( *textures ); + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLsizei, n); + crMemcpy(data_ptr + 4, textures, n * sizeof(*textures)); + crHugePacket(CR_DELETETEXTURES_OPCODE, data_ptr); + crPackFree( data_ptr ); +} + +static void +__handleTexEnvData(GLenum target, GLenum pname, const GLfloat * params) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int params_length; + + int packet_length = + sizeof( int ) + + sizeof( target ) + + sizeof( pname ); + + if (pname == GL_TEXTURE_ENV_COLOR) + { + params_length = 4 * sizeof(*params); + } + else + { + params_length = sizeof(*params); + } + + packet_length += params_length; + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(sizeof(int) + 0, GLenum, target); + WRITE_DATA(sizeof(int) + 4, GLenum, pname); + crMemcpy(data_ptr + sizeof(int) + 8, params, params_length); +} + + +void PACK_APIENTRY +crPackTexEnvfv(GLenum target, GLenum pname, const GLfloat * params) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleTexEnvData(target, pname, params); + WRITE_OPCODE(pc, CR_TEXENVFV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY +crPackTexEnviv(GLenum target, GLenum pname, const GLint * params) +{ + /* floats and ints are the same size, so the packing should be the same */ + CR_GET_PACKER_CONTEXT(pc); + __handleTexEnvData(target, pname, (const GLfloat *) params); + WRITE_OPCODE(pc, CR_TEXENVIV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY +crPackTexEnvf(GLenum target, GLenum pname, GLfloat param) +{ + crPackTexEnvfv(target, pname, ¶m); +} + +void PACK_APIENTRY +crPackTexEnvi(GLenum target, GLenum pname, GLint param) +{ + crPackTexEnviv(target, pname, ¶m); +} + +void PACK_APIENTRY +crPackPrioritizeTextures(GLsizei n, const GLuint * textures, + const GLclampf * priorities) +{ + unsigned char *data_ptr; + int packet_length = + sizeof(n) + + n * sizeof(*textures) + + n * sizeof(*priorities); + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + + WRITE_DATA(0, GLsizei, n); + crMemcpy(data_ptr + 4, textures, n * sizeof(*textures)); + crMemcpy(data_ptr + 4 + n * sizeof(*textures), + priorities, n * sizeof(*priorities)); + + crHugePacket(CR_PRIORITIZETEXTURES_OPCODE, data_ptr); + crPackFree( data_ptr ); +} + +static void +__handleTexGenData(GLenum coord, GLenum pname, + int sizeof_param, const GLvoid * params) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = + sizeof(int) + sizeof(coord) + sizeof(pname) + sizeof_param; + int params_length = sizeof_param; + if (pname == GL_OBJECT_PLANE || pname == GL_EYE_PLANE) + { + packet_length += 3 * sizeof_param; + params_length += 3 * sizeof_param; + } + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(sizeof(int) + 0, GLenum, coord); + WRITE_DATA(sizeof(int) + 4, GLenum, pname); + crMemcpy(data_ptr + sizeof(int) + 8, params, params_length); +} + +void PACK_APIENTRY +crPackTexGendv(GLenum coord, GLenum pname, const GLdouble * params) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleTexGenData(coord, pname, sizeof(*params), params); + WRITE_OPCODE(pc, CR_TEXGENDV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY +crPackTexGenfv(GLenum coord, GLenum pname, const GLfloat * params) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleTexGenData(coord, pname, sizeof(*params), params); + WRITE_OPCODE(pc, CR_TEXGENFV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY +crPackTexGeniv(GLenum coord, GLenum pname, const GLint * params) +{ + CR_GET_PACKER_CONTEXT(pc); + __handleTexGenData(coord, pname, sizeof(*params), params); + WRITE_OPCODE(pc, CR_TEXGENIV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY +crPackTexGend(GLenum coord, GLenum pname, GLdouble param) +{ + crPackTexGendv(coord, pname, ¶m); +} + +void PACK_APIENTRY +crPackTexGenf(GLenum coord, GLenum pname, GLfloat param) +{ + crPackTexGenfv(coord, pname, ¶m); +} + +void PACK_APIENTRY +crPackTexGeni(GLenum coord, GLenum pname, GLint param) +{ + crPackTexGeniv(coord, pname, ¶m); +} + +static GLboolean +__handleTexParameterData(GLenum target, GLenum pname, const GLfloat * params) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length = sizeof(int) + sizeof(target) + sizeof(pname); + int num_params = 0; + + switch (pname) + { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_WRAP_R: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: +#ifdef GL_TEXTURE_PRIORITY + case GL_TEXTURE_PRIORITY: +#endif + num_params = 1; + break; + case GL_TEXTURE_MAX_ANISOTROPY_EXT: + num_params = 1; + break; + case GL_TEXTURE_MIN_LOD: + case GL_TEXTURE_MAX_LOD: + case GL_TEXTURE_BASE_LEVEL: + case GL_TEXTURE_MAX_LEVEL: + num_params = 1; + break; + case GL_TEXTURE_BORDER_COLOR: + num_params = 4; + break; +#ifdef CR_ARB_shadow + case GL_TEXTURE_COMPARE_MODE_ARB: + case GL_TEXTURE_COMPARE_FUNC_ARB: + num_params = 1; + break; +#endif +#ifdef CR_ARB_shadow_ambient + case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB: + num_params = 1; + break; +#endif +#ifdef CR_ARB_depth_texture + case GL_DEPTH_TEXTURE_MODE_ARB: + num_params = 1; + break; +#endif +#ifdef CR_SGIS_generate_mipmap + case GL_GENERATE_MIPMAP_SGIS: + num_params = 1; + break; +#endif + default: + num_params = __packTexParameterNumParams(pname); + if (!num_params) + { + __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, + "crPackTexParameter(bad pname)"); + return GL_FALSE; + } + } + packet_length += num_params * sizeof(*params); + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(sizeof(int) + 0, GLenum, target); + WRITE_DATA(sizeof(int) + 4, GLenum, pname); + crMemcpy(data_ptr + sizeof(int) + 8, params, num_params * sizeof(*params)); + return GL_TRUE; +} + +void PACK_APIENTRY +crPackTexParameterfv(GLenum target, GLenum pname, const GLfloat * params) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handleTexParameterData(target, pname, params)) + { + WRITE_OPCODE(pc, CR_TEXPARAMETERFV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); + } +} + +void PACK_APIENTRY +crPackTexParameteriv(GLenum target, GLenum pname, const GLint * params) +{ + CR_GET_PACKER_CONTEXT(pc); + if (__handleTexParameterData(target, pname, (GLfloat *) params)) + { + WRITE_OPCODE(pc, CR_TEXPARAMETERIV_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); + } +} + +void PACK_APIENTRY +crPackTexParameterf(GLenum target, GLenum pname, GLfloat param) +{ + crPackTexParameterfv(target, pname, ¶m); +} + +void PACK_APIENTRY +crPackTexParameteri(GLenum target, GLenum pname, GLint param) +{ + crPackTexParameteriv(target, pname, ¶m); +} + +#ifdef CR_OPENGL_VERSION_1_2 +void PACK_APIENTRY +crPackTexSubImage3D(GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid * pixels, + const CRPixelPackState * unpackstate) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + packet_length = + sizeof(target) + + sizeof(level) + + sizeof(xoffset) + + sizeof(yoffset) + + sizeof(zoffset) + + sizeof(width) + + sizeof(height) + + sizeof(depth) + + sizeof(format) + + sizeof(type) + sizeof(int) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += crTextureSize(format, type, width, height, depth); + } + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, target); + WRITE_DATA(4, GLint, level); + WRITE_DATA(8, GLint, xoffset); + WRITE_DATA(12, GLint, yoffset); + WRITE_DATA(16, GLint, zoffset); + WRITE_DATA(20, GLsizei, width); + WRITE_DATA(24, GLsizei, height); + WRITE_DATA(28, GLsizei, depth); + WRITE_DATA(32, GLenum, format); + WRITE_DATA(36, GLenum, type); + WRITE_DATA(40, GLint, noimagedata); + WRITE_DATA(44, GLint, (GLint)(uintptr_t) pixels); + + if (!noimagedata) + { + crPixelCopy3D(width, height, depth, (GLvoid *) (data_ptr + 48), format, type, NULL, /* dst */ + pixels, format, type, unpackstate); /* src */ + } + + crHugePacket(CR_TEXSUBIMAGE3D_OPCODE, data_ptr); + crPackFree( data_ptr ); +} +#endif /* CR_OPENGL_VERSION_1_2 */ + +void PACK_APIENTRY +crPackTexSubImage2D(GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLsizei width, + GLsizei height, GLenum format, GLenum type, + const GLvoid * pixels, + const CRPixelPackState * unpackstate) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + packet_length = + sizeof(target) + + sizeof(level) + + sizeof(xoffset) + + sizeof(yoffset) + + sizeof(width) + + sizeof(height) + + sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += crImageSize(format, type, width, height); + } + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, target); + WRITE_DATA(4, GLint, level); + WRITE_DATA(8, GLint, xoffset); + WRITE_DATA(12, GLint, yoffset); + WRITE_DATA(16, GLsizei, width); + WRITE_DATA(20, GLsizei, height); + WRITE_DATA(24, GLenum, format); + WRITE_DATA(28, GLenum, type); + WRITE_DATA(32, GLint, noimagedata); + WRITE_DATA(36, GLint, (GLint)(uintptr_t) pixels); + + if (!noimagedata) + { + crPixelCopy2D(width, height, (GLvoid *) (data_ptr + 40), format, type, NULL, /* dst */ + pixels, format, type, unpackstate); /* src */ + } + + crHugePacket(CR_TEXSUBIMAGE2D_OPCODE, data_ptr); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY +crPackTexSubImage1D(GLenum target, GLint level, + GLint xoffset, GLsizei width, GLenum format, GLenum type, + const GLvoid * pixels, + const CRPixelPackState * unpackstate) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + packet_length = + sizeof(target) + + sizeof(level) + + sizeof(xoffset) + + sizeof(width) + + sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += crImageSize(format, type, width, 1); + } + + data_ptr = (unsigned char *) crPackAlloc(packet_length); + WRITE_DATA(0, GLenum, target); + WRITE_DATA(4, GLint, level); + WRITE_DATA(8, GLint, xoffset); + WRITE_DATA(12, GLsizei, width); + WRITE_DATA(16, GLenum, format); + WRITE_DATA(20, GLenum, type); + WRITE_DATA(24, GLint, noimagedata); + WRITE_DATA(28, GLint, (GLint)(uintptr_t) pixels); + + if (!noimagedata) + { + crPixelCopy1D((GLvoid *) (data_ptr + 32), format, type, + pixels, format, type, width, unpackstate); + } + + crHugePacket(CR_TEXSUBIMAGE1D_OPCODE, data_ptr); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY +crPackAreTexturesResident(GLsizei n, const GLuint * textures, + GLboolean * residences, GLboolean * return_val, + int *writeback) +{ + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + int packet_length; + + (void) return_val; /* Caller must compute this from residences!!! */ + + packet_length = sizeof(int) + /* packet length */ + sizeof(GLenum) + /* extend-o opcode */ + sizeof(n) + /* num_textures */ + n * sizeof(*textures) + /* textures */ + 8 + 8; + + CR_GET_BUFFERED_POINTER(pc, packet_length); + WRITE_DATA(0, int, packet_length); + WRITE_DATA(4, GLenum, CR_ARETEXTURESRESIDENT_EXTEND_OPCODE); + WRITE_DATA(8, GLsizei, n); + crMemcpy(data_ptr + 12, textures, n * sizeof(*textures)); + WRITE_NETWORK_POINTER(12 + n * sizeof(*textures), (void *) residences); + WRITE_NETWORK_POINTER(20 + n * sizeof(*textures), (void *) writeback); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_CMDBLOCK_CHECK_FLUSH(pc); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + + +/********************************************************************** + * Texture compression + */ + +void PACK_APIENTRY crPackCompressedTexImage1DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( border ) + + sizeof( imagesize ) + + sizeof( int ) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += imagesize; + } + + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE1DARB_EXTEND_OPCODE ); + WRITE_DATA( 4, GLenum, target ); + WRITE_DATA( 8, GLint, level ); + WRITE_DATA( 12, GLint, internalformat ); + WRITE_DATA( 16, GLsizei, width ); + WRITE_DATA( 20, GLint, border ); + WRITE_DATA( 24, GLsizei, imagesize ); + WRITE_DATA( 28, int, noimagedata ); + WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data); + + if (!noimagedata) { + crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexImage2DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( border ) + + sizeof( imagesize ) + + sizeof( int ) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += imagesize; + } + + /*crDebug( "Compressing that shit: %d", level );*/ + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE2DARB_EXTEND_OPCODE ); + WRITE_DATA( 4, GLenum, target ); + WRITE_DATA( 8, GLint, level ); + WRITE_DATA( 12, GLint, internalformat ); + WRITE_DATA( 16, GLsizei, width ); + WRITE_DATA( 20, GLsizei, height ); + WRITE_DATA( 24, GLint, border ); + WRITE_DATA( 28, GLsizei, imagesize ); + WRITE_DATA( 32, int, noimagedata ); + WRITE_DATA( 36, GLint, (GLint)(uintptr_t) data); + + if (!noimagedata) { + crMemcpy( (void *)(data_ptr + 40), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexImage3DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( internalformat ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( border ) + + sizeof( imagesize ) + + sizeof( int ) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE3DARB_EXTEND_OPCODE ); + WRITE_DATA( 4, GLenum, target ); + WRITE_DATA( 8, GLint, level ); + WRITE_DATA( 12, GLint, internalformat ); + WRITE_DATA( 16, GLsizei, width ); + WRITE_DATA( 20, GLsizei, height ); + WRITE_DATA( 24, GLsizei, depth ); + WRITE_DATA( 28, GLint, border ); + WRITE_DATA( 32, GLsizei, imagesize ); + WRITE_DATA( 36, int, noimagedata ); + WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data); + + if (!noimagedata) { + crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexSubImage1DARB( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( width ) + + sizeof( format ) + + sizeof( imagesize ) + + sizeof( int ) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE1DARB_EXTEND_OPCODE ); + WRITE_DATA( 4, GLenum, target ); + WRITE_DATA( 8, GLint, level ); + WRITE_DATA( 12, GLint, xoffset ); + WRITE_DATA( 16, GLsizei, width ); + WRITE_DATA( 20, GLenum, format ); + WRITE_DATA( 24, GLsizei, imagesize ); + WRITE_DATA( 28, int, noimagedata ); + WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data); + + if (!noimagedata) { + crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexSubImage2DARB( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( yoffset ) + + sizeof( width ) + + sizeof( height ) + + sizeof( format ) + + sizeof( imagesize ) + + sizeof( int ) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE2DARB_EXTEND_OPCODE ); + WRITE_DATA( 4, GLenum, target ); + WRITE_DATA( 8, GLint, level ); + WRITE_DATA( 12, GLint, xoffset ); + WRITE_DATA( 16, GLint, yoffset ); + WRITE_DATA( 20, GLsizei, width ); + WRITE_DATA( 24, GLsizei, height ); + WRITE_DATA( 28, GLenum, format ); + WRITE_DATA( 32, GLsizei, imagesize ); + WRITE_DATA( 36, int, noimagedata ); + WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data); + + if (!noimagedata) { + crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackCompressedTexSubImage3DARB( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imagesize, const GLvoid *data ) +{ + unsigned char *data_ptr; + int packet_length; + int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB); + + /* All extended opcodes have their first 8 bytes predefined: + * the first four indicate the packet size, and the next four + * indicate the actual extended opcode. + */ + packet_length = + sizeof( GLenum) + /* extended opcode */ + sizeof( target ) + + sizeof( level ) + + sizeof( xoffset ) + + sizeof( yoffset ) + + sizeof( zoffset ) + + sizeof( width ) + + sizeof( height ) + + sizeof( depth ) + + sizeof( format ) + + sizeof( imagesize ) + + sizeof( int ) + sizeof(GLint); + + if (!noimagedata) + { + packet_length += imagesize; + } + + data_ptr = (unsigned char *) crPackAlloc( packet_length ); + WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE3DARB_EXTEND_OPCODE ); + WRITE_DATA( 4, GLenum, target ); + WRITE_DATA( 8, GLint, level ); + WRITE_DATA( 12, GLint, xoffset ); + WRITE_DATA( 16, GLint, yoffset ); + WRITE_DATA( 20, GLint, zoffset ); + WRITE_DATA( 24, GLsizei, width ); + WRITE_DATA( 28, GLsizei, height ); + WRITE_DATA( 32, GLsizei, depth ); + WRITE_DATA( 36, GLenum, format ); + WRITE_DATA( 40, GLsizei, imagesize ); + WRITE_DATA( 44, int, noimagedata ); + WRITE_DATA( 48, GLint, (GLint)(uintptr_t) data); + + if (!noimagedata) { + crMemcpy( (void *)(data_ptr + 52), (void *)data, imagesize); + } + + crHugePacket( CR_EXTEND_OPCODE, data_ptr ); + crPackFree( data_ptr ); +} + +void PACK_APIENTRY crPackGetCompressedTexImageARB( GLenum target, GLint level, GLvoid *img, int *writeback ) +{ + CR_GET_PACKER_CONTEXT(pc); + int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(target)+sizeof(level)+2*8; + unsigned char *data_ptr; + CR_GET_BUFFERED_POINTER( pc, packet_length ); + + WRITE_DATA_AI(int, packet_length); + WRITE_DATA_AI(GLenum, CR_GETCOMPRESSEDTEXIMAGEARB_EXTEND_OPCODE); + WRITE_DATA_AI(GLenum, target); + WRITE_DATA_AI(GLint, level); + WRITE_NETWORK_POINTER(0, (void *) img ); + WRITE_NETWORK_POINTER(8, (void *) writeback ); + WRITE_OPCODE(pc, CR_EXTEND_OPCODE); + CR_UNLOCK_PACKER_CONTEXT(pc); +} diff --git a/src/VBox/GuestHost/OpenGL/packer/pack_visibleregion.c b/src/VBox/GuestHost/OpenGL/packer/pack_visibleregion.c new file mode 100644 index 00000000..152077bc --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/pack_visibleregion.c @@ -0,0 +1,58 @@ +/* $Id: pack_visibleregion.c $ */ +/** @file + * VBox Packing VisibleRegion information + */ + +/* + * Copyright (C) 2008-2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "cr_error.h" + +#ifdef WINDOWS +# include <iprt/win/windows.h> +#endif + +void PACK_APIENTRY crPackWindowVisibleRegion( CR_PACKER_CONTEXT_ARGDECL GLint window, GLint cRects, const GLint * pRects ) +{ + GLint i, size, cnt; + + CR_GET_PACKER_CONTEXT(pc); + unsigned char *data_ptr; + (void) pc; + size = 16 + cRects * 4 * sizeof(GLint); + CR_GET_BUFFERED_POINTER( pc, size ); + WRITE_DATA( 0, GLint, size ); + WRITE_DATA( 4, GLenum, CR_WINDOWVISIBLEREGION_EXTEND_OPCODE ); + WRITE_DATA( 8, GLint, window ); + WRITE_DATA( 12, GLint, cRects ); + + cnt = 16; + for (i=0; i<cRects; ++i) + { + WRITE_DATA(cnt, GLint, (GLint) pRects[4*i+0]); + WRITE_DATA(cnt+4, GLint, (GLint) pRects[4*i+1]); + WRITE_DATA(cnt+8, GLint, (GLint) pRects[4*i+2]); + WRITE_DATA(cnt+12, GLint, (GLint) pRects[4*i+3]); + cnt += 16; + } + WRITE_OPCODE( pc, CR_EXTEND_OPCODE ); + CR_UNLOCK_PACKER_CONTEXT(pc); +} + +void PACK_APIENTRY crPackWindowVisibleRegionSWAP( CR_PACKER_CONTEXT_ARGDECL GLint window, GLint cRects, const GLint * pRects ) +{ + RT_NOREF3(window, cRects, pRects); CR_PACKER_CONTEXT_ARG_NOREF(); + crError( "crPackWindowVisibleRegionSWAP unimplemented and shouldn't be called" ); +} + diff --git a/src/VBox/GuestHost/OpenGL/packer/packer.h b/src/VBox/GuestHost/OpenGL/packer/packer.h new file mode 100644 index 00000000..f70a5bb4 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/packer.h @@ -0,0 +1,27 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved. + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#ifndef CR_PACKER_H +#define CR_PACKER_H + +#ifdef DLLDATA +#undef DLLDATA +#endif +#define DLLDATA(type) DECLEXPORT(type) + +#include <stdio.h> /* for sprintf() */ +#include "cr_pack.h" +#include "cr_packfunctions.h" +#include "packer_extensions.h" +#include "cr_mem.h" + +#ifndef IN_RING0 +extern void __PackError( int line, const char *file, GLenum error, const char *info ); +#else +# define __PackError( line, file, error, info) do { AssertReleaseFailed(); } while (0) +#endif + +#endif /* CR_PACKER_H */ diff --git a/src/VBox/GuestHost/OpenGL/packer/packer.py b/src/VBox/GuestHost/OpenGL/packer/packer.py new file mode 100755 index 00000000..b0b5ad6a --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/packer.py @@ -0,0 +1,274 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +# This script generates the packer.c file from the gl_header.parsed file. + +from __future__ import print_function +import sys, string, re + +import apiutil + + + +def WriteData( offset, arg_type, arg_name, is_swapped ): + """Return a string to write a variable to the packing buffer.""" + retval = 9 + if apiutil.IsPointer(arg_type): + retval = "\tWRITE_NETWORK_POINTER(%d, (void *) %s);" % (offset, arg_name ) + else: + if is_swapped: + if arg_type == "GLfloat" or arg_type == "GLclampf": + retval = "\tWRITE_DATA(%d, GLuint, SWAPFLOAT(%s));" % (offset, arg_name) + elif arg_type == "GLdouble" or arg_type == "GLclampd": + retval = "\tWRITE_SWAPPED_DOUBLE(%d, %s);" % (offset, arg_name) + elif apiutil.sizeof(arg_type) == 1: + retval = "\tWRITE_DATA(%d, %s, %s);" % (offset, arg_type, arg_name) + elif apiutil.sizeof(arg_type) == 2: + retval = "\tWRITE_DATA(%d, %s, SWAP16(%s));" % (offset, arg_type, arg_name) + elif apiutil.sizeof(arg_type) == 4: + retval = "\tWRITE_DATA(%d, %s, SWAP32(%s));" % (offset, arg_type, arg_name) + else: + if arg_type == "GLdouble" or arg_type == "GLclampd": + retval = "\tWRITE_DOUBLE(%d, %s);" % (offset, arg_name) + else: + retval = "\tWRITE_DATA(%d, %s, %s);" % (offset, arg_type, arg_name) + if retval == 9: + print >>sys.stderr, "no retval for %s %s" % (arg_name, arg_type) + assert 0 + return retval + + +def UpdateCurrentPointer( func_name ): + m = re.search( r"^(Color|Normal)([1234])(ub|b|us|s|ui|i|f|d)$", func_name ) + if m : + k = m.group(1) + name = '%s%s' % (k[:1].lower(),k[1:]) + type = m.group(3) + m.group(2) + print("\tpc->current.c.%s.%s = data_ptr;" % (name,type)) + return + + m = re.search( r"^(SecondaryColor)(3)(ub|b|us|s|ui|i|f|d)EXT$", func_name ) + if m : + k = m.group(1) + name = 'secondaryColor' + type = m.group(3) + m.group(2) + print("\tpc->current.c.%s.%s = data_ptr;" % (name,type)) + return + + m = re.search( r"^(TexCoord)([1234])(ub|b|us|s|ui|i|f|d)$", func_name ) + if m : + k = m.group(1) + name = 'texCoord' + type = m.group(3) + m.group(2) + print("\tpc->current.c.%s.%s[0] = data_ptr;" % (name,type)) + return + + m = re.search( r"^(MultiTexCoord)([1234])(ub|b|us|s|ui|i|f|d)ARB$", func_name ) + if m : + k = m.group(1) + name = 'texCoord' + type = m.group(3) + m.group(2) + print("\tpc->current.c.%s.%s[texture-GL_TEXTURE0_ARB] = data_ptr + 4;" % (name,type)) + return + + m = re.match( r"^(Index)(ub|b|us|s|ui|i|f|d)$", func_name ) + if m : + k = m.group(1) + name = 'index' + type = m.group(2) + "1" + print("\tpc->current.c.%s.%s = data_ptr;" % (name,type)) + return + + m = re.match( r"^(EdgeFlag)$", func_name ) + if m : + k = m.group(1) + name = 'edgeFlag' + type = "l1" + print("\tpc->current.c.%s.%s = data_ptr;" % (name,type)) + return + + m = re.match( r"^(FogCoord)(f|d)EXT$", func_name ) + if m : + k = m.group(1) + name = 'fogCoord' + type = m.group(2) + "1" + print("\tpc->current.c.%s.%s = data_ptr;" % (name,type)) + return + + + m = re.search( r"^(VertexAttrib)([1234])N?(ub|b|s|f|d)(NV|ARB)$", func_name ) + if m : + k = m.group(1) + name = 'vertexAttrib' + type = m.group(3) + m.group(2) + # Add 12 to skip the packet length, opcode and index fields + print("\tpc->current.c.%s.%s[index] = data_ptr + 4;" % (name,type)) + if m.group(4) == "ARB" or m.group(4) == "NV": + print("\tpc->current.attribsUsedMask |= (1 << index);") + print("\tpc->current.changedVertexAttrib |= (1 << index);") + return + + + +def PrintFunc( func_name, params, is_swapped, can_have_pointers ): + """Emit a packer function.""" + if is_swapped: + print('void PACK_APIENTRY crPack%sSWAP(%s)' % (func_name, apiutil.MakeDeclarationStringWithContext('CR_PACKER_CONTEXT', params))) + else: + print('void PACK_APIENTRY crPack%s(%s)' % (func_name, apiutil.MakeDeclarationStringWithContext('CR_PACKER_CONTEXT', params))) + print('{') + print('\tCR_GET_PACKER_CONTEXT(pc);') + + # Save original function name + orig_func_name = func_name + + # Convert to a non-vector version of the function if possible + func_name = apiutil.NonVectorFunction( func_name ) + if not func_name: + func_name = orig_func_name + + # Check if there are any pointer parameters. + # That's usually a problem so we'll emit an error function. + nonVecParams = apiutil.Parameters(func_name) + bail_out = 0 + for (name, type, vecSize) in nonVecParams: + if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers: + bail_out = 1 + if bail_out: + for (name, type, vecSize) in nonVecParams: + print('\t(void)%s;' % (name)) + print('\tcrError ( "%s needs to be special cased %d %d!");' % (func_name, vecSize, can_have_pointers)) + print('\t(void) pc;') + print('}') + # XXX we should really abort here + return + + if "extpack" in apiutil.ChromiumProps(func_name): + is_extended = 1 + else: + is_extended = 0 + + + print("\tunsigned char *data_ptr = NULL;") + print('\t(void) pc;') + #if func_name == "Enable" or func_name == "Disable": + # print "\tCRASSERT(!pc->buffer.geometry_only); /* sanity check */" + + for index in range(0,len(params)): + (name, type, vecSize) = params[index] + if vecSize>0 and func_name!=orig_func_name: + print(" if (!%s) {" % name) + # Know the reason for this one, so avoid the spam. + if orig_func_name != "SecondaryColor3fvEXT": + print(" crDebug(\"App passed NULL as %s for %s\");" % (name, orig_func_name)) + print(" return;") + print(" }") + + packet_length = apiutil.PacketLength(nonVecParams) + + if packet_length == 0 and not is_extended: + print("\tCR_GET_BUFFERED_POINTER_NO_ARGS(pc);") + elif func_name[:9] == "Translate" or func_name[:5] == "Color": + # XXX WTF is the purpose of this? + if is_extended: + packet_length += 8 + print("\tCR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, %d, GL_TRUE);" % packet_length) + else: + if is_extended: + packet_length += 8 + print("\tCR_GET_BUFFERED_POINTER(pc, %d);" % packet_length) + UpdateCurrentPointer( func_name ) + + if is_extended: + counter = 8 + print(WriteData( 0, 'GLint', packet_length, is_swapped )) + print(WriteData( 4, 'GLenum', apiutil.ExtendedOpcodeName( func_name ), is_swapped )) + else: + counter = 0 + + # Now emit the WRITE_() macros for all parameters + for index in range(0,len(params)): + (name, type, vecSize) = params[index] + # if we're converting a vector-valued function to a non-vector func: + if vecSize > 0 and func_name != orig_func_name: + ptrType = apiutil.PointerType(type) + for i in range(0, vecSize): + print(WriteData( counter + i * apiutil.sizeof(ptrType), + ptrType, "%s[%d]" % (name, i), is_swapped )) + # XXX increment counter here? + else: + print(WriteData( counter, type, name, is_swapped )) + if apiutil.IsPointer(type): + counter += apiutil.PointerSize() + else: + counter += apiutil.sizeof(type) + + # finish up + if is_extended: + print("\tWRITE_OPCODE(pc, CR_EXTEND_OPCODE);") + else: + print("\tWRITE_OPCODE(pc, %s);" % apiutil.OpcodeName( func_name )) + + if "get" in apiutil.Properties(func_name): + print('\tCR_CMDBLOCK_CHECK_FLUSH(pc);') + + print('\tCR_UNLOCK_PACKER_CONTEXT(pc);') + print('}\n') + + +r0_funcs = [ 'ChromiumParameteriCR', 'WindowSize', 'WindowShow', 'WindowPosition' ] + + +apiutil.CopyrightC() + +print(""" +/* DO NOT EDIT - THIS FILE GENERATED BY THE packer.py SCRIPT */ + +/* For each of the OpenGL functions we have a packer function which + * packs the function's opcode and arguments into a buffer. + */ + +#include "packer.h" +#include "cr_opcodes.h" + +""") + + +keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") + +for func_name in keys: + if apiutil.FindSpecial( "packer", func_name ): + continue + + if not apiutil.HasPackOpcode(func_name): + continue + + pointers_ok = 0 + + return_type = apiutil.ReturnType(func_name) + params = apiutil.Parameters(func_name) + + if return_type != 'void': + # Yet another gross hack for glGetString + if return_type.find('*') == -1: + return_type = return_type + " *" + params.append(("return_value", return_type, 0)) + + if "get" in apiutil.Properties(func_name): + pointers_ok = 1 + params.append(("writeback", "int *", 0)) + + if func_name == 'Writeback': + pointers_ok = 1 + + if not func_name in r0_funcs: + print('#ifndef IN_RING0') + + PrintFunc( func_name, params, 0, pointers_ok ) + PrintFunc( func_name, params, 1, pointers_ok ) + + if not func_name in r0_funcs: + print('#endif') + diff --git a/src/VBox/GuestHost/OpenGL/packer/packer_bbox.py b/src/VBox/GuestHost/OpenGL/packer/packer_bbox.py new file mode 100755 index 00000000..5abb6e2e --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/packer_bbox.py @@ -0,0 +1,316 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +# This script generates the packer_bbox.c file from gl_header.parsed + +from __future__ import print_function +import sys +import string + +import apiutil + + +apiutil.CopyrightC() + +print(""" +/* DO NOT EDIT - THIS FILE GENERATED BY THE packer_bbox.py SCRIPT */ + +/* These functions pack glVertex functions and also update the bounding box + * if the cr_packer_globals.updateBBOX variable is non-zero. + */ + +#include "packer.h" +#include "cr_opcodes.h" +#include "pack_bbox.h" + +#include <float.h> + +/** + * Reset packer bounding box to empty state. + */ +void crPackResetBoundingBox(CRPackContext *pc) +{ + pc->bounds_min.x = FLT_MAX; + pc->bounds_min.y = FLT_MAX; + pc->bounds_min.z = FLT_MAX; + pc->bounds_max.x = -FLT_MAX; + pc->bounds_max.y = -FLT_MAX; + pc->bounds_max.z = -FLT_MAX; + pc->updateBBOX = 1; +} + +/** + * Query current bounding box. + * \return GL_TRUE if non-empty box, GL_FALSE if empty box. + */ +GLboolean crPackGetBoundingBox(CRPackContext *pc, + GLfloat *xmin, GLfloat *ymin, GLfloat *zmin, + GLfloat *xmax, GLfloat *ymax, GLfloat *zmax) +{ + if (pc->bounds_min.x != FLT_MAX) { + *xmin = pc->bounds_min.x; + *ymin = pc->bounds_min.y; + *zmin = pc->bounds_min.z; + *xmax = pc->bounds_max.x; + *ymax = pc->bounds_max.y; + *zmax = pc->bounds_max.z; + return GL_TRUE; + } + else { + return GL_FALSE; + } +} + +""") + +def WriteData( offset, arg_type, arg_name, is_swapped ): + if arg_type.find('*') != -1: + retval = "\tWRITE_NETWORK_POINTER(%d, (void *) %s);" % (offset, arg_name ) + else: + if is_swapped: + if arg_type == "GLfloat" or arg_type == "GLclampf": + retval = "\tWRITE_DATA(%d, GLuint, SWAPFLOAT(%s));" % (offset, arg_name) + elif arg_type == "GLdouble" or arg_type == "GLclampd": + retval = "\tWRITE_SWAPPED_DOUBLE(%d, %s);" % (offset, arg_name) + elif apiutil.sizeof(arg_type) == 1: + retval = "\tWRITE_DATA(%d, %s, %s);" % (offset, arg_type, arg_name) + elif apiutil.sizeof(arg_type) == 2: + retval = "\tWRITE_DATA(%d, %s, SWAP16(%s));" % (offset, arg_type, arg_name) + elif apiutil.sizeof(arg_type) == 4: + retval = "\tWRITE_DATA(%d, %s, SWAP32(%s));" % (offset, arg_type, arg_name) + else: + if arg_type == "GLdouble" or arg_type == "GLclampd": + retval = "\tWRITE_DOUBLE(%d, %s);" % (offset, arg_name) + else: + retval = "\tWRITE_DATA(%d, %s, %s);" % (offset, arg_type, arg_name) + return retval + + +def PrintFunction( func_name, extSuffix, num_coords, argtype, + do_swapped, do_count, do_vector ): + """ + Generate all the functions named crPackVertex[234][dfis][v]BBOX() and + crPackVertex[234][dfis][v]BBOX_COUNT(). + We also handle glVertexAttrib*ARB. + Note: func_name should not have an ARB suffix. + """ + + if do_count: + countSuffix = "_COUNT" + else: + countSuffix = "" + + if do_swapped: + swapSuffix = "SWAP" + else: + swapSuffix = "" + + if func_name[0:12] == "VertexAttrib": + isVertexAttrib = 1 + else: + isVertexAttrib = 0 + + if argtype[0] == "N": + normalized = 1 + else: + normalized = 0; + + if argtype == "b" or argtype == "Nb": + vector_type = "GLbyte" + elif argtype == "ub" or argtype == "Nub": + vector_type = "GLubyte" + elif argtype == "s" or argtype == "Ns": + vector_type = "GLshort" + elif argtype == "us" or argtype == "Nus": + vector_type = "GLushort" + elif argtype == "i" or argtype == "Ni": + vector_type = "GLint" + elif argtype == "ui" or argtype == "Nui": + vector_type = "GLuint" + elif argtype == "f": + vector_type = "GLfloat" + elif argtype == "d": + vector_type = "GLdouble" + else: + print("type is %s" % argtype) + abort() + + if do_vector: + if isVertexAttrib: + func_name = 'VertexAttrib%d%sv' % (num_coords, argtype) + else: + func_name = 'Vertex%d%sv' % (num_coords,argtype) + + params = apiutil.Parameters(func_name + extSuffix) + + print('void PACK_APIENTRY crPack%sBBOX%s%s(%s)' % (func_name + extSuffix, countSuffix, + swapSuffix, apiutil.MakeDeclarationString(params))) + print('{') + + if do_vector: + # vector version + packet_length = num_coords * apiutil.sizeof(vector_type) + if isVertexAttrib: + packet_length += 4 # for index + if packet_length % 4 != 0: + packet_length += 2 + + else: + # non-vector + packet_length = apiutil.PacketLength( params ) + if isVertexAttrib: + packet_length += 0 # for index + if packet_length % 4 != 0: + packet_length += 2 + + + print("\tCR_GET_PACKER_CONTEXT(pc);") + print("\tunsigned char *data_ptr = NULL;") + + if normalized: + if argtype == "Nb": + t = "B" + elif argtype == "Ni": + t = "I" + elif argtype == "Nui": + t = "UI" + elif argtype == "Nub": + t = "UB" + elif argtype == "Ns": + t = "S" + elif argtype == "Nus": + t = "US" + else: + abort() + if do_vector: + print("\tCREATE_%dD_VFLOATS_%s_NORMALIZED();" % (num_coords, t)) + else: + print("\tCREATE_%dD_FLOATS_%s_NORMALIZED();" % (num_coords, t)) + else: + if do_vector: + print("\tCREATE_%dD_VFLOATS();" % num_coords) + else: + print("\tCREATE_%dD_FLOATS();" % num_coords) + + print("\tCR_GET_BUFFERED%s_POINTER(pc, %d);" % (countSuffix, packet_length)) + + # Bounding box code + if isVertexAttrib: + print("\tif (pc->updateBBOX && index == 0)") + else: + print("\tif (pc->updateBBOX)") + print("\t{") + if num_coords < 4: + print("\t\tUPDATE_%dD_BBOX();" % num_coords) + else: + print("\t\tUPDATE_3D_BBOX();") + print("\t}") + + if isVertexAttrib: + print("\tif (index > 0) {") + t = argtype + print("\t\tpc->current.c.vertexAttrib.%s%d[index] = data_ptr + 4;" % (t, num_coords)) + print("\t\tpc->current.attribsUsedMask |= (1 << index);") + if do_count: + print("\t\tpc->current.vtx_count--;") + + print("\t}") + + fname = func_name + extSuffix + if do_vector: + # use non-vector opcode + opcode = apiutil.OpcodeName( func_name[:-1] + extSuffix ) + else: + opcode = apiutil.OpcodeName( func_name + extSuffix ) + counter = 0 + + if do_vector: + if isVertexAttrib: + if do_swapped: + print("\tWRITE_DATA(0, GLuint, SWAP32(index));") + else: + print("\tWRITE_DATA(0, GLuint, index);") + counter += 4 + argname = params[1][0] # skip 'index' parameter + else: + argname = params[0][0] + + for index in range(num_coords): + print(WriteData( counter, vector_type, "%s[%d]" % (argname, index), do_swapped )) + counter += apiutil.sizeof(vector_type) + + if isVertexAttrib: + if do_vector == 2: + # this is a bit of a hack + print("\tWRITE_OPCODE(pc, %s);" % apiutil.OpcodeName( func_name + "ARB" )) + else: + print("\tWRITE_OPCODE(pc, %s);" % apiutil.OpcodeName( func_name[:-1] + "ARB" )) + else: + print("\tWRITE_OPCODE(pc, %s);" % apiutil.OpcodeName( func_name[:-1] )) + else: + for index in range(0,len(params)): + (name, type, vecSize) = params[index] + print(WriteData( counter, type, name, do_swapped )) + counter += apiutil.sizeof(type) + + if isVertexAttrib: + print("\tWRITE_OPCODE(pc, %s);" % apiutil.OpcodeName( func_name + "ARB" )) + else: + print("\tWRITE_OPCODE(pc, %s);" % apiutil.OpcodeName( func_name )) + + print("\tCR_UNLOCK_PACKER_CONTEXT(pc);") + + + print('}\n') + +#end PrintFunction() + + +for num_coords in [2,3,4]: + for argtype in ['d', 'f', 'i', 's']: + func_name = 'Vertex%d%s' % (num_coords, argtype) + for swap in range(0, 2): + for count in range(0, 2): + for vec in range(0, 2): + PrintFunction( func_name, "", num_coords, argtype, swap, + count, vec ) + +for num_coords in [1,2,3,4]: + for argtype in ['d', 'f', 's']: + func_name = 'VertexAttrib%d%s' % (num_coords, argtype) + for swap in range(0, 2): + for count in range(0, 2): + for vec in range(0, 2): + PrintFunction( func_name, "ARB", num_coords, argtype, swap, + count, vec ) + +# Special vector functions +moreFuncs = [ [ "VertexAttrib4ubv", "ub" ], + [ "VertexAttrib4usv", "us" ], + [ "VertexAttrib4uiv", "ui" ], + [ "VertexAttrib4bv", "b" ], + [ "VertexAttrib4iv", "i" ], + [ "VertexAttrib4Nbv", "Nb" ], + [ "VertexAttrib4Nsv", "Ns" ], + [ "VertexAttrib4Niv", "Ni" ], + [ "VertexAttrib4Nubv", "Nub" ], + [ "VertexAttrib4Nusv", "Nus" ], + [ "VertexAttrib4Nuiv", "Nui" ] + ] +for (func_name, argtype) in moreFuncs: + vec = 2 # special, hacked value + num_coords = 4 + for swap in range(0, 2): + for count in range(0, 2): + PrintFunction( func_name, "ARB", num_coords, argtype, swap, count, vec ) + +# Special non-vector functions +moreFuncs = [ [ "VertexAttrib4Nub", "Nub" ] ] +for (func_name, argtype) in moreFuncs: + vec = 0 + num_coords = 4 + for swap in range(0, 2): + for count in range(0, 2): + PrintFunction( func_name, "ARB", num_coords, argtype, swap, count, vec ) diff --git a/src/VBox/GuestHost/OpenGL/packer/packer_defs.py b/src/VBox/GuestHost/OpenGL/packer/packer_defs.py new file mode 100644 index 00000000..40595871 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/packer_defs.py @@ -0,0 +1,203 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. + +# This script generates the packer/packer.def file. + +import sys +import cPickle + +import apiutil + + +apiutil.CopyrightDef() + +print "DESCRIPTION \"\"" +print "EXPORTS" + +keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt") +for func_name in keys: + if apiutil.CanPack(func_name): + print "crPack%s" % func_name + print "crPack%sSWAP" % func_name + +functions = [ + 'crPackVertexAttrib1dARBBBOX', + 'crPackVertexAttrib1dvARBBBOX', + 'crPackVertexAttrib1fARBBBOX', + 'crPackVertexAttrib1fvARBBBOX', + 'crPackVertexAttrib1sARBBBOX', + 'crPackVertexAttrib1svARBBBOX', + 'crPackVertexAttrib2dARBBBOX', + 'crPackVertexAttrib2dvARBBBOX', + 'crPackVertexAttrib2fARBBBOX', + 'crPackVertexAttrib2fvARBBBOX', + 'crPackVertexAttrib2sARBBBOX', + 'crPackVertexAttrib2svARBBBOX', + 'crPackVertexAttrib3dARBBBOX', + 'crPackVertexAttrib3dvARBBBOX', + 'crPackVertexAttrib3fARBBBOX', + 'crPackVertexAttrib3fvARBBBOX', + 'crPackVertexAttrib3sARBBBOX', + 'crPackVertexAttrib3svARBBBOX', + 'crPackVertexAttrib4dARBBBOX', + 'crPackVertexAttrib4dvARBBBOX', + 'crPackVertexAttrib4fARBBBOX', + 'crPackVertexAttrib4fvARBBBOX', + 'crPackVertexAttrib4sARBBBOX', + 'crPackVertexAttrib4svARBBBOX', + 'crPackVertexAttrib4usvARBBBOX', + 'crPackVertexAttrib4ivARBBBOX', + 'crPackVertexAttrib4uivARBBBOX', + 'crPackVertexAttrib4bvARBBBOX', + 'crPackVertexAttrib4ubvARBBBOX', + 'crPackVertexAttrib4NusvARBBBOX', + 'crPackVertexAttrib4NsvARBBBOX', + 'crPackVertexAttrib4NuivARBBBOX', + 'crPackVertexAttrib4NivARBBBOX', + 'crPackVertexAttrib4NubvARBBBOX', + 'crPackVertexAttrib4NbvARBBBOX', + 'crPackVertexAttrib4NubARBBBOX', + 'crPackVertex2dBBOX', + 'crPackVertex2dvBBOX', + 'crPackVertex2fBBOX', + 'crPackVertex2fvBBOX', + 'crPackVertex2iBBOX', + 'crPackVertex2ivBBOX', + 'crPackVertex2sBBOX', + 'crPackVertex2svBBOX', + 'crPackVertex3dBBOX', + 'crPackVertex3dvBBOX', + 'crPackVertex3fBBOX', + 'crPackVertex3fvBBOX', + 'crPackVertex3iBBOX', + 'crPackVertex3ivBBOX', + 'crPackVertex3sBBOX', + 'crPackVertex3svBBOX', + 'crPackVertex4dBBOX', + 'crPackVertex4dvBBOX', + 'crPackVertex4fBBOX', + 'crPackVertex4fvBBOX', + 'crPackVertex4iBBOX', + 'crPackVertex4ivBBOX', + 'crPackVertex4sBBOX', + 'crPackVertex4svBBOX', + 'crPackVertexAttrib1dARBBBOX_COUNT', + 'crPackVertexAttrib1dvARBBBOX_COUNT', + 'crPackVertexAttrib1fARBBBOX_COUNT', + 'crPackVertexAttrib1fvARBBBOX_COUNT', + 'crPackVertexAttrib1sARBBBOX_COUNT', + 'crPackVertexAttrib1svARBBBOX_COUNT', + 'crPackVertexAttrib2dARBBBOX_COUNT', + 'crPackVertexAttrib2dvARBBBOX_COUNT', + 'crPackVertexAttrib2fARBBBOX_COUNT', + 'crPackVertexAttrib2fvARBBBOX_COUNT', + 'crPackVertexAttrib2sARBBBOX_COUNT', + 'crPackVertexAttrib2svARBBBOX_COUNT', + 'crPackVertexAttrib3dARBBBOX_COUNT', + 'crPackVertexAttrib3dvARBBBOX_COUNT', + 'crPackVertexAttrib3fARBBBOX_COUNT', + 'crPackVertexAttrib3fvARBBBOX_COUNT', + 'crPackVertexAttrib3sARBBBOX_COUNT', + 'crPackVertexAttrib3svARBBBOX_COUNT', + 'crPackVertexAttrib4dARBBBOX_COUNT', + 'crPackVertexAttrib4dvARBBBOX_COUNT', + 'crPackVertexAttrib4fARBBBOX_COUNT', + 'crPackVertexAttrib4fvARBBBOX_COUNT', + 'crPackVertexAttrib4sARBBBOX_COUNT', + 'crPackVertexAttrib4svARBBBOX_COUNT', + 'crPackVertexAttrib4usvARBBBOX_COUNT', + 'crPackVertexAttrib4ivARBBBOX_COUNT', + 'crPackVertexAttrib4uivARBBBOX_COUNT', + 'crPackVertexAttrib4bvARBBBOX_COUNT', + 'crPackVertexAttrib4ubvARBBBOX_COUNT', + 'crPackVertexAttrib4NusvARBBBOX_COUNT', + 'crPackVertexAttrib4NsvARBBBOX_COUNT', + 'crPackVertexAttrib4NuivARBBBOX_COUNT', + 'crPackVertexAttrib4NivARBBBOX_COUNT', + 'crPackVertexAttrib4NubvARBBBOX_COUNT', + 'crPackVertexAttrib4NbvARBBBOX_COUNT', + 'crPackVertexAttrib4NubARBBBOX_COUNT', + 'crPackVertex2dBBOX_COUNT', + 'crPackVertex2dvBBOX_COUNT', + 'crPackVertex2fBBOX_COUNT', + 'crPackVertex2fvBBOX_COUNT', + 'crPackVertex2iBBOX_COUNT', + 'crPackVertex2ivBBOX_COUNT', + 'crPackVertex2sBBOX_COUNT', + 'crPackVertex2svBBOX_COUNT', + 'crPackVertex3dBBOX_COUNT', + 'crPackVertex3dvBBOX_COUNT', + 'crPackVertex3fBBOX_COUNT', + 'crPackVertex3fvBBOX_COUNT', + 'crPackVertex3iBBOX_COUNT', + 'crPackVertex3ivBBOX_COUNT', + 'crPackVertex3sBBOX_COUNT', + 'crPackVertex3svBBOX_COUNT', + 'crPackVertex4dBBOX_COUNT', + 'crPackVertex4dvBBOX_COUNT', + 'crPackVertex4fBBOX_COUNT', + 'crPackVertex4fvBBOX_COUNT', + 'crPackVertex4iBBOX_COUNT', + 'crPackVertex4ivBBOX_COUNT', + 'crPackVertex4sBBOX_COUNT', + 'crPackVertex4svBBOX_COUNT', + 'crPackVertexAttribs1dvNV', + 'crPackVertexAttribs1fvNV', + 'crPackVertexAttribs1svNV', + 'crPackVertexAttribs2dvNV', + 'crPackVertexAttribs2fvNV', + 'crPackVertexAttribs2svNV', + 'crPackVertexAttribs3dvNV', + 'crPackVertexAttribs3fvNV', + 'crPackVertexAttribs3svNV', + 'crPackVertexAttribs4dvNV', + 'crPackVertexAttribs4fvNV', + 'crPackVertexAttribs4svNV', + 'crPackVertexAttribs4ubvNV', + 'crPackExpandDrawArrays', + 'crPackExpandDrawElements', + 'crPackUnrollDrawElements', + 'crPackExpandDrawRangeElements', + 'crPackExpandArrayElement', + 'crPackExpandMultiDrawArraysEXT', + 'crPackMultiDrawArraysEXT', + 'crPackMultiDrawElementsEXT', + 'crPackExpandMultiDrawElementsEXT', + 'crPackMapBufferARB', + 'crPackUnmapBufferARB' ] + +for func_name in functions: + print "%s" % func_name + print "%sSWAP" % func_name + + +print """ +crPackInitBuffer +crPackResetPointers +crPackAppendBuffer +crPackAppendBoundedBuffer +crPackSetBuffer +crPackSetBufferDEBUG +crPackReleaseBuffer +crPackFlushFunc +crPackFlushArg +crPackSendHugeFunc +crPackBoundsInfoCR +crPackResetBoundingBox +crPackGetBoundingBox +crPackOffsetCurrentPointers +crPackNullCurrentPointers +crPackNewContext +crPackGetContext +crPackSetContext +crPackFree +crNetworkPointerWrite +crPackCanHoldBuffer +crPackCanHoldBoundedBuffer +crPackMaxData +crPackErrorFunction +cr_packer_globals +_PackerTSD +""" diff --git a/src/VBox/GuestHost/OpenGL/packer/packer_extensions.h b/src/VBox/GuestHost/OpenGL/packer/packer_extensions.h new file mode 100644 index 00000000..fba8d2f2 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/packer_extensions.h @@ -0,0 +1,13 @@ +/* Copyright (c) 2001, Stanford University + * All rights reserved. + * + * See the file LICENSE.txt for information on redistributing this software. + */ + +#ifndef CR_PACKER_EXTENSIONS_H +#define CR_PACKER_EXTENSIONS_H + +int __packTexParameterNumParams( GLenum pname ); +int __packFogParamsLength( GLenum pname ); + +#endif /* CR_PACKER_EXTENSION_H */ diff --git a/src/VBox/GuestHost/OpenGL/packer/packer_special b/src/VBox/GuestHost/OpenGL/packer/packer_special new file mode 100644 index 00000000..42fe6659 --- /dev/null +++ b/src/VBox/GuestHost/OpenGL/packer/packer_special @@ -0,0 +1,185 @@ +# Copyright (c) 2001, Stanford University +# All rights reserved. +# +# See the file LICENSE.txt for information on redistributing this software. +BoundsInfoCR +VertexPointer +ColorPointer +CreateContext +SecondaryColorPointerEXT +NormalPointer +TexCoordPointer +EdgeFlagPointer +InterleavedArrays +IndexPointer +AreTexturesResident +AreProgramsResidentNV +Bitmap +CallLists +NewList +EndList +ClipPlane +DeleteTextures +DrawPixels +Fogfv +Fogiv +GetTexImage +Lightfv +Lightiv +LightModelfv +LightModeliv +LoadMatrixf +LoadMatrixd +Map1d +Map1f +Map2d +Map2f +Materialfv +Materialiv +MultMatrixd +MultMatrixf +PixelMapfv +PixelMapuiv +PixelMapusv +PolygonStipple +PrioritizeTextures +ReadPixels +TexEnvfv +TexEnviv +TexGendv +TexGenfv +TexGeniv +TexEnvf +TexEnvi +TexGend +TexGenf +TexGeni +TexImage1D +TexImage2D +TexImage3D +TexImage3DEXT +TexParameterfv +TexParameteriv +TexParameterf +TexParameteri +TexSubImage1D +TexSubImage2D +TexSubImage3D +DrawElements +MultiDrawArraysEXT +MultiDrawElementsEXT +DrawRangeElements +CombinerParameterfvNV +CombinerParameterivNV +CombinerStageParameterfvNV +ChromiumParametervCR +WindowCreate +FeedbackBuffer +SelectBuffer +Begin +End +VertexArrayRangeNV +LoadTransposeMatrixfARB +LoadTransposeMatrixdARB +MultTransposeMatrixfARB +MultTransposeMatrixdARB +ProgramParameters4dvNV +ProgramParameters4fvNV +VertexAttribPointerNV +VertexAttribs1dvNV +VertexAttribs1fvNV +VertexAttribs1svNV +VertexAttribs2dvNV +VertexAttribs2fvNV +VertexAttribs2svNV +VertexAttribs3dvNV +VertexAttribs3fvNV +VertexAttribs3svNV +VertexAttribs4dvNV +VertexAttribs4fvNV +VertexAttribs4svNV +VertexAttribs4ubvNV +ExecuteProgramNV +LoadProgramNV +RequestResidentProgramsNV +CompressedTexImage3DARB +CompressedTexImage2DARB +CompressedTexImage1DARB +CompressedTexSubImage3DARB +CompressedTexSubImage2DARB +CompressedTexSubImage1DARB +GetCompressedTexImageARB +DeleteFencesNV +FogCoordPointerEXT +PointParameterfvARB +PointParameteriv +ProgramNamedParameter4fNV +ProgramNamedParameter4dNV +ProgramNamedParameter4fvNV +ProgramNamedParameter4dvNV +GetProgramNamedParameterdvNV +GetProgramNamedParameterfvNV +VertexAttrib4bvARB +VertexAttrib4ivARB +VertexAttrib4ubvARB +VertexAttrib4uivARB +VertexAttrib4usvARB +VertexAttribPointerARB +DeleteProgramsARB +ProgramStringARB +VertexAttrib4NbvARB +VertexAttrib4NivARB +VertexAttrib4NsvARB +VertexAttrib4NubvARB +VertexAttrib4NuivARB +VertexAttrib4NusvARB +BufferDataARB +BufferSubDataARB +MapBufferARB +UnmapBufferARB +DeleteBuffersARB +ZPixCR +WindowVisibleRegion +BindAttribLocation +ShaderSource +Uniform1fv +Uniform1iv +Uniform2fv +Uniform2iv +Uniform3fv +Uniform3iv +Uniform4fv +Uniform4iv +UniformMatrix2fv +UniformMatrix3fv +UniformMatrix4fv +DrawBuffers +GetActiveAttrib +GetActiveUniform +GetAttachedShaders +GetShaderInfoLog +GetProgramInfoLog +GetShaderSource +GetAttribLocation +GetUniformLocation +GetAttachedObjectsARB +GetInfoLogARB +GetBufferSubDataARB +DeleteQueriesARB +DeleteFramebuffersEXT +DeleteRenderbuffersEXT +LockArraysEXT +GetUniformsLocations +GetAttribsLocations +UniformMatrix2x3fv +UniformMatrix3x2fv +UniformMatrix2x4fv +UniformMatrix4x2fv +UniformMatrix3x4fv +UniformMatrix4x3fv +VBoxTexPresent +WindowPosition +WindowShow +WindowSize +BeginQueryARB +EndQueryARB |