VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_viewport.c@ 36300

Last change on this file since 36300 was 15532, checked in by vboxsync, 16 years ago

crOpenGL: export to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include <stdio.h>
8#include "state.h"
9#include "state/cr_statetypes.h"
10#include "state_internals.h"
11
12void crStateViewportInit(CRContext *ctx)
13{
14 CRViewportState *v = &ctx->viewport;
15 CRStateBits *sb = GetCurrentBits();
16 CRViewportBits *vb = &(sb->viewport);
17 CRTransformBits *tb = &(sb->transform);
18
19 v->scissorTest = GL_FALSE;
20 RESET(vb->enable, ctx->bitid);
21
22 v->viewportValid = GL_FALSE;
23 v->viewportX = 0;
24 v->viewportY = 0;
25 /* These are defaults, the tilesort spu overrides when
26 * the context has been created */
27 v->viewportW = 640;
28 v->viewportH = 480;
29 RESET(vb->v_dims, ctx->bitid);
30
31 v->scissorValid = GL_FALSE;
32 v->scissorX = 0;
33 v->scissorY = 0;
34 /* These are defaults, the tilesort spu overrides when
35 * the context has been created */
36 v->scissorW = 640;
37 v->scissorH = 480;
38 RESET(vb->s_dims, ctx->bitid);
39
40 v->farClip = 1.0;
41 v->nearClip = 0.0;
42 RESET(vb->depth, ctx->bitid);
43
44 RESET(vb->dirty, ctx->bitid);
45
46 /* XXX why are these here? */
47 RESET(tb->base, ctx->bitid);
48 RESET(tb->dirty, ctx->bitid);
49}
50
51void crStateViewportApply(CRViewportState *v, GLvectorf *p)
52{
53 p->x = (p->x+1.0f)*(v->viewportW / 2.0f) + v->viewportX;
54 p->y = (p->y+1.0f)*(v->viewportH / 2.0f) + v->viewportY;
55 p->z = (GLfloat) ((p->z+1.0f)*((v->farClip - v->nearClip) / 2.0f) + v->nearClip);
56}
57
58void STATE_APIENTRY crStateViewport(GLint x, GLint y, GLsizei width,
59 GLsizei height)
60{
61 CRContext *g = GetCurrentContext();
62 CRViewportState *v = &(g->viewport);
63 CRStateBits *sb = GetCurrentBits();
64 CRViewportBits *vb = &(sb->viewport);
65 CRTransformBits *tb = &(sb->transform);
66
67 if (g->current.inBeginEnd)
68 {
69 crStateError( __LINE__, __FILE__, GL_INVALID_OPERATION,
70 "calling glViewport() between glBegin/glEnd" );
71 return;
72 }
73
74 FLUSH();
75
76 if (width < 0 || height < 0)
77 {
78 crStateError( __LINE__, __FILE__, GL_INVALID_VALUE,
79 "glViewport(bad width or height)" );
80 return;
81 }
82
83 if (x > g->limits.maxViewportDims[0]) x = g->limits.maxViewportDims[0];
84 if (x < -g->limits.maxViewportDims[0]) x = -g->limits.maxViewportDims[0];
85 if (y > g->limits.maxViewportDims[1]) y = g->limits.maxViewportDims[1];
86 if (y < -g->limits.maxViewportDims[1]) y = -g->limits.maxViewportDims[1];
87 if (width > g->limits.maxViewportDims[0]) width = g->limits.maxViewportDims[0];
88 if (height > g->limits.maxViewportDims[1]) height = g->limits.maxViewportDims[1];
89
90 v->viewportX = (GLint) (x);
91 v->viewportY = (GLint) (y);
92 v->viewportW = (GLint) (width);
93 v->viewportH = (GLint) (height);
94
95 v->viewportValid = GL_TRUE;
96
97 DIRTY(vb->v_dims, g->neg_bitid);
98 DIRTY(vb->dirty, g->neg_bitid);
99 /* XXX why are these here? */
100 DIRTY(tb->base, g->neg_bitid);
101 DIRTY(tb->dirty, g->neg_bitid);
102}
103
104void STATE_APIENTRY crStateDepthRange(GLclampd znear, GLclampd zfar)
105{
106 CRContext *g = GetCurrentContext();
107 CRViewportState *v = &(g->viewport);
108 CRStateBits *sb = GetCurrentBits();
109 CRViewportBits *vb = &(sb->viewport);
110 CRTransformBits *tb = &(sb->transform);
111
112 if (g->current.inBeginEnd)
113 {
114 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glDepthRange called in Begin/End");
115 return;
116 }
117
118 FLUSH();
119
120 v->nearClip = znear;
121 v->farClip = zfar;
122 if (v->nearClip < 0.0) v->nearClip = 0.0;
123 if (v->nearClip > 1.0) v->nearClip = 1.0;
124 if (v->farClip < 0.0) v->farClip = 0.0;
125 if (v->farClip > 1.0) v->farClip = 1.0;
126
127 DIRTY(vb->depth, g->neg_bitid);
128 DIRTY(vb->dirty, g->neg_bitid);
129 DIRTY(tb->dirty, g->neg_bitid);
130}
131
132void STATE_APIENTRY crStateScissor (GLint x, GLint y,
133 GLsizei width, GLsizei height)
134{
135 CRContext *g = GetCurrentContext();
136 CRViewportState *v = &(g->viewport);
137 CRStateBits *sb = GetCurrentBits();
138 CRViewportBits *vb = &(sb->viewport);
139
140 if (g->current.inBeginEnd)
141 {
142 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
143 "glScissor called in begin/end");
144 return;
145 }
146
147 FLUSH();
148
149 if (width < 0 || height < 0)
150 {
151 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
152 "glScissor called with negative width/height: %d,%d",
153 width, height);
154 return;
155 }
156
157 v->scissorX = (GLint) (x);
158 v->scissorY = (GLint) (y);
159 v->scissorW = (GLint) (width);
160 v->scissorH = (GLint) (height);
161
162 v->scissorValid = GL_TRUE;
163
164 DIRTY(vb->s_dims, g->neg_bitid);
165 DIRTY(vb->dirty, g->neg_bitid);
166}
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