VirtualBox

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

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

Merged Linux code from Alexander Eichner.

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