feat: glDepthRange and glPolygonOffset
This commit is contained in:
parent
1a9f4bf333
commit
0ab6a7f039
22
GL/draw.c
22
GL/draw.c
|
@ -591,6 +591,24 @@ static inline void _readPositionData(const GLuint first, const GLuint count, Ver
|
|||
} else {
|
||||
assert(0 && "Not Implemented");
|
||||
}
|
||||
|
||||
if(glIsEnabled(GL_POLYGON_OFFSET_FILL)){
|
||||
GLfloat offset_units=0.0f, offset_factor=0.0f;
|
||||
glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &offset_factor);
|
||||
glGetFloatv(GL_POLYGON_OFFSET_UNITS, &offset_units);
|
||||
|
||||
/*
|
||||
o = m * factor + r * units
|
||||
where m is the maximum depth slope of the polygon and r is the smallest value guaranteed to produce a resolvable difference in window coordinate depth values.
|
||||
The value r is an implementation-specific constant.
|
||||
*/
|
||||
|
||||
float offset = 0.01f * offset_factor + 0.001f * offset_units;
|
||||
int i;
|
||||
for( i=0;i<count;i++) {
|
||||
output[i].xyz[2] = output[i].xyz[2]+offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _readUVData(const GLuint first, const GLuint count, Vertex* output) {
|
||||
|
@ -1214,8 +1232,8 @@ static void submitVertices(GLenum mode, GLsizei first, GLuint count, GLenum type
|
|||
GLboolean blendEnabled = glIsEnabled(GL_BLEND);
|
||||
GLboolean depthEnabled = glIsEnabled(GL_DEPTH_TEST);
|
||||
|
||||
//glDepthFunc(GL_EQUAL);
|
||||
//glEnable(GL_BLEND);
|
||||
glDepthFunc(GL_EQUAL);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
/* This is modulation, we need to switch depending on the texture env mode! */
|
||||
//glBlendFunc(GL_DST_COLOR, GL_ZERO);
|
||||
|
|
|
@ -184,6 +184,9 @@ void APIENTRY glOrtho(GLfloat left, GLfloat right,
|
|||
OrthoMatrix[3][1] = -(top + bottom) / (top - bottom);
|
||||
OrthoMatrix[3][2] = -(zfar + znear) / (zfar - znear);
|
||||
|
||||
gl_depthrange_far = zfar;
|
||||
gl_depthrange_near = znear;
|
||||
|
||||
mat_load(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||
mat_apply(&OrthoMatrix);
|
||||
mat_store(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||
|
|
27
GL/state.c
27
GL/state.c
|
@ -31,6 +31,7 @@ static GLboolean SHARED_PALETTE_ENABLED = GL_FALSE;
|
|||
|
||||
static GLboolean ALPHA_TEST_ENABLED = GL_FALSE;
|
||||
|
||||
static GLboolean POLYGON_OFFSET_ENABLED = GL_FALSE;
|
||||
|
||||
GLboolean _glIsSharedTexturePaletteEnabled() {
|
||||
return SHARED_PALETTE_ENABLED;
|
||||
|
@ -82,6 +83,9 @@ static GLenum BLEND_SFACTOR = GL_ONE;
|
|||
static GLenum BLEND_DFACTOR = GL_ZERO;
|
||||
static GLboolean BLEND_ENABLED = GL_FALSE;
|
||||
|
||||
static GLfloat OFFSET_FACTOR = 0.0f;
|
||||
static GLfloat OFFSET_UNITS = 0.0f;
|
||||
|
||||
GLboolean _glIsBlendingEnabled() {
|
||||
return BLEND_ENABLED;
|
||||
}
|
||||
|
@ -346,6 +350,11 @@ GLAPI void APIENTRY glEnable(GLenum cap) {
|
|||
case GL_NEARZ_CLIPPING_KOS:
|
||||
_glEnableClipping(GL_TRUE);
|
||||
break;
|
||||
case GL_POLYGON_OFFSET_POINT:
|
||||
case GL_POLYGON_OFFSET_LINE:
|
||||
case GL_POLYGON_OFFSET_FILL:
|
||||
POLYGON_OFFSET_ENABLED = GL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -400,6 +409,11 @@ GLAPI void APIENTRY glDisable(GLenum cap) {
|
|||
case GL_NEARZ_CLIPPING_KOS:
|
||||
_glEnableClipping(GL_FALSE);
|
||||
break;
|
||||
case GL_POLYGON_OFFSET_POINT:
|
||||
case GL_POLYGON_OFFSET_LINE:
|
||||
case GL_POLYGON_OFFSET_FILL:
|
||||
POLYGON_OFFSET_ENABLED = GL_FALSE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -507,7 +521,8 @@ void glLineWidth(GLfloat width) {
|
|||
}
|
||||
|
||||
void glPolygonOffset(GLfloat factor, GLfloat units) {
|
||||
;
|
||||
OFFSET_FACTOR = factor;
|
||||
OFFSET_UNITS = units;
|
||||
}
|
||||
|
||||
void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params) {
|
||||
|
@ -570,6 +585,10 @@ GLboolean APIENTRY glIsEnabled(GLenum cap) {
|
|||
return LIGHTING_ENABLED;
|
||||
case GL_BLEND:
|
||||
return BLEND_ENABLED;
|
||||
case GL_POLYGON_OFFSET_POINT:
|
||||
case GL_POLYGON_OFFSET_LINE:
|
||||
case GL_POLYGON_OFFSET_FILL:
|
||||
return POLYGON_OFFSET_ENABLED;
|
||||
}
|
||||
|
||||
return GL_FALSE;
|
||||
|
@ -624,6 +643,12 @@ void APIENTRY glGetFloatv(GLenum pname, GLfloat* params) {
|
|||
case GL_MODELVIEW_MATRIX:
|
||||
memcpy4(params, _glGetModelViewMatrix(), sizeof(float) * 16);
|
||||
break;
|
||||
case GL_POLYGON_OFFSET_FACTOR:
|
||||
*params = OFFSET_FACTOR;
|
||||
break;
|
||||
case GL_POLYGON_OFFSET_UNITS:
|
||||
*params = OFFSET_UNITS;
|
||||
break;
|
||||
default:
|
||||
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
||||
_glKosPrintError();
|
||||
|
|
21
Makefile
21
Makefile
|
@ -7,8 +7,8 @@
|
|||
|
||||
TARGET = libGLdc.a
|
||||
OBJS = GL/gldc.o
|
||||
//OBJS = GL/draw.o GL/flush.o GL/framebuffer.o GL/immediate.o GL/lighting.o GL/state.o GL/texture.o GL/glu.o
|
||||
//OBJS += GL/matrix.o GL/fog.o GL/error.o GL/clip.o containers/stack.o containers/named_array.o containers/aligned_vector.o GL/profiler.o
|
||||
#OBJS = GL/draw.o GL/flush.o GL/framebuffer.o GL/immediate.o GL/lighting.o GL/state.o GL/texture.o GL/glu.o
|
||||
#OBJS += GL/matrix.o GL/fog.o GL/error.o GL/clip.o containers/stack.o containers/named_array.o containers/aligned_vector.o GL/profiler.o
|
||||
OBJS += containers/stack.o containers/named_array.o containers/aligned_vector.o GL/profiler.o
|
||||
|
||||
SUBDIRS =
|
||||
|
@ -16,6 +16,14 @@ SUBDIRS =
|
|||
KOS_CFLAGS += -ffast-math -O3 -funroll-loops -Iinclude -funsafe-math-optimizations -fno-expensive-optimizations
|
||||
GCC_FLAGS = -mlra
|
||||
|
||||
# Manipulate the CFLAGS to look our *our* version of the library and includes
|
||||
INC_DIR = $(abspath ./include)
|
||||
LIB_DIR = $(abspath ./)
|
||||
export CFLAGS := $(CFLAGS) -I $(INC_DIR)
|
||||
export OBJEXTRA := $(LIB_DIR)/libGLdc.a
|
||||
|
||||
default: build link
|
||||
|
||||
link:
|
||||
$(KOS_AR) rcs $(TARGET) $(OBJS)
|
||||
|
||||
|
@ -33,3 +41,12 @@ include $(KOS_BASE)/addons/Makefile.prefab
|
|||
create_kos_link:
|
||||
rm -f ../include/GL
|
||||
ln -s ../GLdc/include ../include/GL
|
||||
|
||||
polymark:
|
||||
$(KOS_MAKE) -C samples/quadmark dist
|
||||
|
||||
offset:
|
||||
$(KOS_MAKE) -C samples/polygon_offset
|
||||
|
||||
nehe07:
|
||||
$(KOS_MAKE) -C samples/nehe07 dist
|
21
include/gl.h
21
include/gl.h
|
@ -360,6 +360,27 @@ __BEGIN_DECLS
|
|||
#define GL_RGBA12 0x805A
|
||||
#define GL_RGBA16 0x805B
|
||||
|
||||
/* Polygons */
|
||||
#define GL_POINT 0x1B00
|
||||
#define GL_LINE 0x1B01
|
||||
#define GL_FILL 0x1B02
|
||||
#define GL_CW 0x0900
|
||||
#define GL_CCW 0x0901
|
||||
#define GL_FRONT 0x0404
|
||||
#define GL_BACK 0x0405
|
||||
#define GL_POLYGON_MODE 0x0B40
|
||||
#define GL_POLYGON_SMOOTH 0x0B41
|
||||
#define GL_POLYGON_STIPPLE 0x0B42
|
||||
#define GL_EDGE_FLAG 0x0B43
|
||||
#define GL_CULL_FACE 0x0B44
|
||||
#define GL_CULL_FACE_MODE 0x0B45
|
||||
#define GL_FRONT_FACE 0x0B46
|
||||
#define GL_POLYGON_OFFSET_FACTOR 0x8038
|
||||
#define GL_POLYGON_OFFSET_UNITS 0x2A00
|
||||
#define GL_POLYGON_OFFSET_POINT 0x2A01
|
||||
#define GL_POLYGON_OFFSET_LINE 0x2A02
|
||||
#define GL_POLYGON_OFFSET_FILL 0x8037
|
||||
|
||||
#define GLbyte char
|
||||
#define GLshort short
|
||||
#define GLint int
|
||||
|
|
|
@ -34,6 +34,9 @@ GLAPI void APIENTRY gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
|
|||
GLfloat centerx, GLfloat centery, GLfloat centerz,
|
||||
GLfloat upx, GLfloat upy, GLfloat upz);
|
||||
|
||||
GLAPI GLint APIENTRY gluBuild2DMipmaps( GLenum target,GLint internalFormat, GLsizei width,
|
||||
GLsizei height, GLenum format, GLenum type, const void *data );
|
||||
|
||||
GLAPI const GLubyte* APIENTRY gluErrorString(GLenum error);
|
||||
|
||||
__END_DECLS
|
||||
|
|
Loading…
Reference in New Issue
Block a user