From 4218111ab87dceb0955c144bf6aa3ea5d9e80012 Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Mon, 14 May 2018 17:10:53 +0100 Subject: [PATCH] Make things C89 friendly --- GL/draw.c | 18 ++++++++++++------ GL/lighting.c | 3 ++- GL/state.c | 3 ++- GL/texture.c | 3 ++- Makefile | 3 ++- containers/named_array.h | 5 +++-- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/GL/draw.c b/GL/draw.c index e3f1de1..512017e 100644 --- a/GL/draw.c +++ b/GL/draw.c @@ -90,23 +90,25 @@ static void _parseColour(uint32* out, const GLubyte* in, GLint size, GLenum type } static void _parseFloats(GLfloat* out, const GLubyte* in, GLint size, GLenum type) { + GLubyte i = 0; + switch(type) { case GL_SHORT: { GLshort* inp = (GLshort*) in; - for(GLubyte i = 0; i < size; ++i) { + for(i = 0; i < size; ++i) { out[i] = (GLfloat) inp[i]; } } break; case GL_INT: { GLint* inp = (GLint*) in; - for(GLubyte i = 0; i < size; ++i) { + for(i = 0; i < size; ++i) { out[i] = (GLfloat) inp[i]; } } break; case GL_FLOAT: case GL_DOUBLE: /* Double == Float */ default: - for(GLubyte i = 0; i < size; ++i) out[i] = ((GLfloat*) in)[i]; + for(i = 0; i < size; ++i) out[i] = ((GLfloat*) in)[i]; } } @@ -165,7 +167,8 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ GLboolean lighting_enabled = isLightingEnabled(); - for(GLuint i = first; i < count; ++i) { + GLushort i; + for(i = first; i < count; ++i) { pvr_vertex_t* vertex = (pvr_vertex_t*) dst; vertex->u = vertex->v = 0.0f; vertex->argb = 0; @@ -202,9 +205,12 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ GLfloat contribution [] = {0.0f, 0.0f, 0.0f, 0.0f}; GLfloat to_add [] = {0.0f, 0.0f, 0.0f, 0.0f}; - for(GLubyte i = 0; i < MAX_LIGHTS; ++i) { + /* FIXME!!! Transform the position to eye space */ + + GLubyte j; + for(j = 0; j < MAX_LIGHTS; ++j) { if(isLightEnabled(i)) { - calculateLightingContribution(i, &vertex->x, normal, to_add); + calculateLightingContribution(j, &vertex->x, normal, to_add); contribution[0] += to_add[0]; contribution[1] += to_add[1]; diff --git a/GL/lighting.c b/GL/lighting.c index 42d8eee..164d4f2 100644 --- a/GL/lighting.c +++ b/GL/lighting.c @@ -23,7 +23,8 @@ void initLights() { MATERIAL.diffuse_color_index = 1.0f; MATERIAL.specular_color_index = 1.0f; - for(GLubyte i = 0; i < MAX_LIGHTS; ++i) { + GLubyte i; + for(i = 0; i < MAX_LIGHTS; ++i) { memcpy(LIGHTS[i].ambient, ZERO, sizeof(GLfloat) * 4); memcpy(LIGHTS[i].diffuse, ONE, sizeof(GLfloat) * 4); memcpy(LIGHTS[i].specular, ONE, sizeof(GLfloat) * 4); diff --git a/GL/state.c b/GL/state.c index 7782a23..ed91361 100644 --- a/GL/state.c +++ b/GL/state.c @@ -189,7 +189,8 @@ void initContext() { glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); - for(GLubyte i = 0; i < MAX_LIGHTS; ++i) { + GLubyte i; + for(i = 0; i < MAX_LIGHTS; ++i) { glDisable(GL_LIGHT0 + i); } } diff --git a/GL/texture.c b/GL/texture.c index 4a51d3d..252170c 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -549,7 +549,8 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat, } /* Perform the conversion */ - for(GLuint i = 0; i < bytes; i += 2) { + GLuint i; + for(i = 0; i < bytes; i += 2) { convert(source, dest); dest++; diff --git a/Makefile b/Makefile index 7cec35e..e2584fc 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,10 @@ # kos-ports/libgl Makefile # Copyright (C) 2013, 2014 Josh Pearson # Copyright (C) 2014 Lawrence Sebald +# Copyright (C) 2018 Luke Benstead TARGET = libGL.a -OBJS = gl-rgb.o gl-fog.o gl-sh4-light.o gl-light.o gl-clip.o gl-clip-arrays.o +OBJS = gl-rgb.o gl-fog.o gl-sh4-light.o gl-light.o gl-clip.o gl-clip-arrays.o OBJS += gl-arrays.o gl-pvr.o gl-matrix.o gl-api.o glu-texture.o OBJS += gl-framebuffer.o gl-cap.o gl-error.o OBJS += GL/draw.o GL/flush.o GL/framebuffer.o GL/immediate.o GL/lighting.o GL/state.o GL/texture.o diff --git a/containers/named_array.h b/containers/named_array.h index 88d0774..8989cea 100644 --- a/containers/named_array.h +++ b/containers/named_array.h @@ -43,8 +43,9 @@ inline char named_array_used(NamedArray* array, unsigned int id) { } inline void* named_array_alloc(NamedArray* array, unsigned int* new_id) { - for(unsigned int i = 0; i < array->marker_count; ++i) { - for(unsigned int j = 0; j < 8; ++j) { + unsigned int i = 0, j = 0; + for(i = 0; i < array->marker_count; ++i) { + for(j = 0; j < 8; ++j) { unsigned int id = (i * 8) + j + 1; if(!named_array_used(array, id)) { array->used_markers[i] |= (unsigned char) 1 << j;