-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgrguDepth.cpp
166 lines (136 loc) · 4.34 KB
/
grguDepth.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//**************************************************************
//* OpenGLide - Glide to OpenGL Wrapper
//* http://openglide.sourceforge.net
//*
//* Depth (Z/W-Buffer) Functions
//*
//* OpenGLide is OpenSource under LGPL license
//* Originally made by Fabio Barros
//* Modified by Paul for Glidos (http://www.glidos.net)
//* Linux version by Simon White
//**************************************************************
#include "GlOgl.h"
#include "GLRender.h"
//*************************************************
//* Changes Depth Buffer Mode
//*************************************************
FX_ENTRY void FX_CALL
grDepthBufferMode( GrDepthBufferMode_t mode )
{
#ifdef OGL_DONE
GlideMsg( "grDepthBufferMode( %d )\n", mode );
#endif
RenderDrawTriangles( );
Glide.State.DepthBufferMode = mode;
/*
* In AddTriangle etc. Use of z or w for
* depth buffering is determined by the
* value of OpenGL.DepthBufferType. So
* I set it here.
*/
switch ( mode )
{
case GR_DEPTHBUFFER_DISABLE:
OpenGL.DepthBufferType = 0;
glDisable( GL_DEPTH_TEST );
return;
case GR_DEPTHBUFFER_ZBUFFER:
case GR_DEPTHBUFFER_ZBUFFER_COMPARE_TO_BIAS:
OpenGL.DepthBufferType = 1;
OpenGL.ZNear = ZBUFFERNEAR;
OpenGL.ZFar = ZBUFFERFAR;
break;
case GR_DEPTHBUFFER_WBUFFER:
case GR_DEPTHBUFFER_WBUFFER_COMPARE_TO_BIAS:
OpenGL.DepthBufferType = 0;
OpenGL.ZNear = WBUFFERNEAR;
OpenGL.ZFar = WBUFFERFAR;
break;
}
glEnable( GL_DEPTH_TEST );
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
if ( Glide.State.OriginInformation == GR_ORIGIN_LOWER_LEFT )
{
glOrtho( Glide.State.ClipMinX, Glide.State.ClipMaxX,
Glide.State.ClipMinY, Glide.State.ClipMaxY,
OpenGL.ZNear, OpenGL.ZFar );
glViewport( OpenGL.ClipMinX, OpenGL.ClipMinY,
OpenGL.ClipMaxX - OpenGL.ClipMinX,
OpenGL.ClipMaxY - OpenGL.ClipMinY );
}
else
{
glOrtho( Glide.State.ClipMinX, Glide.State.ClipMaxX,
Glide.State.ClipMaxY, Glide.State.ClipMinY,
OpenGL.ZNear, OpenGL.ZFar );
glViewport( OpenGL.ClipMinX, OpenGL.WindowHeight - OpenGL.ClipMaxY,
OpenGL.ClipMaxX - OpenGL.ClipMinX,
OpenGL.ClipMaxY - OpenGL.ClipMinY );
}
glMatrixMode( GL_MODELVIEW );
#ifdef OPENGL_DEBUG
GLErro( "grDepthBufferMode" );
#endif
}
//*************************************************
//* Enables or Disables Depth Buffer Writing
//*************************************************
FX_ENTRY void FX_CALL
grDepthMask( FxBool enable )
{
#ifdef OGL_DONE
GlideMsg( "grDepthMask( %d )\n", enable );
#endif
RenderDrawTriangles( );
Glide.State.DepthBufferWritting = OpenGL.DepthBufferWritting = enable;
glDepthMask( OpenGL.DepthBufferWritting );
#ifdef OPENGL_DEBUG
GLErro( "grDepthMask" );
#endif
}
//*************************************************
//* Sets the Depth Function to use
//*************************************************
FX_ENTRY void FX_CALL
grDepthBufferFunction( GrCmpFnc_t func )
{
#ifdef OGL_DONE
GlideMsg( "grDepthBufferFunction( %d )\n", func );
#endif
RenderDrawTriangles( );
Glide.State.DepthFunction = func;
// We can do this just because we know the constant values for both OpenGL and Glide
// To port it to anything else than OpenGL we NEED to change this code
OpenGL.DepthFunction = GL_NEVER + func;
glDepthFunc( OpenGL.DepthFunction );
#ifdef OPENGL_DEBUG
GLErro( "grDepthBufferFunction" );
#endif
}
//*************************************************
//* Set the depth bias level
//*************************************************
FX_ENTRY void FX_CALL
grDepthBiasLevel( FxI16 level )
{
#ifdef OGL_PARTDONE
GlideMsg( "grDepthBiasLevel( %d )\n", level );
#endif
RenderDrawTriangles( );
Glide.State.DepthBiasLevel = level;
//OpenGL.DepthBiasLevel = level * D1OVER65536;
OpenGL.DepthBiasLevel = level * 10.0f;
glPolygonOffset( 1.0f, OpenGL.DepthBiasLevel );
if ( level != 0 )
{
glEnable( GL_POLYGON_OFFSET_FILL );
}
else
{
glDisable( GL_POLYGON_OFFSET_FILL );
}
#ifdef OPENGL_DEBUG
GLErro( "grDepthBiasLevel" );
#endif
}