Use vertex arrays when possible.
This commit is contained in:
parent
2d6a3fcc22
commit
1eaee42399
|
@ -836,42 +836,36 @@ GL_IDirect3DDeviceImpl_3_2T_SetLightState(LPDIRECT3DDEVICE3 iface,
|
|||
return DD_OK;
|
||||
}
|
||||
|
||||
static void draw_primitive_start_GL(D3DPRIMITIVETYPE d3dpt)
|
||||
static GLenum convert_D3D_ptype_to_GL(D3DPRIMITIVETYPE d3dpt)
|
||||
{
|
||||
switch (d3dpt) {
|
||||
case D3DPT_POINTLIST:
|
||||
TRACE("Start POINTS\n");
|
||||
glBegin(GL_POINTS);
|
||||
break;
|
||||
TRACE(" primitive type is POINTS\n");
|
||||
return GL_POINTS;
|
||||
|
||||
case D3DPT_LINELIST:
|
||||
TRACE("Start LINES\n");
|
||||
glBegin(GL_LINES);
|
||||
break;
|
||||
TRACE(" primitive type is LINES\n");
|
||||
return GL_LINES;
|
||||
|
||||
case D3DPT_LINESTRIP:
|
||||
TRACE("Start LINE_STRIP\n");
|
||||
glBegin(GL_LINE_STRIP);
|
||||
break;
|
||||
TRACE(" primitive type is LINE_STRIP\n");
|
||||
return GL_LINE_STRIP;
|
||||
|
||||
case D3DPT_TRIANGLELIST:
|
||||
TRACE("Start TRIANGLES\n");
|
||||
glBegin(GL_TRIANGLES);
|
||||
break;
|
||||
TRACE(" primitive type is TRIANGLES\n");
|
||||
return GL_TRIANGLES;
|
||||
|
||||
case D3DPT_TRIANGLESTRIP:
|
||||
TRACE("Start TRIANGLE_STRIP\n");
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
break;
|
||||
TRACE(" primitive type is TRIANGLE_STRIP\n");
|
||||
return GL_TRIANGLE_STRIP;
|
||||
|
||||
case D3DPT_TRIANGLEFAN:
|
||||
TRACE("Start TRIANGLE_FAN\n");
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
break;
|
||||
TRACE(" primitive type is TRIANGLE_FAN\n");
|
||||
return GL_TRIANGLE_FAN;
|
||||
|
||||
default:
|
||||
FIXME("Unhandled primitive %08x\n", d3dpt);
|
||||
break;
|
||||
return GL_POINTS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1305,6 +1299,7 @@ static void draw_primitive_strided(IDirect3DDeviceImpl *This,
|
|||
BOOLEAN vertex_lighted = FALSE;
|
||||
IDirect3DDeviceGLImpl* glThis = (IDirect3DDeviceGLImpl*) This;
|
||||
int num_active_stages = 0;
|
||||
int num_tex_index = ((d3dvtVertexType & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT);
|
||||
|
||||
/* I put the trace before the various locks... So as to better understand where locks occur :-) */
|
||||
if (TRACE_ON(ddraw)) {
|
||||
|
@ -1356,7 +1351,68 @@ static void draw_primitive_strided(IDirect3DDeviceImpl *This,
|
|||
draw_primitive_handle_GL_state(This,
|
||||
(d3dvtVertexType & D3DFVF_POSITION_MASK) != D3DFVF_XYZ,
|
||||
vertex_lighted);
|
||||
draw_primitive_start_GL(d3dptPrimitiveType);
|
||||
|
||||
/* First, see if we can use the OpenGL vertex arrays... This is very limited
|
||||
for now to some 'special' cases where we can do a direct mapping between D3D
|
||||
types and GL types.
|
||||
|
||||
Note that in the future all calls will go through vertex arrays but the arrays
|
||||
will be generated by this function. */
|
||||
if (((d3dvtVertexType & D3DFVF_POSITION_MASK) == D3DFVF_XYZ) && /* Standard XYZ vertices */
|
||||
(((d3dvtVertexType & (D3DFVF_DIFFUSE|D3DFVF_SPECULAR)) == 0) || /* Either no colours */
|
||||
(((d3dvtVertexType & D3DFVF_DIFFUSE) != 0) && /* Or diffuse only but the Alpha component is not used */
|
||||
(This->state_block.render_state[D3DRENDERSTATE_ALPHATESTENABLE - 1] == FALSE) &&
|
||||
(This->state_block.render_state[D3DRENDERSTATE_ALPHABLENDENABLE - 1] == FALSE)))) {
|
||||
int tex_stage;
|
||||
TRACE(" using GL vertex arrays for performance !\n");
|
||||
/* First, the vertices (we are sure we have some :-) */
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(3, GL_FLOAT, lpD3DDrawPrimStrideData->position.dwStride, lpD3DDrawPrimStrideData->position.lpvData);
|
||||
/* Then the normals */
|
||||
if (d3dvtVertexType & D3DFVF_NORMAL) {
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
glNormalPointer(GL_FLOAT, lpD3DDrawPrimStrideData->normal.dwStride, lpD3DDrawPrimStrideData->normal.lpvData);
|
||||
}
|
||||
/* Then the diffuse colour */
|
||||
if (d3dvtVertexType & D3DFVF_DIFFUSE) {
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(3, GL_UNSIGNED_BYTE, lpD3DDrawPrimStrideData->normal.dwStride,
|
||||
((char *) lpD3DDrawPrimStrideData->diffuse.lpvData));
|
||||
}
|
||||
/* Then the various textures */
|
||||
for (tex_stage = 0; tex_stage < num_active_stages; tex_stage++) {
|
||||
int tex_index = This->state_block.texture_stage_state[tex_stage][D3DTSS_TEXCOORDINDEX - 1] & 0x0000FFFF;
|
||||
if (tex_index >= num_tex_index) {
|
||||
WARN("Default texture coordinate not handled in the vertex array path !!!\n");
|
||||
tex_index = num_tex_index - 1;
|
||||
}
|
||||
if (GL_extensions.glClientActiveTexture) {
|
||||
GL_extensions.glClientActiveTexture(GL_TEXTURE0_WINE + tex_stage);
|
||||
}
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, lpD3DDrawPrimStrideData->textureCoords[tex_index].dwStride,
|
||||
lpD3DDrawPrimStrideData->textureCoords[tex_index].lpvData);
|
||||
}
|
||||
if (dwIndices != NULL) {
|
||||
glDrawElements(convert_D3D_ptype_to_GL(d3dptPrimitiveType), dwIndexCount, GL_UNSIGNED_SHORT, dwIndices);
|
||||
} else {
|
||||
glDrawArrays(convert_D3D_ptype_to_GL(d3dptPrimitiveType), 0, dwIndexCount);
|
||||
}
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
if (d3dvtVertexType & D3DFVF_NORMAL) {
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
}
|
||||
if (d3dvtVertexType & D3DFVF_DIFFUSE) {
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
for (tex_stage = 0; tex_stage < num_active_stages; tex_stage++) {
|
||||
if (GL_extensions.glClientActiveTexture) {
|
||||
GL_extensions.glClientActiveTexture(GL_TEXTURE0_WINE + tex_stage);
|
||||
}
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
} else {
|
||||
glBegin(convert_D3D_ptype_to_GL(d3dptPrimitiveType));
|
||||
|
||||
/* Some fast paths first before the generic case.... */
|
||||
if ((d3dvtVertexType == D3DFVF_VERTEX) && (num_active_stages <= 1)) {
|
||||
|
@ -1416,7 +1472,6 @@ static void draw_primitive_strided(IDirect3DDeviceImpl *This,
|
|||
Note that people should write a fast path for all vertex formats out there...
|
||||
*/
|
||||
int index;
|
||||
int num_tex_index = ((d3dvtVertexType & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT);
|
||||
static const D3DVALUE no_index[] = { 0.0, 0.0, 0.0, 0.0 };
|
||||
|
||||
for (index = 0; index < dwIndexCount; index++) {
|
||||
|
@ -1517,6 +1572,7 @@ static void draw_primitive_strided(IDirect3DDeviceImpl *This,
|
|||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
/* Whatever the case, disable the color material stuff */
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
|
@ -4203,6 +4259,7 @@ d3ddevice_init_at_startup(void *gl_handle)
|
|||
/* We query the ARB version to be the most portable we can... */
|
||||
GL_extensions.glActiveTexture = pglXGetProcAddressARB("glActiveTextureARB");
|
||||
GL_extensions.glMultiTexCoord2fv = pglXGetProcAddressARB("glMultiTexCoord2fv");
|
||||
GL_extensions.glClientActiveTexture = pglXGetProcAddressARB("glClientActiveTextureARB");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ GL_API_FUNCTION(glColor3ub)
|
|||
GL_API_FUNCTION(glColor4ub)
|
||||
GL_API_FUNCTION(glColorMask)
|
||||
GL_API_FUNCTION(glColorMaterial)
|
||||
GL_API_FUNCTION(glColorPointer)
|
||||
GL_API_FUNCTION(glCopyPixels)
|
||||
GL_API_FUNCTION(glCopyTexSubImage2D)
|
||||
GL_API_FUNCTION(glCullFace)
|
||||
|
@ -48,9 +49,13 @@ GL_API_FUNCTION(glDepthFunc)
|
|||
GL_API_FUNCTION(glDepthMask)
|
||||
GL_API_FUNCTION(glDepthRange)
|
||||
GL_API_FUNCTION(glDisable)
|
||||
GL_API_FUNCTION(glDisableClientState)
|
||||
GL_API_FUNCTION(glDrawArrays)
|
||||
GL_API_FUNCTION(glDrawBuffer)
|
||||
GL_API_FUNCTION(glDrawElements)
|
||||
GL_API_FUNCTION(glDrawPixels)
|
||||
GL_API_FUNCTION(glEnable)
|
||||
GL_API_FUNCTION(glEnableClientState)
|
||||
GL_API_FUNCTION(glEnd)
|
||||
GL_API_FUNCTION(glFlush)
|
||||
GL_API_FUNCTION(glFogf)
|
||||
|
@ -77,6 +82,7 @@ GL_API_FUNCTION(glMatrixMode)
|
|||
GL_API_FUNCTION(glMultMatrixf)
|
||||
GL_API_FUNCTION(glNormal3f)
|
||||
GL_API_FUNCTION(glNormal3fv)
|
||||
GL_API_FUNCTION(glNormalPointer)
|
||||
GL_API_FUNCTION(glOrtho)
|
||||
GL_API_FUNCTION(glPixelStorei)
|
||||
GL_API_FUNCTION(glPolygonMode)
|
||||
|
@ -94,6 +100,7 @@ GL_API_FUNCTION(glStencilMask)
|
|||
GL_API_FUNCTION(glStencilOp)
|
||||
GL_API_FUNCTION(glTexCoord2f)
|
||||
GL_API_FUNCTION(glTexCoord2fv)
|
||||
GL_API_FUNCTION(glTexCoordPointer)
|
||||
GL_API_FUNCTION(glTexEnvf)
|
||||
GL_API_FUNCTION(glTexEnvfv)
|
||||
GL_API_FUNCTION(glTexEnvi)
|
||||
|
@ -106,6 +113,7 @@ GL_API_FUNCTION(glVertex3d)
|
|||
GL_API_FUNCTION(glVertex3f)
|
||||
GL_API_FUNCTION(glVertex3fv)
|
||||
GL_API_FUNCTION(glVertex4f)
|
||||
GL_API_FUNCTION(glVertexPointer)
|
||||
GL_API_FUNCTION(glViewport)
|
||||
GL_API_FUNCTION(glXCreateContext)
|
||||
GL_API_FUNCTION(glXDestroyContext)
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#define glColor3ub pglColor3ub
|
||||
#define glColor4ub pglColor4ub
|
||||
#define glColorMask pglColorMask
|
||||
#define glColorPointer pglColorPointer
|
||||
#define glCopyPixels pglCopyPixels
|
||||
#define glCopyTexSubImage2D pglCopyTexSubImage2D
|
||||
#define glColorMaterial pglColorMaterial
|
||||
|
@ -91,9 +92,13 @@
|
|||
#define glDepthMask pglDepthMask
|
||||
#define glDepthRange pglDepthRange
|
||||
#define glDisable pglDisable
|
||||
#define glDisableClientState pglDisableClientState
|
||||
#define glDrawArrays pglDrawArrays
|
||||
#define glDrawBuffer pglDrawBuffer
|
||||
#define glDrawElements pglDrawElements
|
||||
#define glDrawPixels pglDrawPixels
|
||||
#define glEnable pglEnable
|
||||
#define glEnableClientState pglEnableClientState
|
||||
#define glEnd pglEnd
|
||||
#define glFlush pglFlush
|
||||
#define glFogf pglFogf
|
||||
|
@ -120,6 +125,7 @@
|
|||
#define glMultMatrixf pglMultMatrixf
|
||||
#define glNormal3f pglNormal3f
|
||||
#define glNormal3fv pglNormal3fv
|
||||
#define glNormalPointer pglNormalPointer
|
||||
#define glOrtho pglOrtho
|
||||
#define glPixelStorei pglPixelStorei
|
||||
#define glPolygonMode pglPolygonMode
|
||||
|
@ -137,6 +143,7 @@
|
|||
#define glStencilOp pglStencilOp
|
||||
#define glTexCoord2f pglTexCoord2f
|
||||
#define glTexCoord2fv pglTexCoord2fv
|
||||
#define glTexCoordPointer pglTexCoordPointer
|
||||
#define glTexEnvf pglTexEnvf
|
||||
#define glTexEnvfv pglTexEnvfv
|
||||
#define glTexEnvi pglTexEnvi
|
||||
|
@ -149,6 +156,7 @@
|
|||
#define glVertex3f pglVertex3f
|
||||
#define glVertex3fv pglVertex3fv
|
||||
#define glVertex4f pglVertex4f
|
||||
#define glVertexPointer pglVertexPointer
|
||||
#define glViewport pglViewport
|
||||
#define glXCreateContext pglXCreateContext
|
||||
#define glXDestroyContext pglXDestroyContext
|
||||
|
|
|
@ -174,6 +174,7 @@ typedef struct {
|
|||
GLint max_texture_units;
|
||||
void (*glActiveTexture)(GLenum texture);
|
||||
void (*glMultiTexCoord2fv)(GLenum target, const GLfloat *v);
|
||||
void (*glClientActiveTexture)(GLenum texture);
|
||||
} GL_EXTENSIONS_LIST;
|
||||
extern GL_EXTENSIONS_LIST GL_extensions;
|
||||
|
||||
|
|
Loading…
Reference in New Issue