VirtualBox

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

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

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1/** @file
2 * VBox OpenGL
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
17 * Clara, CA 95054 USA or visit http://www.sun.com if you need
18 * additional information or have any questions.
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
71 return rc;
72}
73
74/**
75 * Flush all queued OpenGL commands
76 *
77 * @returns VBox error code
78 * @param pClient Client context
79 * @param pCmdBuffer Command buffer
80 * @param cbCmdBuffer Command buffer size
81 * @param cCommands Number of commands in the buffer
82 * @param pLastError Pointer to last error (out)
83 * @param pLastRetVal Pointer to return val of last executed command (out)
84 */
85int vboxglFlushBuffer(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer, uint32_t cbCmdBuffer, uint32_t cCommands, GLenum *pLastError, uint64_t *pLastRetVal)
86{
87 uint32_t i;
88 uint8_t *pOrgBuffer = pCmdBuffer;
89
90 Log(("vboxglFlushBuffer cCommands=%d cbCmdBuffer=%x\n", cCommands, cbCmdBuffer));
91
92 pClient->fHasLastError = false;
93
94 for (i=0;i<cCommands;i++)
95 {
96 PVBOX_OGL_CMD pCmd = (PVBOX_OGL_CMD)pCmdBuffer;
97
98 Assert(((RTHCUINTPTR)pCmdBuffer & VBOX_OGL_CMD_ALIGN_MASK) == 0);
99#ifdef VBOX_OGL_CMD_STRICT
100 AssertMsgReturn(pCmd->Magic == VBOX_OGL_CMD_MAGIC, ("Invalid magic dword %x\n", pCmd->Magic), VERR_INVALID_PARAMETER);
101#endif
102 AssertMsgReturn(pCmd->enmOp < VBOX_OGL_OP_Last, ("Invalid OpenGL cmd %x\n", pCmd->enmOp), VERR_INVALID_PARAMETER);
103
104if ( pCmd->enmOp != VBOX_OGL_OP_Vertex3f
105 && pCmd->enmOp != VBOX_OGL_OP_Normal3f)
106 Log(("Flush cmd %s cParams=%d cbCmd=%x\n", pszVBoxOGLCmd[pCmd->enmOp], pCmd->cParams, pCmd->cbCmd));
107
108 /* call wrapper */
109 AssertMsgReturn(pfnOGLWrapper[pCmd->enmOp], ("No wrapper for opcode %x\n", pCmd->enmOp), VERR_INVALID_PARAMETER);
110 pfnOGLWrapper[pCmd->enmOp](pClient, pCmdBuffer);
111
112 pCmdBuffer += pCmd->cbCmd;
113 }
114 AssertReturn(pCmdBuffer == pOrgBuffer + cbCmdBuffer, VERR_INVALID_PARAMETER);
115
116 *pLastRetVal = pClient->lastretval;
117 if (pClient->fHasLastError)
118 *pLastError = pClient->ulLastError;
119 else
120 *pLastError = glGetError();
121
122#ifdef DEBUG
123 Log(("Flush: last return value=%VX64\n", *pLastRetVal));
124 switch(*pLastError)
125 {
126 case GL_NO_ERROR:
127 Log(("Flush: last error GL_NO_ERROR (%x)\n", GL_NO_ERROR));
128 break;
129 case GL_INVALID_ENUM:
130 Log(("Flush: last error GL_INVALID_ENUM (%x)\n", GL_INVALID_ENUM));
131 break;
132 case GL_INVALID_VALUE:
133 Log(("Flush: last error GL_INVALID_VALUE (%x)\n", GL_INVALID_VALUE));
134 break;
135 case GL_INVALID_OPERATION:
136 Log(("Flush: last error GL_INVALID_OPERATION (%x)\n", GL_INVALID_OPERATION));
137 break;
138 case GL_STACK_OVERFLOW:
139 Log(("Flush: last error GL_STACK_OVERFLOW (%x)\n", GL_STACK_OVERFLOW));
140 break;
141 case GL_STACK_UNDERFLOW:
142 Log(("Flush: last error GL_STACK_UNDERFLOW (%x)\n", GL_STACK_UNDERFLOW));
143 break;
144 case GL_OUT_OF_MEMORY:
145 Log(("Flush: last error GL_OUT_OF_MEMORY (%x)\n", GL_OUT_OF_MEMORY));
146 break;
147 }
148#endif
149 return VINF_SUCCESS;
150}
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