/* * $Id: displaylist.c 200 2007-11-03 11:53:08Z hderuiter $ * * $Date: 2007-11-03 12:26:08 $ * $Revision: 000 $ * * (C) 2007 by Hans de Ruiter * All rights reserved * * This file is part of the MiniGL library project * See the file Licence.txt for more details * */ #include "displaylists.h" #include #include #include #include #include extern GLuint eval_GetMapK1(GLenum target); extern GLuint eval_GetMapK2(GLenum target); extern uint32 client_texture_state[]; union DLOpData_u{ GLboolean b; GLbitfield bf; GLclampd cd; GLubyte ub; GLshort s; GLushort us; GLint i; GLuint ui; GLenum e; GLfloat f; GLdouble d; GLvoid *data; }; typedef void(*DLOpFunc)(struct GLContextIFace *Self, const struct DLOperation_s *op); // Typedefed as DLOperation in struct DLOperation_s{ DLOpFunc opFunc; union DLOpData_u opData; struct DLOperation_s *nextOp; }; typedef struct AlphaFuncData_s{ GLenum func; GLclampf ref; } AlphaFuncData; typedef struct BindTextureData_s{ GLenum target; GLuint texture; } BindTextureData; typedef struct BitmapData_s{ GLsizei width; GLsizei height; GLfloat xorig; GLfloat yorig; GLfloat xmove; GLfloat ymove; const GLubyte bitmap[1]; // placeholder for a variable-length array } BitmapData; typedef struct CopyTexImage2DData_s{ GLenum target; GLint level; GLenum internalFormat; GLint x; GLint y; GLsizei width; GLsizei height; GLint border; } CopyTexImage2DData; typedef struct CopyTexSubImage2DData_s{ GLenum target; GLint level; GLint xoffset; GLint yoffset; GLint x; GLint y; GLsizei width; GLsizei height; } CopyTexSubImage2DData; typedef struct MaterialFVData_s{ GLenum face; GLenum pname; GLfloat params[4]; } MaterialFVData; typedef struct MaterialIVData_s{ GLenum face; GLenum pname; GLint params[4]; } MaterialIVData; typedef struct CallListsData_s{ GLsizei n; GLenum type; GLuint lists[1]; // Placeholder for a variable-length array } CallListsData; typedef struct ClipPlaneData_s{ GLenum plane; GLdouble equ[4]; } ClipPlaneData; typedef struct ColorTableData_s{ GLenum target; GLenum internalformat; GLint width; GLenum format; GLenum type; GLubyte data[1]; // placeholder for a variable-length array; } ColorTableData; typedef struct DrawArraysData_s{ GLenum mode; GLint first; GLsizei count; struct GLvertex_array_state vertex_array; } DrawArraysData; typedef struct DrawElementsData_s{ GLenum mode; GLsizei count; GLenum type; struct GLvertex_array_state vertex_array; GLuint indices[1]; // a placeholder for a variable-length array } DrawElementsData; typedef struct FogfData_s{ GLenum pname; GLfloat param; }FogfData; typedef struct FogfvData_s{ GLenum pname; GLfloat params[1]; // Placehoder for a variable-length array } FogfvData; typedef struct LightfData_s{ GLenum light; GLenum pname; GLfloat param; } LightfData; typedef struct LightfvData_s{ GLenum light; GLenum pname; GLfloat params[4]; } LightfvData; typedef struct LightivData_s{ GLenum light; GLenum pname; GLint params[4]; } LightivData; typedef struct LightModelfData_s{ GLenum pname; GLfloat param; } LightModelfData; typedef struct LightModelfvData_s{ GLenum pname; GLfloat params[4]; } LightModelfvData; typedef struct LightModelivData_s{ GLenum pname; GLint params[4]; } LightModelivData; typedef struct LineStippleData_s{ GLint factor; GLushort pattern; } LineStippleData; typedef struct MaterialfData_s{ GLenum face; GLenum pname; GLfloat param; } MaterialfData; typedef struct MultiTexCoord2fData_s{ GLenum target; GLfloat s; GLfloat t; } MultiTexCoord2fData; typedef struct MultiTexCoord4fData_s{ GLenum target; GLfloat s; GLfloat t; GLfloat r; GLfloat q; } MultiTexCoord4fData; typedef struct PolygonStippleData_s{ GLubyte pattern[32/8 * 32]; } PolygonStippleData; typedef struct PrioritizeTexturesData_s{ GLsizei n; GLuint *textures; GLclampf *priorities; } PrioritizeTexturesData; typedef struct ScissorData_s{ GLint x; GLint y; GLsizei width; GLsizei height; } ScissorData; typedef struct SetStateData_s{ GLenum cap; GLboolean flag; } SetStateData; typedef struct StencilFuncData_s{ GLenum func; GLint ref; GLuint mask; }StencilFuncData; typedef struct TexEnviData_s{ GLenum target; GLenum pname; GLint param; } TexEnviData; typedef struct TexEnvfvData_s{ GLenum target; GLenum pname; GLfloat params[4]; } TexEnvfvData; typedef struct TexGeniData_s{ GLenum coord; GLenum pname; GLint param; } TexGeniData; typedef struct TexGenfvData_s{ GLenum coord; GLenum pname; GLfloat params[4]; } TexGenfvData; typedef struct TexImage2DData_s{ GLenum target; GLint level; GLint internalformat; GLsizei width; GLsizei height; GLint border; GLenum format; GLenum type; GLubyte pixels[1]; // Placeholder for a variaible-length array } TexImage2DData; typedef struct TexParameteriData_s{ GLenum target; GLenum pname; GLint param; } TexParameteriData; typedef struct TexSubImage2D_s{ GLenum target; GLint level; GLint xoffset; GLint yoffset; GLsizei width; GLsizei height; GLenum format; GLenum type; GLubyte pixels[1]; // Placeholder for a variaible-length array } TexSubImage2DData; typedef struct ViewportData_s{ GLint x; GLint y; GLsizei width; GLsizei height; } ViewportData; typedef struct DrawPixelsData_s { GLsizei width; GLsizei height; GLenum format; GLenum type; GLubyte pixels[1]; // Placeholder, allocated with variable length } DrawPixelsData; typedef struct Map1fData_s { GLenum target; GLfloat u1; GLfloat u2; GLint order; GLfloat points[1]; } Map1fData; typedef struct Map1dData_s { GLenum target; GLdouble u1; GLdouble u2; GLint order; GLdouble points[1]; } Map1dData; typedef struct EvalCoord1Data_s { GLfloat arg; } EvalCoord1Data; typedef struct MapGrid1Data_s { GLint n; GLfloat u1; GLfloat u2; } MapGrid1Data; typedef struct EvalMesh1Data_s { GLenum mode; GLint p1; GLint p2; } EvalMesh1Data; typedef struct EvalPoint1Data_s { GLint p; } EvalPoint1Data; typedef struct Map2fData_s { GLenum target; GLfloat u1; GLfloat u2; GLint uorder; GLfloat v1; GLfloat v2; GLint vorder; GLfloat points[1]; } Map2fData; typedef struct Map2dData_s { GLenum target; GLdouble u1; GLdouble u2; GLint uorder; GLdouble v1; GLdouble v2; GLint vorder; GLdouble points[1]; } Map2dData; typedef struct EvalCoord2Data_s { GLfloat u; GLfloat v; } EvalCoord2Data; typedef struct MapGrid2Data_s { GLint nu; GLfloat u1; GLfloat u2; GLint nv; GLfloat v1; GLfloat v2; } MapGrid2Data; typedef struct EvalMesh2Data_s { GLenum mode; GLint p1; GLint p2; GLint q1; GLint q2; } EvalMesh2Data; typedef struct EvalPoint2Data_s { GLint p; GLint q; } EvalPoint2Data; typedef struct PixelTransferData_s { GLenum param; GLfloat value; } PixelTransferData; typedef struct PixelZoomData_s { GLfloat zoom_x; GLfloat zoom_y; } PixelZoomData; typedef struct CopyPixelData_s { GLint x; GLint y; GLsizei width; GLsizei height; GLenum type; } CopyPixelData; typedef struct LogicOpModeData_s { GLenum op; } LogicOpModeData; // ----- PRIVATE FUNCTION PROTOTYPES ----- /** Initialises a list (the list will have a single NULL operation). * * @param list the list to initialize * * @return BOOL set to TRUE if successful */ BOOL dl_InitList(DisplayList *list); /** Allocates a new operation and links it in to the list. * * @param prevOp pointer to the previous operation in the list, or NULL if this is the start of a new list * @param extraBytes the number of extra bytes required for the operation's data. This memory will be allocated * and automatically be pointed to by the data field * * @return DLOperation* pointer to the new operation, or NULL if failed (i.e., out of memory) */ DLOperation* dl_NewOperation(DLOperation *prevOp, GLuint extraBytes); /** Frees an operation. */ void dl_FreeOperation(DLOperation *op); /** Clears a display list. */ void dl_ClearList(DisplayList *list); // Returns the buffer size required to store the image data in bytes. GLuint dl_imageSize(GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type); // Copies image data from an image into a packed buffer. This will follow the OpenGL's unpack settings void dl_copyImage(struct GLContextIFace *Self, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *srcImage, void *destImage); // Call these macros before and after packed image uploading #define BEGIN_IMAGEUPLOAD \ GLint unpackAlignment, unpackRowLength, skipPixels, skipRows; \ Self->GLGetIntegerv(GL_UNPACK_ALIGNMENT, &unpackAlignment); \ Self->GLGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpackRowLength); \ Self->GLGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skipPixels); \ Self->GLGetIntegerv(GL_UNPACK_SKIP_ROWS, &skipRows); \ \ Self->GLPixelStorei(GL_UNPACK_ALIGNMENT, 1); \ Self->GLPixelStorei(GL_UNPACK_ROW_LENGTH, 0); \ Self->GLPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); \ Self->GLPixelStorei(GL_UNPACK_SKIP_ROWS, 0); #define END_IMAGEUPLOAD \ Self->GLPixelStorei(GL_UNPACK_ALIGNMENT, unpackAlignment); \ Self->GLPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength); \ Self->GLPixelStorei(GL_UNPACK_SKIP_PIXELS, skipPixels); \ Self->GLPixelStorei(GL_UNPACK_SKIP_ROWS, skipRows); /** Returns the number of elements in the vertex array needed to perform a DrawElements() operation with the given indices. * This assumes that all elements up to the highest addressed element are going to be used (i.e., no compression in order * to get rid of non-used elements). * * @param count the number of indices in the indices array * @param type the type of the indices * @param indices pointer to the indices array itself * * @return GLsizei the number of elements that the vertex array must contain */ GLsizei dl_getVertexArrayCountFromIndices(GLsizei count, GLint type, const void *indices); /** Returns the size in bytes that the vertex arrays would take up if the arrays were packed, for the current client state. * * @param context pointer to the context containing the arrays * @param count the number of elements in the array * * @return int the size of the vertex array in bytes */ int dl_getVertexArraySize(GLcontext context, GLsizei count); /** Copies the vertex array data into the given buffer. This buffer should be the size returned by dl_getVertexArraySize() * * @param context pointer to the context whose vertex array data will be copied * @param vertexArray pointer to the target vertex array * @param vertexArrayBuffer pointer to the buffer where the packed vertex data will be stored * @param first the first element in the vertex array to copy * @param count the number of elements in the vertex array to copy */ void dl_copyVertexArray(GLcontext context, struct GLvertex_array_state *vertexArray, GLvoid *vertexArrayBuffer, GLint first, GLsizei count); // ----- PUBLIC FUNCTIONS ----- void cgl_GLCallList(struct GLContextIFace *Self, GLuint list){ GLcontext context = GET_INSTANCE(Self); if(dl_IsDLActive(Self)){ dl_save_CallList(Self, list); if(!dl_CompileAndExecuteMode(Self)){ return; } } if(list == 0){ context->DisplayListNestingLevel = 0; return; } DisplayList *dList = &(context->DisplayListArray[list - 1]); for(DLOperation *currOp = dList->firstOp; currOp; currOp = currOp->nextOp){ currOp->opFunc(Self, currOp); } } void cgl_GLCallLists(struct GLContextIFace *Self, GLsizei n, GLenum type, const GLvoid *lists){ GLcontext context = GET_INSTANCE(Self); if(dl_IsDLActive(Self)){ dl_save_CallLists(Self, n, type, lists); if(!dl_CompileAndExecuteMode(Self)){ return; } } if(!lists){ context->CurrentError = GL_INVALID_VALUE; return; } switch(type){ case GL_BYTE: { const GLbyte *listArray = lists; for(int i = 0; i < n; i++){ cgl_GLCallList(Self, listArray[i] + context->DisplayListBaseOffset); } break; } case GL_UNSIGNED_BYTE: { const GLubyte *listArray = lists; for(int i = 0; i < n; i++){ cgl_GLCallList(Self, listArray[i] + context->DisplayListBaseOffset); } break; } case GL_SHORT: { const GLshort *listArray = lists; for(int i = 0; i < n; i++){ cgl_GLCallList(Self, listArray[i] + context->DisplayListBaseOffset); } break; } case GL_UNSIGNED_SHORT: { const GLushort *listArray = lists; for(int i = 0; i < n; i++){ cgl_GLCallList(Self, listArray[i] + context->DisplayListBaseOffset); } break; } case GL_INT: { const GLint *listArray = lists; for(int i = 0; i < n; i++){ cgl_GLCallList(Self, listArray[i] + context->DisplayListBaseOffset); } break; } case GL_UNSIGNED_INT: { const GLuint *listArray = lists; for(int i = 0; i < n; i++){ cgl_GLCallList(Self, listArray[i] + context->DisplayListBaseOffset); } break; } case GL_FLOAT: { const GLfloat *listArray = lists; for(int i = 0; i < n; i++){ cgl_GLCallList(Self, listArray[i] + context->DisplayListBaseOffset); } break; } case GL_2_BYTES: { const GLubyte *listArray = lists; for(int i = 0; i < n; i++){ GLuint val = listArray[2*i] * 256 + listArray[2*i + 1] + context->DisplayListBaseOffset; cgl_GLCallList(Self, val); } break; } case GL_3_BYTES: { const GLubyte *listArray = lists; for(int i = 0; i < n; i++){ GLuint val = listArray[3*i] * 65536 + listArray[3*i + 1] * 256 + listArray[3*i + 2] + context->DisplayListBaseOffset; cgl_GLCallList(Self, val); } break; } case GL_4_BYTES: { const GLubyte *listArray = lists; for(int i = 0; i < n; i++){ GLuint val = listArray[4*i] * 16777216 + listArray[4*i + 1] * 65536 + listArray[4*i + 2] * 256 + listArray[3*i + 3] + context->DisplayListBaseOffset; cgl_GLCallList(Self, val); } break; } default: context->CurrentError = GL_INVALID_ENUM; return; } } void cgl_GLDeleteLists(struct GLContextIFace *Self, GLuint list, GLsizei range){ GLcontext context = GET_INSTANCE(Self); if(range < 0){ context->CurrentError = GL_INVALID_VALUE; } if(list - 1 + range > context->DisplayListArraySize){ range = context->DisplayListArraySize - (list - 1); } int i; for(i = list - 1; i < range + list - 1; i++){ dl_ClearList(&(context->DisplayListArray[i])); context->DisplayListArray[i].firstOp = NULL; } } void cgl_GLEndList(struct GLContextIFace *Self){ GLcontext context = GET_INSTANCE(Self); // Make sure that we're not between glBegin()/glEnd() calls if(context->CurrentPrimitive != GL_BASE){ context->CurrentError = GL_INVALID_OPERATION; return; } if(context->DisplayListCompileError){ context->CurrentError = context->DisplayListCompileError; return; } #ifdef MGL_DISPLAYLIST_COMPILEW3DARRAYS // Compile list into W3DVertexArray objects // ##### FIXME! ##### #endif GLuint listIdx = context->TargetDisplayListIdx; if(context->TargetDisplayListStart != context->DisplayListArray[listIdx].firstOp){ // need to delete the old list dl_ClearList(&(context->DisplayListArray[listIdx])); } context->DisplayListArray[listIdx].firstOp = context->TargetDisplayListStart; context->TargetDisplayListStart = NULL; context->TargetDisplayListEnd = NULL; // Delete the dummy op at the start of the list if(context->DisplayListArray[listIdx].firstOp && !context->DisplayListArray[listIdx].firstOp->opFunc){ DLOperation *actualFirstOp = context->DisplayListArray[listIdx].firstOp->nextOp; dl_FreeOperation(context->DisplayListArray[listIdx].firstOp); context->DisplayListArray[listIdx].firstOp = actualFirstOp; } } GLuint cgl_GLGenLists(struct GLContextIFace *Self, GLsizei range){ GLcontext context = GET_INSTANCE(Self); if(range < 0){ context->CurrentError = GL_INVALID_VALUE; } if(range == 0){ return 0; } // Make sure that we're not between glBegin()/glEnd() calls if(context->CurrentPrimitive != GL_BASE){ context->CurrentError = GL_INVALID_OPERATION; return 0; } // Find a free spot in the display-list array and allocate the new lists int i, j; BOOL foundGap = FALSE; for(i = 0; i < context->DisplayListArraySize - range; i++){ if(context->DisplayListArray[i].firstOp == NULL){ foundGap = TRUE; // note, we're testing this assertion for(j = i; j < i + range; j++){ if(context->DisplayListArray[i].firstOp){ foundGap = GL_FALSE; break; } } if(foundGap){ for(j = i; j < i + range; j++){ if(dl_InitList(&(context->DisplayListArray[j])) == FALSE){ return 0; } } return i + 1; } else{ i += j; } } } return 0; } GLboolean cgl_GLIsList(struct GLContextIFace *Self, GLuint list){ GLcontext context = GET_INSTANCE(Self); // Make sure that we're not between glBegin()/glEnd() calls if(context->CurrentPrimitive != GL_BASE){ context->CurrentError = GL_INVALID_OPERATION; return GL_FALSE; } if(list > 0 && list <= context->DisplayListArraySize){ if(context->DisplayListArray[list - 1].firstOp){ return GL_TRUE; } } return GL_FALSE; } void cgl_GLListBase(struct GLContextIFace *Self, GLuint base){ GLcontext context = GET_INSTANCE(Self); // Make sure that we're not between glBegin()/glEnd() calls if(context->CurrentPrimitive != GL_BASE){ context->CurrentError = GL_INVALID_OPERATION; return; } context->DisplayListBaseOffset = base; } void cgl_GLNewList(struct GLContextIFace *Self, GLuint list, GLenum mode){ GLcontext context = GET_INSTANCE(Self); if(list == 0 || list >= context->DisplayListArraySize){ context->CurrentError = GL_INVALID_VALUE; return; } if(mode != GL_COMPILE && mode != GL_COMPILE_AND_EXECUTE){ context->CurrentError = GL_INVALID_ENUM; return; } // Make sure that we're not between glBegin()/glEnd() calls if(context->CurrentPrimitive != GL_BASE){ context->CurrentError = GL_INVALID_OPERATION; return; } // Some naughty OpenGL apps don't call glGenLists() and hard-code list numbers. // We'll generate new lists on the fly in this case if(context->DisplayListArray[list-1].firstOp == NULL) { if(dl_InitList(&(context->DisplayListArray[list-1])) == FALSE) { // OpenGL apps shouldn't be doing this anyway context->CurrentError = GL_INVALID_VALUE; return; } } if(context->DisplayListArray[list-1].firstOp->opFunc == NULL){ context->TargetDisplayListStart = context->DisplayListArray[list-1].firstOp; } else{ // Have to construct a new list without destroying the old one context->TargetDisplayListStart = dl_NewOperation(NULL, 0); if(!context->TargetDisplayListStart){ context->CurrentError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListStart->opFunc = NULL; } context->TargetDisplayListEnd = context->TargetDisplayListStart; context->TargetDisplayListIdx = list - 1; context->DisplayListCompileMode = mode; context->DisplayListCompileError = 0; } // ----- Execution Functions ----- void dl_execute_ActiveTexture(struct GLContextIFace *Self, const DLOperation *op){ Self->GLActiveTexture(op->opData.e); } void dl_execute_AlphaFunc(struct GLContextIFace *Self, const DLOperation *op){ AlphaFuncData *data = (AlphaFuncData*) op->opData.data; Self->GLAlphaFunc(data->func, data->ref); } void dl_execute_BlendFunc(struct GLContextIFace *Self, const DLOperation *op){ GLenum *data = (GLenum*) op->opData.data; Self->GLBlendFunc(data[0], data[1]); } void dl_execute_Begin(struct GLContextIFace *Self, const DLOperation *op){ Self->GLBegin(op->opData.e); } void dl_execute_BindTexture(struct GLContextIFace *Self, const DLOperation *op){ BindTextureData *data = (BindTextureData*) op->opData.data; Self->GLBindTexture(data->target, data->texture); } void dl_execute_Bitmap(struct GLContextIFace *Self, const DLOperation *op){ BitmapData *data = (BitmapData*) op->opData.data; BEGIN_IMAGEUPLOAD Self->GLBitmap(data->width, data->height, data->xorig, data->yorig, data->xmove, data->ymove, (GLvoid*)data->bitmap); END_IMAGEUPLOAD } void dl_execute_DrawPixels(struct GLContextIFace *Self, const DLOperation *op) { DrawPixelsData *data = (DrawPixelsData *)op->opData.data; BEGIN_IMAGEUPLOAD Self->GLDrawPixels(data->width, data->height, data->format, data->type, (GLvoid *)data->pixels); END_IMAGEUPLOAD } void dl_execute_CallList(struct GLContextIFace *Self, const DLOperation *op){ Self->GLCallList(op->opData.ui); } void dl_execute_CallLists(struct GLContextIFace *Self, const DLOperation *op){ CallListsData *data = op->opData.data; Self->GLCallLists(data->n, data->type, data->lists); } void dl_execute_Clear(struct GLContextIFace *Self, const DLOperation *op){ Self->GLClear(op->opData.bf); } void dl_execute_ClearColor(struct GLContextIFace *Self, const DLOperation *op){ GLclampf *data = op->opData.data; Self->GLClearColor(data[0], data[1], data[2], data[3]); } void dl_execute_ClearDepth(struct GLContextIFace *Self, const DLOperation *op){ Self->GLClearDepth(op->opData.cd); } void dl_execute_ClearStencil(struct GLContextIFace *Self, const DLOperation *op){ Self->GLClearStencil(op->opData.i); } void dl_execute_ClipPlane(struct GLContextIFace *Self, const DLOperation *op){ ClipPlaneData *data = op->opData.data; Self->GLClipPlane(data->plane, data->equ); } void dl_execute_Color4f(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLColor4f(data[0], data[1], data[2], data[3]); } void dl_execute_ColorMask(struct GLContextIFace *Self, const DLOperation *op){ GLboolean *data = op->opData.data; Self->GLColorMask(data[0], data[1], data[2], data[3]); } void dl_execute_ColorMaterial(struct GLContextIFace *Self, const DLOperation *op){ GLenum *data = op->opData.data; Self->GLColorMaterial(data[0], data[1]); } void dl_execute_ColorTable(struct GLContextIFace *Self, const DLOperation *op){ ColorTableData *data = op->opData.data; Self->GLColorTable(data->target, data->internalformat, data->width, data->format, data->type, data->data); } void dl_execute_CopyTexImage2D(struct GLContextIFace *Self, const DLOperation *op){ CopyTexImage2DData *data = (CopyTexImage2DData*) op->opData.data; Self->GLCopyTexImage2D(data->target, data->level, data->internalFormat, data->x, data->y, data->width, data->height, data->border); } void dl_execute_CopyTexSubImage2D(struct GLContextIFace *Self, const DLOperation *op){ CopyTexSubImage2DData *data = (CopyTexSubImage2DData*) op->opData.data; Self->GLCopyTexSubImage2D(data->target, data->level, data->xoffset, data->yoffset, data->x, data->y, data->width, data->height); } void dl_execute_CullFace(struct GLContextIFace *Self, const DLOperation *op){ Self->GLCullFace(op->opData.e); } void dl_execute_DepthFunc(struct GLContextIFace *Self, const DLOperation *op){ Self->GLDepthFunc(op->opData.e); } void dl_execute_DepthMask(struct GLContextIFace *Self, const DLOperation *op){ Self->GLDepthMask(op->opData.b); } void dl_execute_DepthRange(struct GLContextIFace *Self, const DLOperation *op){ GLclampd *data = op->opData.data; Self->GLDepthRange(data[0], data[1]); } void dl_execute_DrawArrays(struct GLContextIFace *Self, const DLOperation *op){ DrawArraysData *data = op->opData.data; GLcontext context = GET_INSTANCE(Self); struct GLvertex_array_state old_vertex_array = context->vertex_array; context->vertex_array = data->vertex_array; Self->GLDrawArrays(data->mode, data->first, data->count); context->vertex_array = old_vertex_array; } void dl_execute_DrawBuffer(struct GLContextIFace *Self, const DLOperation *op){ Self->GLDrawBuffer(op->opData.e); } void dl_execute_ReadBuffer(struct GLContextIFace *Self, const DLOperation *op){ Self->GLReadBuffer(op->opData.e); } void dl_execute_DrawElements(struct GLContextIFace *Self, const DLOperation *op){ DrawElementsData *data = op->opData.data; GLcontext context = GET_INSTANCE(Self); struct GLvertex_array_state old_vertex_array = context->vertex_array; context->vertex_array = data->vertex_array; Self->GLDrawElements(data->mode, data->count, data->type, data->indices); context->vertex_array = old_vertex_array; } void dl_execute_End(struct GLContextIFace *Self, const DLOperation *op){ Self->GLEnd(); } void dl_execute_Fogf(struct GLContextIFace *Self, const DLOperation *op){ FogfData *data = op->opData.data; Self->GLFogf(data->pname, data->param); } void dl_execute_Fogfv(struct GLContextIFace *Self, const DLOperation *op){ FogfvData *data = op->opData.data; Self->GLFogfv(data->pname, data->params); } void dl_execute_FrontFace(struct GLContextIFace *Self, const DLOperation *op){ Self->GLFrontFace(op->opData.e); } void dl_execute_Frustum(struct GLContextIFace *Self, const DLOperation *op){ GLdouble *data = op->opData.data; Self->GLFrustum(data[0], data[1], data[2], data[3], data[4], data[5]); } void dl_execute_Hint(struct GLContextIFace *Self, const DLOperation *op){ GLenum *data = op->opData.data; Self->GLHint(data[0], data[1]); } void dl_execute_Lightf(struct GLContextIFace *Self, const DLOperation *op){ LightfData *data = op->opData.data; Self->GLLightf(data->light, data->pname, data->param); } void dl_execute_Lightfv(struct GLContextIFace *Self, const DLOperation *op){ LightfvData *data = op->opData.data; Self->GLLightfv(data->light, data->pname, data->params); } void dl_execute_Lightiv(struct GLContextIFace *Self, const DLOperation *op){ LightivData *data = op->opData.data; Self->GLLightiv(data->light, data->pname, data->params); } void dl_execute_LightModelf(struct GLContextIFace *Self, const DLOperation *op){ LightModelfData *data = op->opData.data; Self->GLLightModelf(data->pname, data->param); } void dl_execute_LightModelfv(struct GLContextIFace *Self, const DLOperation *op){ LightModelfvData *data = op->opData.data; Self->GLLightModelfv(data->pname, data->params); } void dl_execute_LightModeliv(struct GLContextIFace *Self, const DLOperation *op){ LightModelivData *data = op->opData.data; Self->GLLightModeliv(data->pname, data->params); } void dl_execute_LineWidth(struct GLContextIFace *Self, const DLOperation *op){ Self->GLLineWidth(op->opData.f); } void dl_execute_LineStipple(struct GLContextIFace *Self, const DLOperation *op){ LineStippleData *data = op->opData.data; Self->GLLineStipple(data->factor, data->pattern); } void dl_execute_ListBase(struct GLContextIFace *Self, const DLOperation *op){ Self->GLListBase(op->opData.ui); } void dl_execute_LoadIdentity(struct GLContextIFace *Self, const DLOperation *op){ Self->GLLoadIdentity(); } void dl_execute_LoadMatrixf(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLLoadMatrixf(data); } void dl_execute_LoadMatrixd(struct GLContextIFace *Self, const DLOperation *op){ GLdouble *data = op->opData.data; Self->GLLoadMatrixd(data); } void dl_execute_Materialf(struct GLContextIFace *Self, const DLOperation *op){ MaterialfData *data = op->opData.data; Self->GLMaterialf(data->face, data->pname, data->param); } void dl_execute_Materialfv(struct GLContextIFace *Self, const DLOperation *op){ MaterialFVData *data = op->opData.data; Self->GLMaterialfv(data->face, data->pname, data->params); } void dl_execute_Materialiv(struct GLContextIFace *Self, const DLOperation *op){ MaterialIVData *data = op->opData.data; Self->GLMaterialiv(data->face, data->pname, data->params); } void dl_execute_MatrixMode(struct GLContextIFace *Self, const DLOperation *op){ Self->GLMatrixMode(op->opData.e); } void dl_execute_MultiTexCoord2f(struct GLContextIFace *Self, const DLOperation *op){ MultiTexCoord2fData *data = op->opData.data; Self->GLMultiTexCoord2f(data->target, data->s, data->t); } void dl_execute_MultiTexCoord4f(struct GLContextIFace *Self, const DLOperation *op){ MultiTexCoord4fData *data = op->opData.data; Self->GLMultiTexCoord4f(data->target, data->s, data->t, data->r, data->q); } void dl_execute_MultMatrixf(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLMultMatrixf(data); } void dl_execute_MultMatrixd(struct GLContextIFace *Self, const DLOperation *op){ GLdouble *data = op->opData.data; Self->GLMultMatrixd(data); } void dl_execute_Normal3f(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLNormal3f(data[0], data[1], data[2]); } void dl_execute_Ortho(struct GLContextIFace *Self, const DLOperation *op){ GLdouble *data = op->opData.data; Self->GLOrtho(data[0], data[1], data[2], data[3], data[4], data[5]); } void dl_execute_PinTexture(struct GLContextIFace *Self, const DLOperation *op){ Self->PinTexture(op->opData.ui); } void dl_execute_PointSize(struct GLContextIFace *Self, const DLOperation *op){ Self->GLPointSize(op->opData.f); } void dl_execute_PolygonMode(struct GLContextIFace *Self, const DLOperation *op){ GLenum *data = op->opData.data; Self->GLPolygonMode(data[0], data[1]); } void dl_execute_PolygonStipple(struct GLContextIFace *Self, const DLOperation *op){ PolygonStippleData *data = (PolygonStippleData*) op->opData.data; BEGIN_IMAGEUPLOAD Self->GLPolygonStipple(data->pattern); END_IMAGEUPLOAD } void dl_execute_PolygonOffset(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLPolygonOffset(data[0], data[1]); } void dl_execute_PopAttrib(struct GLContextIFace *Self, const DLOperation *op){ Self->GLPopAttrib(); } void dl_execute_PopMatrix(struct GLContextIFace *Self, const DLOperation *op){ Self->GLPopMatrix(); } void dl_execute_PushAttrib(struct GLContextIFace *Self, const DLOperation *op){ Self->GLPushAttrib(op->opData.bf); } void dl_execute_PushMatrix(struct GLContextIFace *Self, const DLOperation *op){ Self->GLPushMatrix(); } void dl_execute_RasterPos4f(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLRasterPos4f(data[0], data[1], data[2], data[3]); } void dl_execute_Rectf(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLRectf(data[0], data[1], data[2], data[3]); } void dl_execute_Rotatef(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLRotatef(data[0], data[1], data[2], data[3]); } void dl_execute_Scalef(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLScalef(data[0], data[1], data[2]); } void dl_execute_Scissor(struct GLContextIFace *Self, const DLOperation *op){ ScissorData *data = op->opData.data; Self->GLScissor(data->x, data->y, data->width, data->height); } void dl_execute_SetState(struct GLContextIFace *Self, const DLOperation *op){ SetStateData *data = op->opData.data; Self->SetState(data->cap, data->flag); } void dl_execute_SetTextureRenderTarget(struct GLContextIFace *Self, const DLOperation *op){ Self->SetTextureRenderTarget(op->opData.ui); } void dl_execute_SetZOffset(struct GLContextIFace *Self, const DLOperation *op){ Self->SetZOffset(op->opData.f); } void dl_execute_ShadeModel(struct GLContextIFace *Self, const DLOperation *op){ Self->GLShadeModel(op->opData.e); } void dl_execute_StencilFunc(struct GLContextIFace *Self, const DLOperation *op){ StencilFuncData *data = op->opData.data; Self->GLStencilFunc(data->func, data->ref, data->mask); } void dl_execute_StencilMask(struct GLContextIFace *Self, const DLOperation *op){ Self->GLStencilMask(op->opData.ui); } void dl_execute_StencilOp(struct GLContextIFace *Self, const DLOperation *op){ GLenum *data = op->opData.data; Self->GLStencilOp(data[0], data[1], data[2]); } void dl_execute_TexCoord2f(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLTexCoord2f(data[0], data[1]); } void dl_execute_TexCoord4f(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLTexCoord4f(data[0], data[1], data[2], data[3]); } void dl_execute_TexEnvi(struct GLContextIFace *Self, const DLOperation *op){ TexEnviData *data = op->opData.data; Self->GLTexEnvi(data->target, data->pname, data->param); } void dl_execute_TexEnvfv(struct GLContextIFace *Self, const DLOperation *op){ TexEnvfvData *data = op->opData.data; Self->GLTexEnvfv(data->target, data->pname, data->params); } void dl_execute_TexGeni(struct GLContextIFace *Self, const DLOperation *op){ TexGeniData *data = op->opData.data; Self->GLTexGeni(data->coord, data->pname, data->param); } void dl_execute_TexGenfv(struct GLContextIFace *Self, const DLOperation *op){ TexGenfvData *data = op->opData.data; Self->GLTexGenfv(data->coord, data->pname, data->params); } void dl_execute_TexImage2D(struct GLContextIFace *Self, const DLOperation *op){ TexImage2DData *data = (TexImage2DData*) op->opData.data; BEGIN_IMAGEUPLOAD Self->GLTexImage2D(data->target, data->level, data->internalformat, data->width, data->height, data->border, data->format, data->type, (GLvoid*)data->pixels); END_IMAGEUPLOAD } void dl_execute_TexParameteri(struct GLContextIFace *Self, const DLOperation *op){ TexParameteriData *data= op->opData.data; Self->GLTexParameteri(data->target, data->pname, data->param); } void dl_execute_TexSubImage2D(struct GLContextIFace *Self, const DLOperation *op){ TexSubImage2DData *data = (TexSubImage2DData*) op->opData.data; BEGIN_IMAGEUPLOAD Self->GLTexSubImage2D(data->target, data->level, data->xoffset, data->yoffset, data->width, data->height, data->format, data->type, (GLvoid*)data->pixels); END_IMAGEUPLOAD } void dl_execute_Translatef(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data= op->opData.data; Self->GLTranslatef(data[0], data[1], data[2]); } void dl_execute_UnpinTexture(struct GLContextIFace *Self, const DLOperation *op){ Self->UnpinTexture(op->opData.ui); } void dl_execute_Vertex4f(struct GLContextIFace *Self, const DLOperation *op){ GLfloat *data = op->opData.data; Self->GLVertex4f(data[0], data[1], data[2], data[3]); } void dl_execute_Viewport(struct GLContextIFace *Self, const DLOperation *op){ ViewportData *data = op->opData.data; Self->GLViewport(data->x, data->y, data->width, data->height); } void dl_execute_InitNames(struct GLContextIFace *Self, const DLOperation *op) { Self->GLInitNames(); } void dl_execute_LoadName(struct GLContextIFace *Self, const DLOperation *op) { GLuint name = op->opData.ui; Self->GLLoadName(name); } void dl_execute_PushName(struct GLContextIFace *Self, const DLOperation *op) { GLuint name = op->opData.ui; Self->GLPushName(name); } void dl_execute_PopName(struct GLContextIFace *Self, const DLOperation *op) { Self->GLPopName(); } void dl_execute_Map1f(struct GLContextIFace *Self, const DLOperation *op) { Map1fData *data = op->opData.data; Self->GLMap1f(data->target, data->u1, data->u2, eval_GetMapK1(data->target), data->order, &data->points[0]); } void dl_execute_Map1d(struct GLContextIFace *Self, const DLOperation *op) { Map1dData *data = op->opData.data; Self->GLMap1d(data->target, data->u1, data->u2, eval_GetMapK1(data->target), data->order, &data->points[0]); } void dl_execute_EvalCoord1f(struct GLContextIFace *Self, const DLOperation *op) { EvalCoord1Data *data = op->opData.data; Self->GLEvalCoord1f(data->arg); } void dl_execute_MapGrid1f(struct GLContextIFace *Self, const DLOperation *op) { MapGrid1Data *data = op->opData.data; Self->GLMapGrid1f(data->n, data->u1, data->u2); } void dl_execute_EvalMesh1(struct GLContextIFace *Self, const DLOperation *op) { EvalMesh1Data *data = op->opData.data; Self->GLEvalMesh1(data->mode, data->p1, data->p2); } void dl_execute_EvalPoint1(struct GLContextIFace *Self, const DLOperation *op) { EvalPoint1Data *data = op->opData.data; Self->GLEvalPoint1(data->p); } void dl_execute_Map2f(struct GLContextIFace *Self, const DLOperation *op) { Map2fData *data = op->opData.data; Self->GLMap2f(data->target, data->u1, data->u2, eval_GetMapK2(data->target) * data->vorder, data->uorder, data->v1, data->v2, eval_GetMapK2(data->target), data->vorder, &data->points[0]); } void dl_execute_Map2d(struct GLContextIFace *Self, const DLOperation *op) { Map2dData *data = op->opData.data; Self->GLMap2d(data->target, data->u1, data->u2, eval_GetMapK2(data->target) * data->vorder, data->uorder, data->v1, data->v2, eval_GetMapK2(data->target), data->vorder, &data->points[0]); } void dl_execute_EvalCoord2f(struct GLContextIFace *Self, const DLOperation *op) { EvalCoord2Data *data = op->opData.data; Self->GLEvalCoord2f(data->u, data->v); } void dl_execute_MapGrid2f(struct GLContextIFace *Self, const DLOperation *op) { MapGrid2Data *data = op->opData.data; Self->GLMapGrid2f(data->nu, data->u1, data->u2, data->nv, data->v1, data->v2); } void dl_execute_EvalMesh2(struct GLContextIFace *Self, const DLOperation *op) { EvalMesh2Data *data = op->opData.data; Self->GLEvalMesh2(data->mode, data->p1, data->p2, data->q1, data->q2); } void dl_execute_EvalPoint2(struct GLContextIFace *Self, const DLOperation *op) { EvalPoint2Data *data = op->opData.data; Self->GLEvalPoint2(data->p, data->q); } void dl_execute_PixelTransfer(struct GLContextIFace *Self, const DLOperation *op) { PixelTransferData *data = op->opData.data; Self->GLPixelTransferf(data->param, data->value); } void dl_execute_PixelZoom(struct GLContextIFace *Self, const DLOperation *op) { PixelZoomData *data = op->opData.data; Self->GLPixelZoom(data->zoom_x, data->zoom_y); } void dl_execute_CopyPixels(struct GLContextIFace *Self, const DLOperation *op) { CopyPixelData *data = op->opData.data; Self->GLCopyPixels(data->x, data->y, data->width, data->height, data->type); } void dl_execute_LogicOp(struct GLContextIFace *Self, const DLOperation *op) { LogicOpModeData *data = op->opData.data; Self->GLLogicOp(data->op); } // ----- Save Functions ----- void dl_save_ActiveTexture(struct GLContextIFace *Self, GLenum unit){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ActiveTexture; newOp->opData.e = unit; } void dl_save_AlphaFunc(struct GLContextIFace *Self, GLenum func, GLclampf ref){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(AlphaFuncData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_AlphaFunc; AlphaFuncData *data = (AlphaFuncData*)newOp->opData.data; data->func = func; data->ref = ref; } void dl_save_BlendFunc(struct GLContextIFace *Self, GLenum sfactor, GLenum dfactor){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLenum) * 2); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_BlendFunc; GLenum *data = (GLenum*)newOp->opData.data; data[0] = sfactor; data[1] = dfactor; } void dl_save_Begin(struct GLContextIFace *Self, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Begin; newOp->opData.e = mode; } void dl_save_BindTexture(struct GLContextIFace *Self, GLenum target, GLuint texture){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(BindTextureData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_BindTexture; BindTextureData *data = (BindTextureData*)newOp->opData.data; data->target = target; data->texture = texture; } void dl_save_Bitmap(struct GLContextIFace *Self, GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLvoid *bitmap){ GLcontext context = GET_INSTANCE(Self); GLuint bitmapSize = dl_imageSize(width, height, 0, GL_COLOR_INDEX, GL_BITMAP); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(BitmapData) + bitmapSize - 1); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Bitmap; BitmapData *data = (BitmapData*)newOp->opData.data; data->width = width; data->height = height; data->xorig = xorig; data->yorig = yorig; data->xmove = xmove; data->ymove = ymove; dl_copyImage(Self, 0, 0, width, height, 0, GL_COLOR_INDEX, GL_BITMAP, bitmap, (GLvoid*)data->bitmap); } void dl_save_DrawPixels(struct GLContextIFace *Self, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) { GLcontext context = GET_INSTANCE(Self); GLuint imageSize = dl_imageSize(width, height, 0, format, type); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(DrawPixelsData) + imageSize -1); if (!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_DrawPixels; DrawPixelsData *data = (DrawPixelsData *)newOp->opData.data; data->width = width; data->height = height; data->type = type; data->format = format; dl_copyImage(Self, 0, 0, width, height, 0, format, type, pixels, (GLvoid*)data->pixels); } void dl_save_CallList(struct GLContextIFace *Self, GLuint list) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_CallList; newOp->opData.ui = list; } void dl_save_CallLists(struct GLContextIFace *Self, GLsizei n, GLenum type, const GLvoid *lists){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(CallListsData) + sizeof(GLuint) * (n - 1)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_CallLists; CallListsData *data = (CallListsData*)newOp->opData.data; GLuint *listIds = (GLuint*)lists; for(int i = 0; i < n; i++){ data->lists[i] = listIds[i]; } } void dl_save_Clear(struct GLContextIFace *Self, GLbitfield mask){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Clear; newOp->opData.bf = mask; } void dl_save_ClearColor(struct GLContextIFace *Self, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLclampf) * 4); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ClearColor; GLclampf *data = (GLclampf*)newOp->opData.data; data[0] = red; data[1] = green; data[2] = blue; data[3] = alpha; } void dl_save_ClearDepth(struct GLContextIFace *Self, GLclampd depth){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ClearDepth; newOp->opData.cd = depth; } void dl_save_ClearStencil(struct GLContextIFace *Self, GLint s){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ClearStencil; newOp->opData.i = s; } void dl_save_ClipPlane(struct GLContextIFace *Self, GLenum plane, const GLdouble *equ){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(ClipPlaneData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ClipPlane; ClipPlaneData *data = (ClipPlaneData*)newOp->opData.data; data->plane = plane; data->equ[0] = equ[0]; data->equ[1] = equ[1]; data->equ[2] = equ[2]; data->equ[3] = equ[3]; } void dl_save_Color4f(struct GLContextIFace *Self, GLfloat r, GLfloat g, GLfloat b, GLfloat a){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 4); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Color4f; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = r; data[1] = g; data[2] = b; data[3] = a; } void dl_save_ColorMask(struct GLContextIFace *Self, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLboolean) * 4); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ColorMask; GLboolean *data = (GLboolean*)newOp->opData.data; data[0] = red; data[1] = green; data[2] = blue; data[3] = alpha; } void dl_save_ColorMaterial(struct GLContextIFace *Self, GLenum face, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLenum) * 2); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ColorMaterial; GLenum *data = (GLenum*)newOp->opData.data; data[0] = face; data[1] = mode; } void dl_save_ColorTable(struct GLContextIFace *Self, GLenum target, GLenum internalformat, GLint width, GLenum format, GLenum type, const GLvoid* data){ GLcontext context = GET_INSTANCE(Self); GLuint elementSize, typeSize; switch(format){ case GL_RED: case GL_GREEN: case GL_BLUE: case GL_ALPHA: case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: elementSize = 1; break; case GL_RGB: case GL_BGR: elementSize = 3; break; case GL_RGBA: case GL_BGRA: elementSize = 4; default: context->DisplayListCompileError = GL_INVALID_VALUE; return; } switch(type){ case GL_UNSIGNED_BYTE: case GL_BYTE: case GL_UNSIGNED_BYTE_3_3_2: case GL_UNSIGNED_BYTE_2_3_3_REV: typeSize = sizeof(GLbyte); break; case GL_UNSIGNED_SHORT: case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5_REV: case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: case GL_SHORT: typeSize = sizeof(GLshort); break; case GL_UNSIGNED_INT: case GL_INT: case GL_UNSIGNED_INT_8_8_8_8: case GL_UNSIGNED_INT_8_8_8_8_REV: case GL_UNSIGNED_INT_10_10_10_2: // case GL_UNSIGNED_INT_2_10_10_10_RE: typeSize = sizeof(GLint); break; case GL_FLOAT: typeSize = sizeof(GLfloat); break; default: context->DisplayListCompileError = GL_INVALID_VALUE; return; } GLuint tableSize = width * elementSize *typeSize; DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(ColorTableData) + tableSize - 1); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ColorTable; ColorTableData *opData = (ColorTableData*)newOp->opData.data; opData->target = target; opData->internalformat = internalformat; opData->width = width; opData->format = format; opData->type = type; GLubyte *ubData = (GLubyte*)data; for(GLuint i = 0; i < tableSize; i++){ opData->data[i] = ubData[i]; } } void dl_save_CopyTexImage2D(struct GLContextIFace *Self, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(CopyTexImage2DData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_CopyTexImage2D; CopyTexImage2DData *data = (CopyTexImage2DData*)newOp->opData.data; data->target = target; data->level = level; data->internalFormat = internalFormat; data->x = x; data->y = y; data->width = width; data->height = height; data->border = border; } extern void dl_save_CopyTexSubImage2D(struct GLContextIFace *Self, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(CopyTexSubImage2DData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexSubImage2D; CopyTexSubImage2DData *data = (CopyTexSubImage2DData*)newOp->opData.data; data->target = target; data->level = level; data->xoffset = xoffset; data->yoffset = yoffset; data->x = x; data->y = y; data->width = width; data->height = height; } void dl_save_CullFace(struct GLContextIFace *Self, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_CullFace; newOp->opData.e = mode; } void dl_save_DepthFunc(struct GLContextIFace *Self, GLenum func){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_DepthFunc; newOp->opData.e = func; } void dl_save_DepthMask(struct GLContextIFace *Self, GLboolean mask){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_DepthMask; newOp->opData.b = mask; } void dl_save_DepthRange(struct GLContextIFace *Self, GLclampd nearval, GLclampd farval){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLclampd) * 2); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_DepthRange; GLclampd *data = (GLclampd*)newOp->opData.data; data[0] = nearval; data[1] = farval; } void dl_save_DrawArrays(struct GLContextIFace *Self, GLenum mode, GLint first, GLsizei count){ GLcontext context = GET_INSTANCE(Self); int vertexArraySize = dl_getVertexArraySize(context, count); if(vertexArraySize == 0) { context->DisplayListCompileError = GL_INVALID_VALUE; return; } DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(DrawArraysData) + vertexArraySize); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_DrawArrays; DrawArraysData *data = (DrawArraysData*)newOp->opData.data; data->mode = mode; data->first = first; data->count = count; // Now copying the vertex array into the vertex array buffer void *vertexArrayBuffer = ((uint8*)data + sizeof(DrawArraysData)); dl_copyVertexArray(context, &(data->vertex_array), vertexArrayBuffer, first, count); } void dl_save_DrawBuffer(struct GLContextIFace *Self, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_DrawBuffer; newOp->opData.e = mode; } void dl_save_ReadBuffer(struct GLContextIFace *Self, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ReadBuffer; newOp->opData.e = mode; } void dl_save_DrawElements(struct GLContextIFace *Self, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices){ GLcontext context = GET_INSTANCE(Self); GLsizei elementSize; switch(type){ case GL_UNSIGNED_BYTE: elementSize = sizeof(GLubyte); break; case GL_UNSIGNED_SHORT: elementSize = sizeof(GLushort); break; case GL_UNSIGNED_INT: elementSize = sizeof(GLuint); break; default: context->DisplayListCompileError = GL_INVALID_VALUE; return; } int indexArraySize = count * elementSize; int dataPlusIndexSize = indexArraySize + sizeof(DrawElementsData) + 4 - indexArraySize % 4; // ensure alignment of following vertexArray GLsizei vertexArrayCount = dl_getVertexArrayCountFromIndices(count, type, indices); if(vertexArrayCount == 0) { context->DisplayListCompileError = GL_INVALID_VALUE; return; } int vertexArraySize = dl_getVertexArraySize(context, vertexArrayCount); if(vertexArraySize == 0) { context->DisplayListCompileError = GL_INVALID_VALUE; return; } DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, dataPlusIndexSize + vertexArraySize); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_DrawElements; DrawElementsData *data = (DrawElementsData*)newOp->opData.data; data->mode = mode; data->count = count; data->type = type; // Copy the index array switch(type){ case GL_UNSIGNED_BYTE: { GLubyte *srcIndices = (GLubyte*) indices; GLubyte *destIndices = (GLubyte*) data->indices; for(GLsizei i = 0; i < count; i++){ destIndices[i] = srcIndices[i]; } break; } case GL_UNSIGNED_SHORT: { GLushort *srcIndices = (GLushort*) indices; GLushort *destIndices = (GLushort*) data->indices; for(GLsizei i = 0; i < count; i++){ destIndices[i] = srcIndices[i]; } break; } case GL_UNSIGNED_INT: { GLuint *srcIndices = (GLuint*) indices; GLuint *destIndices = (GLuint*) data->indices; for(GLsizei i = 0; i < count; i++){ destIndices[i] = srcIndices[i]; } break; } default: context->DisplayListCompileError = GL_INVALID_VALUE; } // Now copying the vertex array into the vertex array buffer void *vertexArrayBuffer = ((uint8*)data + dataPlusIndexSize); dl_copyVertexArray(context, &(data->vertex_array), vertexArrayBuffer, 0, vertexArrayCount); } void dl_save_End(struct GLContextIFace *Self){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_End; } void dl_save_Fogf(struct GLContextIFace *Self, GLenum pname, GLfloat param){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(FogfData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Fogf; FogfData *data = (FogfData*)newOp->opData.data; data->pname = pname; data->param = param; } void dl_save_Fogfv(struct GLContextIFace *Self, GLenum pname, const GLfloat *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp; if(pname == GL_FOG_COLOR){ newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(FogfvData) + sizeof(GLfloat) * 3); } else{ newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(FogfvData)); } if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Fogfv; FogfvData *data = (FogfvData*)newOp->opData.data; data->pname = pname; data->params[0] = params[0]; if(pname == GL_FOG_COLOR){ data->params[1] = params[1]; data->params[2] = params[2]; data->params[3] = params[3]; } } void dl_save_FrontFace(struct GLContextIFace *Self, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_FrontFace; newOp->opData.e = mode; } void dl_save_Frustum(struct GLContextIFace *Self, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLdouble) * 6); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Frustum; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = left; data[1] = right; data[2] = bottom; data[3] = top; data[4] = nearval; data[5] = farval; } void dl_save_Hint(struct GLContextIFace *Self, GLenum target, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLenum) * 2); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Hint; GLenum *data = (GLenum*)newOp->opData.data; data[0] = target; data[1] = mode; } void dl_save_Lightf(struct GLContextIFace *Self, GLenum light, GLenum pname, GLfloat param){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(LightfData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Lightf; LightfData *data = (LightfData*)newOp->opData.data; data->light = light; data->pname = pname; data->param = param; } void dl_save_Lightfv(struct GLContextIFace *Self, GLenum light, GLenum pname, const GLfloat *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(LightfvData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Lightfv; LightfvData *data = (LightfvData*)newOp->opData.data; data->light = light; data->pname = pname; data->params[0] = params[0]; switch(pname){ case GL_AMBIENT: case GL_DIFFUSE: case GL_SPECULAR: case GL_POSITION: data->params[3] = params[3]; case GL_SPOT_DIRECTION: data->params[1] = params[1]; data->params[2] = params[2]; } } void dl_save_Lightiv(struct GLContextIFace *Self, GLenum light, GLenum pname, const GLint *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(LightivData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Lightiv; LightivData *data = (LightivData*)newOp->opData.data; data->light = light; data->pname = pname; data->params[0] = params[0]; switch(pname){ case GL_AMBIENT: case GL_DIFFUSE: case GL_SPECULAR: case GL_POSITION: data->params[3] = params[3]; case GL_SPOT_DIRECTION: data->params[1] = params[1]; data->params[2] = params[2]; } } void dl_save_LightModelf(struct GLContextIFace *Self, GLenum pname, GLfloat param){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(LightModelfData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Lightf; LightModelfData *data = (LightModelfData*)newOp->opData.data; data->pname = pname; data->param = param; } void dl_save_LightModelfv(struct GLContextIFace *Self, GLenum pname, const GLfloat *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(LightModelfvData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LightModelfv; LightModelfvData *data = (LightModelfvData*)newOp->opData.data; data->pname = pname; data->params[0] = params[0]; if(pname == GL_LIGHT_MODEL_AMBIENT){ data->params[1] = params[1]; data->params[2] = params[2]; data->params[3] = params[3]; } } void dl_save_LightModeliv(struct GLContextIFace *Self, GLenum pname, const GLint *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(LightModelivData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LightModeliv; LightModelivData *data = (LightModelivData*)newOp->opData.data; data->pname = pname; data->params[0] = params[0]; if(pname == GL_LIGHT_MODEL_AMBIENT){ data->params[1] = params[1]; data->params[2] = params[2]; data->params[3] = params[3]; } } void dl_save_LineWidth(struct GLContextIFace *Self, GLfloat width){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LineWidth; newOp->opData.f = width; } void dl_save_LineStipple(struct GLContextIFace *Self, GLint factor, GLushort pattern){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(LineStippleData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LineStipple; LineStippleData *data = (LineStippleData*)newOp->opData.data; data->factor = factor; data->pattern = pattern; } void dl_save_ListBase(struct GLContextIFace *Self, GLuint base){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ListBase; newOp->opData.ui = base; } void dl_save_LoadIdentity(struct GLContextIFace *Self){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LoadIdentity; } void dl_save_LoadMatrixf(struct GLContextIFace *Self, const GLfloat *m){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 16); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LoadMatrixf; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = m[0]; data[1] = m[1]; data[2] = m[2]; data[3] = m[3]; data[4] = m[4]; data[5] = m[5]; data[6] = m[6]; data[7] = m[7]; data[8] = m[8]; data[9] = m[9]; data[10] = m[10]; data[11] = m[11]; data[12] = m[12]; data[13] = m[13]; data[14] = m[14]; data[15] = m[15]; } void dl_save_LoadMatrixd(struct GLContextIFace *Self, const GLdouble *m){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLdouble) * 16); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LoadMatrixd; GLdouble *data = (GLdouble*)newOp->opData.data; data[0] = m[0]; data[1] = m[1]; data[2] = m[2]; data[3] = m[3]; data[4] = m[4]; data[5] = m[5]; data[6] = m[6]; data[7] = m[7]; data[8] = m[8]; data[9] = m[9]; data[10] = m[10]; data[11] = m[11]; data[12] = m[12]; data[13] = m[13]; data[14] = m[14]; data[15] = m[15]; } void dl_save_Materialf(struct GLContextIFace *Self, GLenum face, GLenum pname, GLfloat param){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(MaterialfData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } newOp->opFunc = dl_execute_Materialf; MaterialfData *data = (MaterialfData*)newOp->opData.data; data->face = face; data->pname = pname; data->param = param; context->TargetDisplayListEnd = newOp; } void dl_save_Materialfv(struct GLContextIFace *Self, GLenum face, GLenum pname, const GLfloat *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(MaterialFVData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } newOp->opFunc = dl_execute_Materialfv; MaterialFVData *data = (MaterialFVData*)newOp->opData.data; data->face = face; data->pname = pname; context->TargetDisplayListEnd = newOp; switch(pname){ case GL_SHININESS: data->params[0] = *params; break; case GL_AMBIENT: case GL_DIFFUSE: case GL_SPECULAR: case GL_EMISSION: case GL_AMBIENT_AND_DIFFUSE: data->params[0] = params[0]; data->params[1] = params[1]; data->params[2] = params[2]; data->params[3] = params[3]; break; case GL_COLOR_INDEXES: data->params[0] = params[0]; data->params[1] = params[1]; data->params[2] = params[2]; break; } } void dl_save_Materialiv(struct GLContextIFace *Self, GLenum face, GLenum pname, const GLint *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(MaterialFVData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } newOp->opFunc = dl_execute_Materialiv; MaterialIVData *data = (MaterialIVData*)newOp->opData.data; data->face = face; data->pname = pname; context->TargetDisplayListEnd = newOp; switch(pname){ case GL_SHININESS: data->params[0] = *params; break; case GL_AMBIENT: case GL_DIFFUSE: case GL_SPECULAR: case GL_EMISSION: case GL_AMBIENT_AND_DIFFUSE: data->params[0] = params[0]; data->params[1] = params[1]; data->params[2] = params[2]; data->params[3] = params[3]; break; case GL_COLOR_INDEXES: data->params[0] = params[0]; data->params[1] = params[1]; data->params[2] = params[2]; break; } } void dl_save_MatrixMode(struct GLContextIFace *Self, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_MatrixMode; newOp->opData.e = mode; } void dl_save_MultiTexCoord2f(struct GLContextIFace *Self, GLenum target, GLfloat s, GLfloat t){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(MultiTexCoord2fData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } newOp->opFunc = dl_execute_MultiTexCoord2f; MultiTexCoord2fData *data = (MultiTexCoord2fData*)newOp->opData.data; data->target = target; data->s = s; data->t = t; } void dl_save_MultiTexCoord4f(struct GLContextIFace *Self, GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(MultiTexCoord4fData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } newOp->opFunc = dl_execute_MultiTexCoord4f; MultiTexCoord4fData *data = (MultiTexCoord4fData*)newOp->opData.data; data->target = target; data->s = s; data->t = t; data->r = r; data->q = q; } void dl_save_MultMatrixf(struct GLContextIFace *Self, const GLfloat *m){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 16); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_MultMatrixf; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = m[0]; data[1] = m[1]; data[2] = m[2]; data[3] = m[3]; data[4] = m[4]; data[5] = m[5]; data[6] = m[6]; data[7] = m[7]; data[8] = m[8]; data[9] = m[9]; data[10] = m[10]; data[11] = m[11]; data[12] = m[12]; data[13] = m[13]; data[14] = m[14]; data[15] = m[15]; } void dl_save_MultMatrixd(struct GLContextIFace *Self, const GLdouble *m){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLdouble) * 16); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_MultMatrixd; GLdouble *data = (GLdouble*)newOp->opData.data; data[0] = m[0]; data[1] = m[1]; data[2] = m[2]; data[3] = m[3]; data[4] = m[4]; data[5] = m[5]; data[6] = m[6]; data[7] = m[7]; data[8] = m[8]; data[9] = m[9]; data[10] = m[10]; data[11] = m[11]; data[12] = m[12]; data[13] = m[13]; data[14] = m[14]; data[15] = m[15]; } void dl_save_Normal3f(struct GLContextIFace *Self, GLfloat nx, GLfloat ny, GLfloat nz){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 3); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Normal3f; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = nx; data[1] = ny; data[2] = nz; } void dl_save_Ortho(struct GLContextIFace *Self, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLdouble) * 6); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Ortho; GLdouble *data = (GLdouble*)newOp->opData.data; data[0] = left; data[1] = right; data[2] = bottom; data[3] = top; data[4] = nearval; data[5] = farval; } void dl_save_PinTexture(struct GLContextIFace *Self, GLuint texnum){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PinTexture; newOp->opData.ui = texnum; } void dl_save_PointSize(struct GLContextIFace *Self, GLfloat size){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PointSize; newOp->opData.f = size; } void dl_save_PolygonMode(struct GLContextIFace *Self, GLenum face, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLenum) * 2); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PolygonMode; GLenum *data = (GLenum*)newOp->opData.data; data[0] = face; data[1] = mode; } void dl_save_PolygonStipple(struct GLContextIFace *Self, const GLubyte *pattern){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(PolygonStippleData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PolygonStipple; PolygonStippleData *data = (PolygonStippleData*)newOp->opData.data; dl_copyImage(Self, 0, 0, 32, 32, 0, GL_COLOR_INDEX, GL_BITMAP, (GLvoid*)pattern, (GLvoid*)data->pattern); } void dl_save_PolygonOffset(struct GLContextIFace *Self, GLfloat factor, GLfloat units){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 2); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PolygonOffset; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = factor; data[1] = units; } void dl_save_PopAttrib(struct GLContextIFace *Self){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PopAttrib; } void dl_save_PopMatrix(struct GLContextIFace *Self){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PopMatrix; } void dl_save_PushAttrib(struct GLContextIFace *Self, GLbitfield mask){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PushAttrib; newOp->opData.bf = mask; } void dl_save_PushMatrix(struct GLContextIFace *Self){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PushMatrix; } void dl_save_RasterPos4f(struct GLContextIFace *Self, GLfloat x, GLfloat y, GLfloat z, GLfloat w){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 4); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_RasterPos4f; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = x; data[1] = y; data[2] = z; data[3] = w; } void dl_save_Rectf(struct GLContextIFace *Self, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 4); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Rectf; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = x1; data[1] = y1; data[2] = x2; data[3] = y2; } void dl_save_Rotatef(struct GLContextIFace *Self, GLfloat angle, GLfloat x, GLfloat y, GLfloat z){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 4); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Rotatef; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = angle; data[1] = x; data[2] = y; data[3] = z; } void dl_save_Scalef(struct GLContextIFace *Self, GLfloat x, GLfloat y, GLfloat z){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 3); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Scalef; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = x; data[1] = y; data[2] = z; } void dl_save_Scissor(struct GLContextIFace *Self, GLint x, GLint y, GLsizei width, GLsizei height){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(ScissorData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Scissor; ScissorData *data = (ScissorData*)newOp->opData.data; data->x = x; data->y = y; data->width = width; data->height = height; } void dl_save_SetState(struct GLContextIFace *Self, GLenum cap, GLboolean flag){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(SetStateData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_SetState; SetStateData *data = (SetStateData*)newOp->opData.data; data->cap = cap; data->flag = flag; } void dl_save_SetZOffset(struct GLContextIFace *Self, GLfloat offset){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_SetZOffset; newOp->opData.f = offset; } void dl_save_SetTextureRenderTarget(struct GLContextIFace *Self, GLuint texnum){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_SetTextureRenderTarget; newOp->opData.ui = texnum; } void dl_save_ShadeModel(struct GLContextIFace *Self, GLenum mode){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_ShadeModel; newOp->opData.e = mode; } void dl_save_StencilFunc(struct GLContextIFace *Self, GLenum func, GLint ref, GLuint mask){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(StencilFuncData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_StencilFunc; StencilFuncData *data = (StencilFuncData*)newOp->opData.data; data->func = func; data->ref = ref; data->mask = mask; } void dl_save_StencilMask(struct GLContextIFace *Self, GLuint mask){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_StencilMask; newOp->opData.ui = mask; } void dl_save_StencilOp(struct GLContextIFace *Self, GLenum fail, GLenum zfail, GLenum zpass){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLenum) * 3); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_StencilOp; GLenum *data = (GLenum*)newOp->opData.data; data[0] = fail; data[1] = zfail; data[2] = zpass; } void dl_save_TexCoord2f(struct GLContextIFace *Self, GLfloat s, GLfloat t){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 2); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexCoord2f; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = s; data[1] = t; } void dl_save_TexCoord4f(struct GLContextIFace *Self, GLfloat s, GLfloat t, GLfloat r, GLfloat q){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 4); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexCoord4f; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = s; data[1] = t; data[2] = r; data[3] = q; } void dl_save_TexEnvi(struct GLContextIFace *Self, GLenum target, GLenum pname, GLint param){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(TexEnviData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexEnvi; TexEnviData *data = (TexEnviData*)newOp->opData.data; data->target = target; data->pname = pname; data->param = param; } void dl_save_TexEnvfv(struct GLContextIFace *Self, GLenum target, GLenum pname, const GLfloat *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(TexEnvfvData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexEnvfv; TexEnvfvData *data = (TexEnvfvData*)newOp->opData.data; data->target = target; data->pname = pname; data->params[0] = params[0]; if(pname == GL_TEXTURE_ENV_COLOR){ data->params[1] = params[1]; data->params[2] = params[2]; data->params[3] = params[3]; } } void dl_save_TexGeni(struct GLContextIFace *Self, GLenum coord, GLenum pname, GLint param){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(TexGeniData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexGeni; TexGeniData *data = (TexGeniData*)newOp->opData.data; data->coord = coord; data->pname = pname; data->param = param; } void dl_save_TexGenfv(struct GLContextIFace *Self, GLenum coord, GLenum pname, const GLfloat *params){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(TexGenfvData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexGenfv; TexGenfvData *data = (TexGenfvData*)newOp->opData.data; data->coord = coord; data->pname = pname; data->params[0] = params[0]; switch(pname){ case GL_OBJECT_PLANE: case GL_EYE_PLANE: data->params[1] = params[1]; data->params[2] = params[2]; data->params[3] = params[3]; } } void dl_save_TexImage2D(struct GLContextIFace *Self, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels){ GLcontext context = GET_INSTANCE(Self); GLuint imageSize = dl_imageSize(width, height, border, format, type); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(TexImage2DData) + imageSize - 1); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexImage2D; TexImage2DData *data = (TexImage2DData*)newOp->opData.data; data->target = target; data->level = level; data->internalformat = internalformat; data->width = width; data->height = height; data->border = border; data->format = format; data->type = type; dl_copyImage(Self, 0, 0, width, height, border, format, type, pixels, (GLvoid*)data->pixels); } void dl_save_TexParameteri(struct GLContextIFace *Self, GLenum target, GLenum pname, const GLint param){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(TexParameteriData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexParameteri; TexParameteriData *data = (TexParameteriData*)newOp->opData.data; data->target = target; data->pname = pname; data->param = param; } void dl_save_TexSubImage2D(struct GLContextIFace *Self, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels){ GLcontext context = GET_INSTANCE(Self); GLuint imageSize = dl_imageSize(width, height, 0, format, type); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(TexSubImage2DData) + imageSize - 1); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_TexSubImage2D; TexSubImage2DData *data = (TexSubImage2DData*)newOp->opData.data; data->target = target; data->level = level; data->xoffset = xoffset; data->yoffset = yoffset; data->width = width; data->height = height; data->format = format; data->type = type; dl_copyImage(Self, 0, 0, width, height, 0, format, type, pixels, (GLvoid*)data->pixels); } void dl_save_Translatef(struct GLContextIFace *Self, GLfloat x, GLfloat y, GLfloat z){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 3); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Translatef; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = x; data[1] = y; data[2] = z; } void dl_save_UnpinTexture(struct GLContextIFace *Self, GLuint texnum){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_UnpinTexture; newOp->opData.ui = texnum; } void dl_save_Vertex4f(struct GLContextIFace *Self, GLfloat x, GLfloat y, GLfloat z, GLfloat w){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(GLfloat) * 4); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Vertex4f; GLfloat *data = (GLfloat*)newOp->opData.data; data[0] = x; data[1] = y; data[2] = z; data[3] = w; } void dl_save_Viewport(struct GLContextIFace *Self, GLint x, GLint y, GLsizei width, GLsizei height){ GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(ViewportData)); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Viewport; ViewportData *data = (ViewportData*)newOp->opData.data; data->x = x; data->y = y; data->width = width; data->height = height; } void dl_save_InitNames(struct GLContextIFace *Self) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_InitNames; } void dl_save_LoadName(struct GLContextIFace *Self, GLuint name) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LoadName; newOp->opData.ui = name; } void dl_save_PushName(struct GLContextIFace *Self, GLuint name) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PushName; newOp->opData.ui = name; } void dl_save_PopName(struct GLContextIFace *Self) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, 0); if(!newOp){ context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PopName; } void dl_save_Map1f(struct GLContextIFace *Self, GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, GLfloat *points) { GLcontext context = GET_INSTANCE(Self); GLuint mapK = eval_GetMapK1(target); GLuint size = mapK * order * sizeof(GLfloat); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(Map1fData) + size); if (!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Map1f; Map1fData *data = (Map1fData *)newOp->opData.data; data->target = target; data->u1 = u1; data->u2 = u2; data->order = order; GLfloat *targetData = &data->points[0]; int i, j; for (i = 0; i < order; i++) { for (j = 0; j < mapK; j++) *targetData++ = (GLfloat)points[j]; points += stride; } } void dl_save_Map1d(struct GLContextIFace *Self, GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, GLdouble *points) { GLcontext context = GET_INSTANCE(Self); GLuint mapK = eval_GetMapK1(target); GLuint size = mapK * order * sizeof(GLdouble); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(Map1fData) + size); if (!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Map1d; Map1dData *data = (Map1dData *)newOp->opData.data; data->target = target; data->u1 = u1; data->u2 = u2; data->order = order; GLdouble *targetData = &data->points[0]; int i, j; for (i = 0; i < order; i++) { for (j = 0; j < mapK; j++) *targetData++ = (GLdouble)points[j]; points += stride; } } void dl_save_EvalCoord1f(struct GLContextIFace *Self, GLfloat arg) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(EvalCoord1Data)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_EvalCoord1f; EvalCoord1Data *data = (EvalCoord1Data *)newOp->opData.data; data->arg = arg; } void dl_save_MapGrid1f(struct GLContextIFace *Self, GLint n, GLfloat u1, GLfloat u2) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(MapGrid1Data)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_MapGrid1f; MapGrid1Data *data = (MapGrid1Data *)newOp->opData.data; data->n = n; data->u1 = u1; data->u2 = u2; } void dl_save_EvalMesh1(struct GLContextIFace *Self, GLenum mode, GLint p1, GLint p2) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(EvalMesh1Data)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_EvalMesh1; EvalMesh1Data *data = (EvalMesh1Data *)newOp->opData.data; data->mode = mode; data->p1 = p1; data->p2 = p2; } void dl_save_EvalPoint1(struct GLContextIFace *Self, GLint p) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(EvalPoint1Data)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_EvalPoint1; EvalPoint1Data *data = (EvalPoint1Data *)newOp->opData.data; data->p = p; } void dl_save_Map2f(struct GLContextIFace *Self, GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat *points) { GLcontext context = GET_INSTANCE(Self); GLuint mapK = eval_GetMapK2(target); GLuint size = mapK * uorder * vorder * sizeof(GLfloat); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(Map2fData) + size); if (!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Map2f; Map2fData *data = (Map2fData *)newOp->opData.data; data->target = target; data->u1 = u1; data->u2 = u2; data->uorder = uorder; data->v1 = v1; data->v2 = v2; data->vorder = vorder; GLfloat *targetData = &data->points[0]; int i, j, k; for (i = 0; i < uorder; i++) { GLfloat *oldPoints = points; for (j = 0; j < vorder; j++) { for (k = 0; k < mapK; k++) *targetData++ = points[k]; points += vstride; } points = oldPoints + ustride; } } void dl_save_Map2d(struct GLContextIFace *Self, GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble *points) { GLcontext context = GET_INSTANCE(Self); GLuint mapK = eval_GetMapK2(target); GLuint size = mapK * uorder * vorder * sizeof(GLdouble); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(Map2dData) + size); if (!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_Map2d; Map2dData *data = (Map2dData *)newOp->opData.data; data->target = target; data->u1 = u1; data->u2 = u2; data->uorder = uorder; data->v1 = v1; data->v2 = v2; data->vorder = vorder; GLdouble *targetData = &data->points[0]; int i, j, k; for (i = 0; i < uorder; i++) { GLdouble *oldPoints = points; for (j = 0; j < vorder; j++) { for (k = 0; k < mapK; k++) *targetData++ = points[k]; points += vstride; } points = oldPoints + ustride; } } void dl_save_EvalCoord2f(struct GLContextIFace *Self, GLfloat u, GLfloat v) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(EvalCoord2Data)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_EvalCoord2f; EvalCoord2Data *data = (EvalCoord2Data *)newOp->opData.data; data->u = u; data->v = v; } void dl_save_MapGrid2f(struct GLContextIFace *Self, GLint nu, GLfloat u1, GLfloat u2, GLint nv, GLfloat v1, GLfloat v2) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(MapGrid2Data)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_MapGrid2f; MapGrid2Data *data = (MapGrid2Data *)newOp->opData.data; data->nu = nu; data->u1 = u1; data->u2 = u2; data->nv = nv; data->v1 = v1; data->v2 = v2; } void dl_save_EvalMesh2(struct GLContextIFace *Self, GLenum mode, GLint p1, GLint p2, GLint q1, GLint q2) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(EvalMesh2Data)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_EvalMesh2; EvalMesh2Data *data = (EvalMesh2Data *)newOp->opData.data; data->mode = mode; data->p1 = p1; data->p2 = p2; data->q1 = q1; data->q2 = q2; } void dl_save_EvalPoint2(struct GLContextIFace *Self, GLint p, GLint q) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(EvalPoint2Data)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_EvalPoint2; EvalPoint2Data *data = (EvalPoint2Data *)newOp->opData.data; data->p = p; data->q = 1; } void dl_save_PixelTransfer(struct GLContextIFace *Self, GLenum param, GLfloat value) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(PixelTransferData)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PixelTransfer; PixelTransferData *data = (PixelTransferData *)newOp->opData.data; data->param = param; data->value = value; } void dl_save_PixelZoom(struct GLContextIFace *Self, GLfloat zx, GLfloat zy) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(PixelZoomData)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_PixelZoom; PixelZoomData *data = (PixelZoomData *)newOp->opData.data; data->zoom_x = zx; data->zoom_y = zy; } void dl_save_CopyPixels(struct GLContextIFace *Self, GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(CopyPixelData)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_CopyPixels; CopyPixelData *data = (CopyPixelData *)newOp->opData.data; data->x = x; data->y = y; data->width = width; data->height = height; data->type = type; } void dl_save_LogicOp(struct GLContextIFace *Self, GLenum op) { GLcontext context = GET_INSTANCE(Self); DLOperation *newOp = dl_NewOperation(context->TargetDisplayListEnd, sizeof(LogicOpModeData)); if(!newOp) { context->DisplayListCompileError = GL_OUT_OF_MEMORY; return; } context->TargetDisplayListEnd = newOp; newOp->opFunc = dl_execute_LogicOp; LogicOpModeData *data = (LogicOpModeData *)newOp->opData.data; data->op = op; } // ----- PRIVATE FUNCTIONS ----- BOOL dl_InitList(DisplayList *list){ if(list->firstOp != NULL){ return FALSE; } list->firstOp = dl_NewOperation(NULL, 0); if(!list->firstOp){ return FALSE; } list->firstOp->opFunc = NULL; return TRUE; } DLOperation* dl_NewOperation(DLOperation *prevOp, GLuint extraBytes){ DLOperation *newOp = (DLOperation*)IExec->AllocVec(sizeof(DLOperation) + extraBytes, 0); if(newOp){ newOp->opFunc = NULL; newOp->nextOp = NULL; if(extraBytes){ newOp->opData.data = (void*)(newOp + 1); } } if(prevOp){ prevOp->nextOp = newOp; } return newOp; } void dl_FreeOperation(DLOperation *op){ IExec->FreeVec(op); } void dl_ClearList(DisplayList *list){ if(!list){ return; } DLOperation *currOp = list->firstOp; while(currOp){ DLOperation *nextOp = currOp->nextOp; dl_FreeOperation(currOp); currOp = nextOp; } list->firstOp = NULL; } GLuint dl_imageSize(GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type){ GLuint elementSize, typeSize; switch(format){ case GL_COLOR_INDEX: case GL_RED: case GL_GREEN: case GL_BLUE: case GL_ALPHA: case GL_LUMINANCE: elementSize = 1; break; case GL_RGB: case GL_BGR: elementSize = 3; break; case GL_RGBA: case GL_BGRA: elementSize = 4; break; case GL_LUMINANCE_ALPHA: elementSize = 2; default: return 0; } switch(type){ case GL_BITMAP: return (width + 7) / 8 * height; break; case GL_UNSIGNED_BYTE: case GL_BYTE: case GL_UNSIGNED_BYTE_3_3_2: case GL_UNSIGNED_BYTE_2_3_3_REV: typeSize = sizeof(GLbyte); break; case GL_UNSIGNED_SHORT: case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5_REV: case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: case GL_SHORT: typeSize = sizeof(GLshort); break; case GL_UNSIGNED_INT: case GL_INT: case GL_UNSIGNED_INT_8_8_8_8: case GL_UNSIGNED_INT_8_8_8_8_REV: case GL_UNSIGNED_INT_10_10_10_2: // case GL_UNSIGNED_INT_2_10_10_10_RE: typeSize = sizeof(GLint); break; case GL_FLOAT: typeSize = sizeof(GLfloat); break; default: return 0; } return width * height * elementSize * typeSize; } void dl_copyImage(struct GLContextIFace *Self, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *srcImage, void *destImage){ GLint unpackRowLength, skipPixels, skipRows; Self->GLGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpackRowLength); Self->GLGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skipPixels); Self->GLGetIntegerv(GL_UNPACK_SKIP_ROWS, &skipRows); GLuint elementSize, typeSize; switch(format){ case GL_COLOR_INDEX: case GL_RED: case GL_GREEN: case GL_BLUE: case GL_ALPHA: case GL_LUMINANCE: elementSize = 1; break; case GL_RGB: case GL_BGR: elementSize = 3; break; case GL_RGBA: case GL_BGRA: elementSize = 4; break; case GL_LUMINANCE_ALPHA: elementSize = 2; default: return; } switch(type){ case GL_BITMAP: // This special case is dealt with below break; case GL_UNSIGNED_BYTE: case GL_BYTE: case GL_UNSIGNED_BYTE_3_3_2: case GL_UNSIGNED_BYTE_2_3_3_REV: typeSize = sizeof(GLbyte); break; case GL_UNSIGNED_SHORT: case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5_REV: case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: case GL_SHORT: typeSize = sizeof(GLshort); break; case GL_UNSIGNED_INT: case GL_INT: case GL_UNSIGNED_INT_8_8_8_8: case GL_UNSIGNED_INT_8_8_8_8_REV: case GL_UNSIGNED_INT_10_10_10_2: // case GL_UNSIGNED_INT_2_10_10_10_RE: typeSize = sizeof(GLint); break; case GL_FLOAT: typeSize = sizeof(GLfloat); break; default: return; } GLuint bytesPerRow, rowOffset; if(type == GL_BITMAP){ bytesPerRow = (width + 7) / 8; rowOffset = (skipPixels + 7) / 8; // ##### FIXME! ##### maybe the pixels need to be shifted? } else{ GLuint bytesPerPixel = elementSize *typeSize; bytesPerRow = width * bytesPerPixel; rowOffset = skipPixels * bytesPerPixel; } GLubyte *destPixel = (GLubyte*) destImage; GLubyte *srcRowStart = (GLubyte*) srcImage + skipRows * bytesPerRow + rowOffset; for(GLsizei y = 0; y < height; y++){ for(GLsizei x = 0; x < bytesPerRow; x++){ *destPixel = srcRowStart[x]; destPixel++; } srcRowStart += bytesPerRow; } } #ifndef max #define max(a, b) (((a) > (b)) ? (a) : (b)) #endif GLsizei dl_getVertexArrayCountFromIndices(GLsizei count, GLint type, const void *indices) { GLsizei vertexArrayCount = 0; switch(type){ case GL_UNSIGNED_BYTE: { GLubyte *srcIndices = (GLubyte*) indices; for(GLsizei i = 0; i < count; i++){ vertexArrayCount = max(vertexArrayCount, srcIndices[i]); } break; } case GL_UNSIGNED_SHORT: { GLushort *srcIndices = (GLushort*) indices; for(GLsizei i = 0; i < count; i++){ vertexArrayCount = max(vertexArrayCount, srcIndices[i]); } break; } case GL_UNSIGNED_INT: { GLuint *srcIndices = (GLuint*) indices; for(GLsizei i = 0; i < count; i++){ vertexArrayCount = max(vertexArrayCount, srcIndices[i]); } break; } default: return 0; } return vertexArrayCount + 1; // indices start at 0 not 1 } int typeSize(GLenum type) { switch (type) { case GL_BYTE: return sizeof(GLbyte); case GL_UNSIGNED_BYTE: return sizeof(GLubyte); case GL_SHORT: return sizeof(GLshort); case GL_UNSIGNED_SHORT: return sizeof(GLushort); case GL_INT: return sizeof(GLint); case GL_UNSIGNED_INT: return sizeof(GLuint); case GL_FLOAT: return sizeof(GLdouble); case GL_DOUBLE: return sizeof(GLdouble); default: return 0; } } int dl_getVertexArraySize(GLcontext context, GLsizei count) { int i; int vertexArrayElementSize = 0; // Calculate how much space is needed for a single row in the array if (context->vertex_array.ClientState & GLCS_COLOR) { int elementSize = typeSize(context->vertex_array.ColorArray.type) * context->vertex_array.ColorArray.size; if(elementSize == 0) { return 0; } vertexArrayElementSize += elementSize; } if (context->vertex_array.ClientState & GLCS_NORMAL) { int elementSize = typeSize(context->vertex_array.NormalArray.type) * context->vertex_array.NormalArray.size; if(elementSize == 0) { return 0; } vertexArrayElementSize += elementSize; } for (i = 0; i <= context->texture.MaxTextureUnit; i++) { if (context->vertex_array.ClientState & client_texture_state[i] && (context->enable.Texture2D[i] || context->enable.Texture1D[i])) { int elementSize = typeSize(context->vertex_array.TexCoordArray[i].type) * context->vertex_array.TexCoordArray[i].size; if(elementSize == 0) { return 0; } vertexArrayElementSize += elementSize; } } if (context->vertex_array.ClientState & GLCS_VERTEX) { int elementSize = typeSize(context->vertex_array.VertexArray.type) * context->vertex_array.VertexArray.size; if(elementSize == 0) { return 0; } vertexArrayElementSize += elementSize; } return vertexArrayElementSize * count; } void dl_copyVertexArray(GLcontext context, struct GLvertex_array_state *vertexArray, GLvoid *vertexArrayBuffer, GLint first, GLsizei count) { int i, j; // Copy basic vertex state data *vertexArray = context->vertex_array; // Calculate the storage requirements and set up the copy operation int vertexArrayElementSize = 0; int colourElementSize, texCoordElementSize[MAX_TEXTURE_UNITS], normalElementSize, vertexElementSize; GLsizei colourStride, texCoordStride[MAX_TEXTURE_UNITS], normalStride, vertexStride; GLubyte *colourElementPtr, *texCoordElementPtr[MAX_TEXTURE_UNITS], *normalElementPtr, *vertexElementPtr; if (context->vertex_array.ClientState & GLCS_COLOR) { colourElementSize = typeSize(context->vertex_array.ColorArray.type) * context->vertex_array.ColorArray.size; if(colourElementSize != 0) { vertexArrayElementSize += colourElementSize; colourStride = context->vertex_array.ColorArray.stride; colourElementPtr = (GLubyte*)context->vertex_array.ColorArray.pointer + colourStride * first; } else { colourStride = 0; // to suppress a compiler warning colourElementPtr = NULL; } } else { colourElementSize = 0; // to suppress a compiler warning colourStride = 0; // to suppress a compiler warning colourElementPtr = NULL; } if (context->vertex_array.ClientState & GLCS_NORMAL) { normalElementSize = typeSize(context->vertex_array.NormalArray.type) * context->vertex_array.NormalArray.size; if(normalElementSize != 0) { vertexArrayElementSize += normalElementSize; normalStride = context->vertex_array.NormalArray.stride; normalElementPtr = (GLubyte*)context->vertex_array.NormalArray.pointer + normalStride * first; } else { normalStride = 0; // to suppress a compiler warning normalElementPtr = NULL; } } else { normalElementSize = 0; // to suppress a compiler warning normalStride = 0; // to suppress a compiler warning normalElementPtr = NULL; } for (i = 0; i <= context->texture.MaxTextureUnit; i++) { if (context->vertex_array.ClientState & client_texture_state[i] && (context->enable.Texture2D[i] || context->enable.Texture1D[i])) { texCoordElementSize[i] = typeSize(context->vertex_array.TexCoordArray[i].type) * context->vertex_array.TexCoordArray[i].size; if(texCoordElementSize[i] != 0) { vertexArrayElementSize += texCoordElementSize[i]; texCoordStride[i] = context->vertex_array.TexCoordArray[i].stride; texCoordElementPtr[i] = (GLubyte*)context->vertex_array.TexCoordArray[i].pointer + texCoordStride[i] * first; } else { texCoordStride[i] = 0; // to suppress a compiler warning texCoordElementPtr[i] = NULL; } } else { texCoordElementSize[i] = 0; // to suppress a compiler warning texCoordStride[i] = 0; // to suppress a compiler warning texCoordElementPtr[i] = NULL; } } if (context->vertex_array.ClientState & GLCS_VERTEX) { vertexElementSize = typeSize(context->vertex_array.VertexArray.type) * context->vertex_array.VertexArray.size; if(vertexElementSize != 0) { vertexArrayElementSize += vertexElementSize; vertexStride = context->vertex_array.VertexArray.stride; vertexElementPtr = (GLubyte*)context->vertex_array.VertexArray.pointer + vertexStride * first; } else { vertexStride = 0; // to suppress a compiler warning vertexElementPtr = NULL; } } else { vertexElementSize = 0; // to suppress a compiler warning vertexStride = 0; // to suppress a compiler warning vertexElementPtr = NULL; } // Now copy the vertex data GLubyte *outArrayLinePtr = vertexArrayBuffer; for(i = 0; i < count; ++i) { GLubyte *currOutPtr = outArrayLinePtr; if(colourElementPtr) { memcpy(currOutPtr, colourElementPtr, colourElementSize); currOutPtr += colourElementSize; colourElementPtr += colourStride; } for(j = 0; j <= context->texture.MaxTextureUnit; j++) { if(texCoordElementPtr[j]) { memcpy(currOutPtr, texCoordElementPtr[j], texCoordElementSize[j]); currOutPtr += texCoordElementSize[j]; texCoordElementPtr[j] += texCoordStride[j]; } } if(normalElementPtr) { memcpy(currOutPtr, normalElementPtr, normalElementSize); currOutPtr += normalElementSize; normalElementPtr += normalStride; } if(vertexElementPtr) { memcpy(currOutPtr, vertexElementPtr, vertexElementSize); currOutPtr += vertexElementSize; vertexElementPtr += vertexStride; } outArrayLinePtr += vertexArrayElementSize; } // Update the vertex data pointers and stride GLubyte *dataPtr = vertexArrayBuffer; if(colourElementPtr) { vertexArray->ColorArray.pointer = (void*)dataPtr; vertexArray->ColorArray.stride = vertexArrayElementSize; dataPtr += colourElementSize; } for(j = 0; j <= context->texture.MaxTextureUnit; j++) { if(texCoordElementPtr[j]) { vertexArray->TexCoordArray[j].pointer = (void*)dataPtr; vertexArray->TexCoordArray[j].stride = vertexArrayElementSize; dataPtr += texCoordElementSize[j]; } } if(normalElementPtr) { vertexArray->NormalArray.pointer = (void*)dataPtr; vertexArray->NormalArray.stride = vertexArrayElementSize; dataPtr += normalElementSize; } if(vertexElementPtr) { vertexArray->VertexArray.pointer = (void*)dataPtr; vertexArray->VertexArray.stride = vertexArrayElementSize; dataPtr += vertexElementSize; } }