#include "displaylists.h" #include "selection.h" #include "smartlock.h" #include "sysinc.h" #include #include #include #include #include #include "minigl_vectors.c" void buf_InitBuffer(GLcontext context, GLbuffer *buffer); void buf_SetFrontBuffer(GLcontext context, void *bitmap, GLboolean free); void buf_SetBackBuffer(GLcontext context, void *bitmap, GLboolean free); GLboolean vid_SetBitmap(GLcontext context, struct BitMap *bitMap, int *w, int *h); GLboolean vid_OpenWindow(GLcontext context, int w, int h, int left, int top); GLboolean vid_OpenDisplay(GLcontext context, int width, int height, uint32 id); GLboolean vid_CreateWarp3DContext(GLcontext context); void vid_CloseCurrentDisplay(GLcontext context); GLboolean vid_AllocDepthStencil(GLcontext context, GLboolean setstate); void vid_DestroyWarp3DContext(GLcontext context); void vid_SetDefaultStates(GLcontext context); GLboolean MGLInitContext(GLcontext context); void *mgl_CreateContextTags(struct MiniGLIFace *IMiniGL, ...) { va_list ap; void *res; struct TagItem *tags; va_startlinear(ap, IMiniGL); tags = va_getlinearva(ap, struct TagItem *); res = IMiniGL->CreateContext(tags); return res; } void cgl_UpdateContextTags(struct GLContextIFace *IGL, ...) { va_list ap; struct TagItem *tags; va_startlinear(ap, IGL); tags = va_getlinearva(ap, struct TagItem *); IGL->MGLUpdateContext(tags); } void *mgl_CreateContext(struct MiniGLIFace *IMiniGL, struct TagItem *tagList) { GLcontext context; BOOL bWindowMode; BOOL privateBuffers = FALSE; void *pBitmap; void *pFrontBuffer; void *pBackBuffer; int width, height, left, top, offx, offy; uint32 mode; struct GLContextIFace *IGL; int i; /* First of all, create the interface */ IGL = (struct GLContextIFace *)IExec->MakeInterfaceTags( IMiniGL->Data.LibBase, MIT_VectorTable, miniglcontext_vectors, MIT_DataSize, sizeof(struct GLcontext_t), MIT_Flags, IFLF_NONE, MIT_Version, 1, MIT_Name, "MiniGLContext", TAG_DONE ); if (!IGL) { return 0; } context = (GLcontext)GET_INSTANCE(IGL); IUtility->ClearMem(context, sizeof(struct GLcontext_t)); width = (int32)IUtility->GetTagData(MGLCC_Width, (uint32)-1, tagList); height = (int32)IUtility->GetTagData(MGLCC_Height, (uint32)-1, tagList); left = (int32)IUtility->GetTagData(MGLCC_WindowLeft, 30, tagList); top = (int32)IUtility->GetTagData(MGLCC_WindowTop, 30, tagList); offx = (int32)IUtility->GetTagData(MGLCC_OffsetX, 0, tagList); offy = (int32)IUtility->GetTagData(MGLCC_OffsetY, 0, tagList); bWindowMode = (BOOL)IUtility->GetTagData(MGLCC_Windowed, (uint32)FALSE, tagList); pBitmap = (void *)IUtility->GetTagData(MGLCC_Bitmap, 0, tagList); mode = IUtility->GetTagData(MGLCC_ScreenMode, MGL_SM_BESTMODE, tagList); privateBuffers = (int)IUtility->GetTagData(MGLCC_PrivateBuffers,0,tagList); pFrontBuffer = (void *)IUtility->GetTagData(MGLCC_FrontBuffer,0,tagList); pBackBuffer = (void *)IUtility->GetTagData(MGLCC_BackBuffer,0,tagList); context->fbDirtyHook = (void (*)(void *, void *))IUtility->GetTagData(MGLCC_FBDirtyHook,0,tagList); context->fbDirtyHookData = (void *)IUtility->GetTagData(MGLCC_FBDirtyHookData,0,tagList); dprintf("width = %ld, height = %ld, offx = %ld, offy = %ld\n", width, height, offx, offy); context->Params.newVertexBufferSize = IUtility->GetTagData(MGLCC_VertexBufferSize, 8192, tagList); context->Params.newTextureBufferSize = IUtility->GetTagData(MGLCC_TextureBufferSize, 8192, tagList); context->Params.newDisplayListArraySize = IUtility->GetTagData(MGLCC_DisplayListArraySize, 8192, tagList); context->Params.maxDisplayListNesting = IUtility->GetTagData(MGLCC_MaxDisplayListNesting, 64, tagList); context->Params.newNumberOfBuffers = IUtility->GetTagData(MGLCC_Buffers, 3, tagList); context->Params.newPixelDepth = IUtility->GetTagData(MGLCC_PixelDepth, 16, tagList); context->Params.newWindowMode = bWindowMode; context->Params.clw = (GLboolean)IUtility->GetTagData(MGLCC_CloseWorkbench, GL_FALSE, tagList); context->Params.newNoMipMapping = (GLboolean)IUtility->GetTagData(MGLCC_NoMipMapping, GL_FALSE, tagList); context->Params.newCloseGadget = (GLboolean)IUtility->GetTagData(MGLCC_CloseGadget, GL_FALSE, tagList); context->Params.newStencilBuffer = (GLboolean)IUtility->GetTagData(MGLCC_StencilBuffer, GL_FALSE, tagList); context->Params.newSizeGadget = (GLboolean)IUtility->GetTagData(MGLCC_SizeGadget, GL_FALSE, tagList); context->Params.newVBOSize = IUtility->GetTagData(MGLCC_VBOSize, 64, tagList); context->nameStackPointer = NAMESTACK_EMPTY; context->selectionBuffer = NULL; context->selectionBufferPointer = 0; context->selectionBufferOverflow = FALSE; context->selectionBufferSize = 0; context->renderMode = GL_RENDER; context->Self = IGL; CREATE_PROFILE() /* Initialize buffers. The vid_Open* or vid_SetBitmap functions will set * those */ buf_InitBuffer(context, &context->currentBackBuffer); buf_InitBuffer(context, &context->currentFrontBuffer); for (i = 0; i < MGL_MAX_AUX_BUFFERS; i++) { buf_InitBuffer(context, &context->currentAuxBuffer[i]); } dprintf("%ld screen buffers\n", context->Params.newNumberOfBuffers); GLboolean bRes; /* Setup primary display */ if (pBitmap) { // old style private bRes = vid_SetBitmap(context, pBitmap, &width, &height); context->priv = 1; context->NumBuffers = 1; } else if (privateBuffers) { if (privateBuffers == 1 && pFrontBuffer) { /* try the next just for testing */ bRes = vid_SetBitmap(context,pFrontBuffer, &width, &height); context->priv = 1; /* Single Buffered Application Private Buffers*/ context->NumBuffers = 1; } else if (privateBuffers == 2 && pFrontBuffer && pBackBuffer) { width = IP96->p96GetBitMapAttr(pFrontBuffer, P96BMA_WIDTH); height= IP96->p96GetBitMapAttr(pBackBuffer, P96BMA_WIDTH); buf_SetFrontBuffer(context,pFrontBuffer,GL_FALSE); buf_SetBackBuffer(context,pBackBuffer,GL_FALSE); context->priv = 2; /* Double Buffered Application Provided buffers */ /* these two lines come from vid_SetBitmap not sure if they are needed here or not ANDY*/ context->BufNr = 0; // The drawing buffer context->DoSync = GL_TRUE; // Enable sync'ing context->NumBuffers = 2; bRes = GL_TRUE; } else { bRes = GL_FALSE; } } else if (bWindowMode || mode == MGL_SM_WINDOWMODE) { bRes = vid_OpenWindow(context, width, height, left, top); } else { bRes = vid_OpenDisplay(context, width, height, mode); } if (!bRes) { IExec->DeleteInterface((struct Interface *)IGL); return NULL; } /* Set draw and read buffers */ if (context->NumBuffers == 1) { context->drawBuffer = &context->currentFrontBuffer; context->readBuffer = &context->currentFrontBuffer; context->color_buffer.DrawBuffer = GL_FRONT; context->color_buffer.ReadBuffer = GL_FRONT; } else { context->drawBuffer = &context->currentBackBuffer; context->readBuffer = &context->currentFrontBuffer; context->color_buffer.DrawBuffer = GL_BACK; context->color_buffer.ReadBuffer = GL_BACK; } context->color_buffer.WriteMaskRed = GL_TRUE; context->color_buffer.WriteMaskGreen = GL_TRUE; context->color_buffer.WriteMaskBlue = GL_TRUE; context->color_buffer.WriteMaskAlpha = GL_TRUE; /* Create the Warp3D context */ if (!vid_CreateWarp3DContext(context)) { vid_CloseCurrentDisplay(context); IExec->DeleteInterface((struct Interface *)IGL); return NULL; } /* Allocate stencil buffer and depth buffer if necessary */ if (!vid_AllocDepthStencil(context, GL_TRUE)) { vid_DestroyWarp3DContext(context); vid_CloseCurrentDisplay(context); IExec->DeleteInterface((struct Interface *)IGL); return NULL; } vid_SetDefaultStates(context); switch (context->w3dContext->CurrentChip) { case W3D_CHIP_PERMEDIA2: case W3D_CHIP_RADEON: case W3D_CHIP_RADEON_R200: case W3D_CHIP_RADEON_R300: context->UseZFog = GL_TRUE; break; default: context->UseZFog = GL_FALSE; } dprintf("Initializing context\n"); /* Initialize the context */ if (GL_FALSE == MGLInitContext(context)) { dprintf("Error: Can't initialize context\n"); IGL->DeleteContext(); return NULL; } dprintf("Setting up default parameters\n"); IGL->GLScissor(0, 0, width, height); IGL->GLDepthRange(0.0, 1.0); IGL->GLViewport(offx, offy, width, height); IGL->GLClearColor(0.0, 0.0, 0.0, 1.0); IGL->GLColor4f(1.0, 1.0, 1.0, 1.0); #ifndef GLNDEBUG dprintf("Lockmode = "); if (context->LockMode == MGL_LOCK_MANUAL) { kprintf("MGL_LOCK_MANUAL\n"); } else if (context->LockMode == MGL_LOCK_AUTOMATIC) { kprintf("MGL_LOCK_AUTOMATIC\n"); } else if (context->LockMode == MGL_LOCK_SMART) { kprintf("MGL_LOCK_SMART\n"); } else { kprintf("unknown\n"); } #endif dprintf("Done\n"); return (void *)IGL; }