VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.cpp@ 7813

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

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/** @file
2 * VBox OpenGL
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17
18#include <iprt/alloc.h>
19#include <iprt/string.h>
20#include <iprt/assert.h>
21#include <VBox/err.h>
22#define VBOX_OGL_WITH_CMD_STRINGS
23#define VBOX_OGL_WITH_FUNCTION_WRAPPERS
24#include "vboxgl.h"
25
26#define LOG_GROUP LOG_GROUP_SHARED_OPENGL
27#include <VBox/log.h>
28
29/**
30 * glGetString implementation
31 *
32 * @returns VBox error code
33 * @param pClient Client context
34 * @param name glGetString name parameter
35 * @param pString String pointer
36 * @param pcbString String length (in/out)
37 */
38int vboxglGetString(VBOXOGLCTX *pClient, GLenum name, char *pString, uint32_t *pcbString)
39{
40 const GLubyte *pName;
41 uint32_t cbLen;
42 int rc = VINF_SUCCESS;
43
44 vboxglEnableOpenGL(pClient);
45
46 pName = glGetString(name);
47 if (pName == NULL)
48 {
49 Log(("glGetString failed for name %x\n", name));
50 rc = VERR_INVALID_PARAMETER;
51 goto end;
52 }
53 cbLen = strlen((char *)pName) + 1;
54
55 if (cbLen > *pcbString)
56 cbLen = *pcbString - 1;
57
58 memcpy(pString, pName, cbLen);
59 /* force termination */
60 pString[cbLen] = 0;
61 *pcbString = cbLen + 1;
62
63end:
64
65 vboxglDisableOpenGL(pClient);
66
67 return rc;
68}
69
70/**
71 * Flush all queued OpenGL commands
72 *
73 * @returns VBox error code
74 * @param pClient Client context
75 * @param pCmdBuffer Command buffer
76 * @param cbCmdBuffer Command buffer size
77 * @param cCommands Number of commands in the buffer
78 * @param pLastError Pointer to last error (out)
79 * @param pLastRetVal Pointer to return val of last executed command (out)
80 */
81int vboxglFlushBuffer(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer, uint32_t cbCmdBuffer, uint32_t cCommands, GLenum *pLastError, uint64_t *pLastRetVal)
82{
83 uint32_t i;
84 uint8_t *pOrgBuffer = pCmdBuffer;
85
86 Log(("vboxglFlushBuffer cCommands=%d cbCmdBuffer=%x\n", cCommands, cbCmdBuffer));
87
88 pClient->fHasLastError = false;
89
90 for (i=0;i<cCommands;i++)
91 {
92 PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCmdBuffer;
93
94 Assert(((RTHCUINTPTR)pCmdBuffer & VBOX_OGL_CMD_ALIGN_MASK) == 0);
95#ifdef VBOX_OGL_CMD_STRICT
96 AssertMsgReturn(pCmd->Magic == VBOX_OGL_CMD_MAGIC, ("Invalid magic dword %x\n", pCmd->Magic), VERR_INVALID_PARAMETER);
97#endif
98 AssertMsgReturn(pCmd->enmOp < VBOX_OGL_OP_Last, ("Invalid OpenGL cmd %x\n", pCmd->enmOp), VERR_INVALID_PARAMETER);
99
100if ( pCmd->enmOp != VBOX_OGL_OP_Vertex3f
101 && pCmd->enmOp != VBOX_OGL_OP_Normal3f)
102 Log(("Flush cmd %s cParams=%d cbCmd=%x\n", pszVBoxOGLCmd[pCmd->enmOp], pCmd->cParams, pCmd->cbCmd));
103
104 /* call wrapper */
105 AssertMsgReturn(pfnOGLWrapper[pCmd->enmOp], ("No wrapper for opcode %x\n", pCmd->enmOp), VERR_INVALID_PARAMETER);
106 pfnOGLWrapper[pCmd->enmOp](pClient, pCmdBuffer);
107
108 pCmdBuffer += pCmd->cbCmd;
109 }
110 AssertReturn(pCmdBuffer == pOrgBuffer + cbCmdBuffer, VERR_INVALID_PARAMETER);
111
112 *pLastRetVal = pClient->lastretval;
113 if (pClient->fHasLastError)
114 *pLastError = pClient->ulLastError;
115 else
116 *pLastError = glGetError();
117
118#ifdef DEBUG
119 Log(("Flush: last return value=%VX64\n", *pLastRetVal));
120 switch(*pLastError)
121 {
122 case GL_NO_ERROR:
123 Log(("Flush: last error GL_NO_ERROR (%x)\n", GL_NO_ERROR));
124 break;
125 case GL_INVALID_ENUM:
126 Log(("Flush: last error GL_INVALID_ENUM (%x)\n", GL_INVALID_ENUM));
127 break;
128 case GL_INVALID_VALUE:
129 Log(("Flush: last error GL_INVALID_VALUE (%x)\n", GL_INVALID_VALUE));
130 break;
131 case GL_INVALID_OPERATION:
132 Log(("Flush: last error GL_INVALID_OPERATION (%x)\n", GL_INVALID_OPERATION));
133 break;
134 case GL_STACK_OVERFLOW:
135 Log(("Flush: last error GL_STACK_OVERFLOW (%x)\n", GL_STACK_OVERFLOW));
136 break;
137 case GL_STACK_UNDERFLOW:
138 Log(("Flush: last error GL_STACK_UNDERFLOW (%x)\n", GL_STACK_UNDERFLOW));
139 break;
140 case GL_OUT_OF_MEMORY:
141 Log(("Flush: last error GL_OUT_OF_MEMORY (%x)\n", GL_OUT_OF_MEMORY));
142 break;
143 }
144#endif
145 return VINF_SUCCESS;
146}
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