Skip to content

Commit

Permalink
Better use of arrays, multitex (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 29, 2003
1 parent 4f5cbb1 commit 55e03c1
Show file tree
Hide file tree
Showing 6 changed files with 527 additions and 98 deletions.
16 changes: 13 additions & 3 deletions doomsday/Include/drOpenGL/drOpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define __DROPENGL_H__

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <GL/gl.h>
#include <GL/glext.h>
Expand All @@ -14,8 +15,8 @@
#include "../doomsday.h"
#include "../dglib.h"

#define DROGL_VERSION 203
#define DROGL_VERSION_TEXT "2.0.3"
#define DROGL_VERSION 210
#define DROGL_VERSION_TEXT "2.1.0"
#define DROGL_VERSION_FULL "DGL OpenGL Driver Version "DROGL_VERSION_TEXT" ("__DATE__")"

enum { VX, VY, VZ };
Expand All @@ -30,19 +31,22 @@ typedef struct glvertex_s {
float pos[3];
float color[4];
float tex[2];
float tex2[2];
float tex3[2];
float tex4[2];
} glvertex_t;


//-------------------------------------------------------------------------
// main.c
//
extern int useFog, maxTexSize;
extern DGLuint currentTex;
extern int palExtAvailable, sharedPalExtAvailable;
extern boolean texCoordPtrEnabled;
extern int verbose, noArrays;
extern int useAnisotropic;
extern float maxAniso;
extern int maxTexUnits;

void DG_Clear(int bufferbits);

Expand Down Expand Up @@ -109,11 +113,17 @@ int DG_Bind(DGLuint texture);
//-------------------------------------------------------------------------
// ext.c
//
extern PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB;
extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
extern PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB;
extern PFNGLMULTITEXCOORD2FVARBPROC glMultiTexCoord2fvARB;
extern PFNGLLOCKARRAYSEXTPROC glLockArraysEXT;
extern PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT;

extern int extMultiTex;
extern int extTexEnvComb;
extern int extNvTexEnvComb;
extern int extAtiTexEnvComb;
extern int extAniso;

void initExtensions(void);
Expand Down
8 changes: 8 additions & 0 deletions doomsday/Src/drOpenGL/drOpenGL.def
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ EXPORTS
DG_GetInteger
DG_GetIntegerv
DG_SetInteger
DG_SetFloatv
DG_GetString
DG_Enable
DG_Disable
DG_EnableArrays
DG_DisableArrays
DG_Arrays
DG_UnlockArrays
DG_Func
DG_ZBias
DG_NewTexture
Expand Down Expand Up @@ -50,9 +55,12 @@ EXPORTS
DG_Vertex3fv
DG_TexCoord2f
DG_TexCoord2fv
DG_MultiTexCoord2f
DG_MultiTexCoord2fv
DG_Vertices2ftv
DG_Vertices3ftv
DG_Vertices3fctv
DG_DrawElements
DG_Grab
DG_Fog
DG_Fogv
Expand Down
157 changes: 151 additions & 6 deletions doomsday/Src/drOpenGL/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

// MACROS ------------------------------------------------------------------

#define MAX_TEX_UNITS 4

// TYPES -------------------------------------------------------------------

// FUNCTION PROTOTYPES -----------------------------------------------------
Expand All @@ -26,7 +28,7 @@
// PUBLIC DATA DEFINITIONS -------------------------------------------------

int polyCounter; // Triangle counter, really.
int useTexCoords = DGL_FALSE;
char useTexCoords[MAX_TEX_UNITS];

// PRIVATE DATA DEFINITIONS ------------------------------------------------

Expand Down Expand Up @@ -178,7 +180,7 @@ void DG_TexCoord2f(float s, float t)
{
currentVertex.tex[0] = s;
currentVertex.tex[1] = t;
useTexCoords = DGL_TRUE;
useTexCoords[0] = DGL_TRUE;
}

//===========================================================================
Expand All @@ -188,7 +190,33 @@ void DG_TexCoord2fv(float *data)
{
currentVertex.tex[0] = data[0];
currentVertex.tex[1] = data[1];
useTexCoords = DGL_TRUE;
useTexCoords[0] = DGL_TRUE;
}

//===========================================================================
// DG_MultiTexCoord2f
//===========================================================================
void DG_MultiTexCoord2f(int target, float s, float t)
{
float *tex =
(target == DGL_TEXTURE0? currentVertex.tex
: target == DGL_TEXTURE1? currentVertex.tex2
: target == DGL_TEXTURE2? currentVertex.tex3
: currentVertex.tex4);

tex[0] = s;
tex[1] = t;
useTexCoords[target - DGL_TEXTURE0] = DGL_TRUE;
}

//===========================================================================
// DG_MultiTexCoord2fv
//===========================================================================
void DG_MultiTexCoord2fv(int target, float *data)
{
currentVertex.tex[0] = data[0];
currentVertex.tex[1] = data[1];
useTexCoords[target - DGL_TEXTURE0] = DGL_TRUE;
}

//===========================================================================
Expand Down Expand Up @@ -286,15 +314,15 @@ void DG_Begin(int mode)
primType = mode;
stackPos = 0;

useTexCoords = DGL_FALSE;
memset(useTexCoords, 0, sizeof(useTexCoords));
}

