VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/OpenGL/VBoxCmd.cpp@ 8060

Last change on this file since 8060 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

File size: 4.4 KB
Line 
1/** @file
2 *
3 * VBoxDisp -- Windows Guest OpenGL ICD
4 *
5 * Copyright (C) 2006-2007 innotek GmbH
6 *
7 * This file is part of VirtualBox Open Source Edition (OSE), as
8 * available from http://www.virtualbox.org. This file is free software;
9 * you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License (GPL) as published by the Free Software
11 * Foundation, in version 2 as it comes in the "COPYING" file of the
12 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14 */
15#define VBOX_OGL_WITH_CMD_STRINGS
16#include "VBoxOGL.h"
17#include <VBox/version.h>
18#include <stdarg.h>
19#include <stdio.h>
20
21
22/**
23 * Queue a new OpenGL command
24 *
25 * @param enmOp OpenGL command op
26 * @param cParams Number of parameters
27 * @param cbParams Memory needed for parameters
28 */
29void VBoxCmdStart(uint32_t enmOp, uint32_t cParams, uint32_t cbParams)
30{
31 PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
32 PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
33
34 DbgPrintf2(("Start %s cParams=%d cbParams=%d\n", pszVBoxOGLCmd[enmOp], cParams, cbParams));
35
36 if (pCtx->pCurrentCmd + cParams*VBOX_OGL_CMD_ALIGN + cbParams + sizeof(VBOX_OGL_CMD) >= pCtx->pCmdBufferEnd)
37 {
38 DbgPrintf(("VBoxCmdStart -> cmd queue full -> flush!\n"));
39 VBoxOGLFlush();
40 pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
41 }
42 Assert(pCtx->pCurrentCmd + cbParams + sizeof(VBOX_OGL_CMD) < pCtx->pCmdBufferEnd);
43
44#ifdef VBOX_OGL_CMD_STRICT
45 pCmd->Magic = VBOX_OGL_CMD_MAGIC;
46#endif
47 pCmd->enmOp = enmOp;
48 pCmd->cbCmd = sizeof(VBOX_OGL_CMD);
49 pCmd->cParams = cParams;
50 return;
51}
52
53/**
54 * Add a parameter (fixed size) to the currently queued OpenGL command
55 *
56 * @param pParam Parameter ptr
57 * @param cbParam Parameter value size
58 */
59void VBoxCmdSaveParameter(uint8_t *pParam, uint32_t cbParam)
60{
61 PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
62 PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
63 uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
64
65 Assert(pCurrentCmdBlock + cbParam < pCtx->pCmdBufferEnd);
66
67#ifdef DEBUG
68 switch(cbParam)
69 {
70 case 1:
71 DbgPrintf2(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint8_t *)pParam, cbParam));
72 break;
73 case 2:
74 DbgPrintf2(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint16_t *)pParam, cbParam));
75 break;
76 case 4:
77 default:
78 DbgPrintf2(("Param %s val=%x cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], *(uint32_t *)pParam, cbParam));
79 break;
80 }
81#endif
82
83 memcpy(pCurrentCmdBlock, pParam, cbParam);
84 pCmd->cbCmd += cbParam;
85 pCmd->cbCmd = RT_ALIGN(pCmd->cbCmd, VBOX_OGL_CMD_ALIGN);
86}
87
88/**
89 * Add a parameter (variable size) to the currently queued OpenGL command
90 *
91 * @param pParam Parameter ptr
92 * @param cbParam Parameter value size
93 */
94void VBoxCmdSaveMemParameter(uint8_t *pParam, uint32_t cbParam)
95{
96 PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
97 PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
98 uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
99 PVBOX_OGL_VAR_PARAM pCurrentParam = (PVBOX_OGL_VAR_PARAM)pCurrentCmdBlock;
100
101 Assert(pCurrentCmdBlock + cbParam < pCtx->pCmdBufferEnd);
102
103 DbgPrintf2(("Mem Param %s cbParam=%d\n", pszVBoxOGLCmd[pCmd->enmOp], cbParam));
104
105#ifdef VBOX_OGL_CMD_STRICT
106 pCurrentParam->Magic = VBOX_OGL_CMD_MAGIC;
107#endif
108
109 if (pParam && cbParam)
110 {
111 pCurrentParam->cbParam = cbParam;
112 memcpy(pCurrentParam+1, pParam, cbParam);
113 }
114 else
115 {
116 pCurrentParam->cbParam = 0;
117 cbParam = 0;
118 }
119 pCmd->cbCmd += sizeof(*pCurrentParam) + cbParam;
120 pCmd->cbCmd = RT_ALIGN(pCmd->cbCmd, VBOX_OGL_CMD_ALIGN);
121}
122
123/**
124 * Finish the queued command
125 *
126 * @param enmOp OpenGL command op
127 */
128void VBoxCmdStop(uint32_t enmOp)
129{
130 PVBOX_OGL_THREAD_CTX pCtx = VBoxOGLGetThreadCtx();
131 PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCtx->pCurrentCmd;
132 uint8_t *pCurrentCmdBlock = (uint8_t *)pCmd + pCmd->cbCmd;
133
134 DbgPrintf2(("End %s cbCmd=%d\n", pszVBoxOGLCmd[pCmd->enmOp], pCmd->cbCmd));
135
136 pCtx->pCurrentCmd = pCurrentCmdBlock;
137 pCtx->cCommands++;
138}
139
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette