⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dglwgl.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 5 页
字号:
			continue;
		}

		if (ppfd->iLayerType != ppfdCandidate.iLayerType) {
			continue;
		}
		
		if (((dwFlags ^ ppfdCandidate.dwFlags) & dwFlags) &
			(PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP |
			PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL))
		{
			continue;
		}
		
		if (!(dwFlags & PFD_DOUBLEBUFFER_DONTCARE)) {
			if ((dwFlags & PFD_DOUBLEBUFFER) !=
				(ppfdCandidate.dwFlags & PFD_DOUBLEBUFFER))
			{
				continue;
			}
		}
		
//		if (!(dwFlags & PFD_STEREO_DONTCARE)) {
			if ((dwFlags & PFD_STEREO) !=
				(ppfdCandidate.dwFlags & PFD_STEREO))
			{
				continue;
			}
//		}
		
        if (ppfd->iPixelType==PFD_TYPE_RGBA
            && ppfd->cAlphaBits && !ppfdCandidate.cAlphaBits) {
            continue;
		}
		
        if (ppfd->iPixelType==PFD_TYPE_RGBA
			&& ppfd->cAccumBits && !ppfdCandidate.cAccumBits) {
			continue;
        }
		
        if (ppfd->cDepthBits && !ppfdCandidate.cDepthBits) {
			continue;
        }
		
        if (ppfd->cStencilBits && !ppfdCandidate.cStencilBits) {
            continue;
        }

		if (ppfd->cAuxBuffers && !ppfdCandidate.cAuxBuffers) {
			continue;
		}
		
		/*
		** See if candidate is better than the previous best choice
		*/
		if (bestIndex == -1) {
			ppfdBest = ppfdCandidate;
			bestIndex = i;
			continue;
		}
		
		if ((ppfd->cColorBits > ppfdBest.cColorBits &&
			ppfdCandidate.cColorBits > ppfdBest.cColorBits) ||
			(ppfd->cColorBits <= ppfdCandidate.cColorBits &&
			ppfdCandidate.cColorBits < ppfdBest.cColorBits))
		{
			ppfdBest = ppfdCandidate;
			bestIndex = i;
			continue;
		}
		
		if (ppfd->iPixelType==PFD_TYPE_RGBA
            && ppfd->cAlphaBits
            && ppfdCandidate.cAlphaBits > ppfdBest.cAlphaBits)
		{
			ppfdBest = ppfdCandidate;
			bestIndex = i;
			continue;
		}
		
		if (ppfd->iPixelType==PFD_TYPE_RGBA
			&& ppfd->cAccumBits
            && ppfdCandidate.cAccumBits > ppfdBest.cAccumBits)
		{
			ppfdBest = ppfdCandidate;
			bestIndex = i;
			continue;
		}
		
		if ((ppfd->cDepthBits > ppfdBest.cDepthBits &&
			ppfdCandidate.cDepthBits > ppfdBest.cDepthBits) ||
			(ppfd->cDepthBits <= ppfdCandidate.cDepthBits &&
			ppfdCandidate.cDepthBits < ppfdBest.cDepthBits))
		{
			ppfdBest = ppfdCandidate;
			bestIndex = i;
			continue;
		}
		
		if (ppfd->cStencilBits &&
			ppfdCandidate.cStencilBits > ppfdBest.cStencilBits)
		{
			ppfdBest = ppfdCandidate;
			bestIndex = i;
			continue;
		}
		
		if (ppfd->cAuxBuffers &&
			ppfdCandidate.cAuxBuffers > ppfdBest.cAuxBuffers)
		{
			ppfdBest = ppfdCandidate;
			bestIndex = i;
			continue;
		}
    }

	if (bestIndex != -1) {
		ddlogPrintf(DDLOG_SYSTEM, "Pixel Format %d chosen as best match", bestIndex+1);
	    return bestIndex + 1;
	}

	// Return the pixelformat that has the most capabilities.
	// ** NOTE: This is only possible due to the way the list
	// of pixelformats is built. **
	// Now picks best pixelformat. KeithH
	bestIndex = numPixelFormats;	// most capable double buffer format
	ddlogPrintf(DDLOG_SYSTEM, "Pixel Format %d chosen by default", bestIndex);
	return (bestIndex);
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(CopyContext)(
	HGLRC a,
	HGLRC b,
	UINT c)
{
	// Validate license
	if (!dglValidate())
		return FALSE;
    UNSUPPORTED("wglCopyContext")
    return FALSE; // Failed
}