//===========================================================================
// DG_End
//===========================================================================
void DG_End(void)
{
int i, glPrimitive =
int i, k, glPrimitive =
primType == DGL_POINTS? GL_POINTS
: primType == DGL_LINES? GL_LINES
: primType == DGL_TRIANGLES? GL_TRIANGLES
Expand All @@ -317,7 +345,17 @@ void DG_End(void)
for(i = 0, v = vertexStack; i < stackPos; i++, v++)
{
glColor4fv(v->color);
if(useTexCoords) glTexCoord2fv(v->tex);
if(useTexCoords[0]) glTexCoord2fv(v->tex);
for(k = 1; k < MAX_TEX_UNITS; k++)
{
if(useTexCoords[k])
{
glMultiTexCoord2fvARB(GL_TEXTURE0 + k,
k == 1? v->tex2
: k == 2? v->tex3
: v->tex4);
}
}
glVertex3fv(v->pos);
}
glEnd();
Expand Down Expand Up @@ -360,4 +398,111 @@ void DG_End(void)
primType = DGL_FALSE;
}

//===========================================================================
// DG_EnableArrays
//===========================================================================
void DG_EnableArrays(int vertices, int colors, int coords)
{
int i;

if(vertices) glEnableClientState(GL_VERTEX_ARRAY);
if(colors) glEnableClientState(GL_COLOR_ARRAY);

for(i = 0; i < maxTexUnits; i++)
{
if(coords & (1 << i))
{
if(glClientActiveTextureARB)
{
glClientActiveTextureARB(GL_TEXTURE0 + i);
}
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
}

//===========================================================================
// DG_DisableArrays
//===========================================================================
void DG_DisableArrays(int vertices, int colors, int coords)
{
int i;

if(vertices) glDisableClientState(GL_VERTEX_ARRAY);
if(colors) glDisableClientState(GL_COLOR_ARRAY);

for(i = 0; i < maxTexUnits; i++)
{
if(coords & (1 << i))
{
if(glClientActiveTextureARB)
{
glClientActiveTextureARB(GL_TEXTURE0 + i);
}
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
}

//===========================================================================
// DG_Arrays
// Enable, set and optionally lock all enabled arrays.
//===========================================================================
void DG_Arrays(void *vertices, void *colors, int numCoords,
void **coords, int lock)
{
int i;

if(vertices)
{
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 16, vertices);
}

if(colors)
{
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
}

for(i = 0; i < numCoords; i++)
{
if(coords[i])
{
if(glClientActiveTextureARB)
{
glClientActiveTextureARB(GL_TEXTURE0 + i);
}
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, coords[i]);
}
}

if(lock > 0 && glLockArraysEXT)
{
// 'lock' is the number of vertices to lock.
glLockArraysEXT(0, lock);
}
}

//===========================================================================
// DG_UnlockArrays
//===========================================================================
void DG_UnlockArrays(void)
{
if(glUnlockArraysEXT)
{
glUnlockArraysEXT();
}
}

//===========================================================================
// DG_DrawElements
//===========================================================================
void DG_DrawElements(int type, int count, unsigned int *indices)
{
if(type == DGL_TRIANGLES)
{
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, indices);
}
}

0 comments on commit 55e03c1

Please sign in to comment.