// ***********************************************************************

HGLRC APIENTRY _GLD_WGL_EXPORT(CreateContext)(
	HDC a)
{
	int ipf;

	// Validate license
	if (!dglValidate())
		return 0;

	// Check that the current PFD is valid
	ipf = dglGetPixelFormat();
	if (!IsValidPFD(ipf))
		return (HGLRC)0;

	return dglCreateContext(a, &glb.lpPF[ipf-1]);
}

// ***********************************************************************

HGLRC APIENTRY _GLD_WGL_EXPORT(CreateLayerContext)(
	HDC a,
	int b)
{
	// Validate license
	if (!dglValidate())
		return 0;

    UNSUPPORTED("wglCreateLayerContext")
    return NULL; // Failed
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(DeleteContext)(
	HGLRC a)
{
	// Validate license
	if (!dglValidate())
		return FALSE;

    return dglDeleteContext(a);
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(DescribeLayerPlane)(
	HDC hDC,
	int iPixelFormat,
	int iLayerPlane,
	UINT nBytes,
	LPLAYERPLANEDESCRIPTOR plpd)
{
	// Validate license
	if (!dglValidate())
		return FALSE;

	UNSUPPORTED("DGL_DescribeLayerPlane")

//	gldLogPrintf(GLDLOG_INFO, "DescribeLayerPlane: %d, %d", iPixelFormat, iLayerPlane);

	return FALSE;
}

// ***********************************************************************

int APIENTRY _GLD_WGL_EXPORT(DescribePixelFormat)(
	HDC a,
	int b,
	UINT c,
	LPPIXELFORMATDESCRIPTOR d)
{
	UINT nSize;

	// Validate license
	if (!dglValidate())
		return 0;

	if (d == NULL) // Calling app requires max number of PF's
		return glb.nPixelFormatCount;

	// The supplied buffer may be larger than the info that we
	// will be copying.
	if (c > sizeof(PIXELFORMATDESCRIPTOR))
		nSize = sizeof(PIXELFORMATDESCRIPTOR);
	else
		nSize = c;

    // Setup an empty PFD before doing validation check
    memset(d, 0, nSize);
    d->nSize = nSize;
    d->nVersion = 1;

	if (!IsValidPFD(b))
		return 0; // Bail if PFD index is invalid

	memcpy(d, &glb.lpPF[b-1].pfd, nSize);

	return glb.nPixelFormatCount;
}

// ***********************************************************************

HGLRC APIENTRY _GLD_WGL_EXPORT(GetCurrentContext)(void)
{
	// Validate license
	if (!dglValidate())
		return 0;

	return dglGetCurrentContext();
}

// ***********************************************************************

HDC APIENTRY _GLD_WGL_EXPORT(GetCurrentDC)(void)
{
	// Validate license
	if (!dglValidate())
		return 0;

	return dglGetCurrentDC();
}

// ***********************************************************************

PROC APIENTRY _GLD_WGL_EXPORT(GetDefaultProcAddress)(
	LPCSTR a)
{
	// Validate license
	if (!dglValidate())
		return NULL;

    UNSUPPORTED("DGL_GetDefaultProcAddress")
    return NULL;
}

// ***********************************************************************

int APIENTRY _GLD_WGL_EXPORT(GetLayerPaletteEntries)(
	HDC a,
	int b,
	int c,
	int d,
	COLORREF *e)
{
	// Validate license
	if (!dglValidate())
		return 0;

    UNSUPPORTED("DGL_GetLayerPaletteEntries")
    return 0;
}

// ***********************************************************************

int APIENTRY _GLD_WGL_EXPORT(GetPixelFormat)(
	HDC a)
{
	// Validate license
	if (!dglValidate())
		return 0;

	return dglGetPixelFormat();
}

// ***********************************************************************

PROC APIENTRY _GLD_WGL_EXPORT(GetProcAddress)(
	LPCSTR a)
{
	PROC dglGetProcAddressD3D(LPCSTR a);

	// Validate license
	if (!dglValidate())
		return NULL;

#ifdef _USE_GLD3_WGL
	return _gldDriver.wglGetProcAddress(a);
#else
	return dglGetProcAddressD3D(a);
#endif
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(MakeCurrent)(
	HDC a,
	HGLRC b)
{
	// Validate license
	if (!dglValidate())
		return FALSE;

	return dglMakeCurrent(a, b);
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(RealizeLayerPalette)(
	HDC a,
	int b,
	BOOL c)
{
	// Validate license
	if (!dglValidate())
		return FALSE;

    UNSUPPORTED("DGL_RealizeLayerPalette")
	return FALSE;
}

// ***********************************************************************

int APIENTRY _GLD_WGL_EXPORT(SetLayerPaletteEntries)(
	HDC a,
	int b,
	int c,
	int d,
	CONST COLORREF *e)
{
	// Validate license
	if (!dglValidate())
		return 0;

    UNSUPPORTED("DGL_SetLayerPaletteEntries")
	return 0;
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(SetPixelFormat)(
	HDC a,
	int b,
	CONST PIXELFORMATDESCRIPTOR *c)
{
	// Validate license
	if (!dglValidate())
		return FALSE;

	if (IsValidPFD(b)) {
		ddlogPrintf(DDLOG_SYSTEM, "SetPixelFormat: PixelFormat %d has been set", b);
		dglSetPixelFormat(b);
		return TRUE;
	} else {
		ddlogPrintf(DDLOG_ERROR,
					"SetPixelFormat: PixelFormat %d is invalid and cannot be set", b);
		return FALSE;
	}
}

// ***********************************************************************
/*
 * Share lists between two gl_context structures.
 * This was added for WIN32 WGL function support, since wglShareLists()
 * must be called *after* wglCreateContext() with valid GLRCs. (DaveM)
 */
//
// Copied from GLD2.x. KeithH
//
static GLboolean _gldShareLists(
	GLcontext *ctx1,
	GLcontext *ctx2)
{
	/* Sanity check context pointers */
	if (ctx1 == NULL || ctx2 == NULL)
		return GL_FALSE;
	/* Sanity check shared list pointers */
	if (ctx1->Shared == NULL || ctx2->Shared == NULL)
		return GL_FALSE;
	/* Decrement reference count on sharee to release previous list */
	ctx2->Shared->RefCount--;
#if 0	/* 3DStudio exits on this memory release */
	if (ctx2->Shared->RefCount == 0)
		free_shared_state(ctx2, ctx2->Shared);
#endif
	/* Re-assign list from sharer to sharee and increment reference count */
	ctx2->Shared = ctx1->Shared;
	ctx1->Shared->RefCount++;
	return GL_TRUE;
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(ShareLists)(
	HGLRC a,
	HGLRC b)
{
	DGL_ctx *dgl1, *dgl2;

	// Validate license
	if (!dglValidate())
		return FALSE;

	// Mesa supports shared lists, but you need to supply the shared
	// GL context info when calling gl_create_context(). An auxiliary
	// function gl_share_lists() has been added to update the shared
	// list info after the GL contexts have been created. (DaveM)
	dgl1 = dglGetContextAddress(a);
	dgl2 = dglGetContextAddress(b);
	if (dgl1->bAllocated && dgl2->bAllocated) {
#ifdef _USE_GLD3_WGL
		return _gldShareLists(dgl1->glCtx, dgl2->glCtx);
#else
		return (*mesaFuncs.gl_share_lists)(dgl1->glCtx, dgl2->glCtx);
#endif
	}
	return FALSE;
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(SwapBuffers)(
	HDC a)
{
	// Validate license
	if (!dglValidate())
		return FALSE;

	return dglSwapBuffers(a);
}

// ***********************************************************************

BOOL APIENTRY _GLD_WGL_EXPORT(SwapLayerBuffers)(
	HDC a,
	UINT b)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -