From 3a7fcec4d70854da9d3c5d74fb7b215356c80e79 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 24 Sep 2008 15:56:48 +0200 Subject: [PATCH] wined3d: Handle texture coordinates the same way we handle other vertex attributes. --- dlls/wined3d/directx.c | 56 ++++++++++++++++++++++++++- dlls/wined3d/drawprim.c | 71 ++++------------------------------ dlls/wined3d/wined3d_private.h | 4 +- include/wine/wined3d_gl.h | 12 ++++++ 4 files changed, 77 insertions(+), 66 deletions(-) diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 5d805e39aa1..fd0d2900d7a 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -176,7 +176,8 @@ glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED]; glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED]; glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED]; glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED]; -glTexAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED]; +glMultiTexCoordFunc multi_texcoord_funcs[WINED3DDECLTYPE_UNUSED]; +glAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED]; /** * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created, @@ -3968,6 +3969,11 @@ static void WINE_GLAPI invalid_func(void *data) { DebugBreak(); } +static void WINE_GLAPI invalid_texcoord_func(GLenum unit, void * data) { + ERR("Invalid texcoord function called\n"); + DebugBreak(); +} + #define GLINFO_LOCATION (Adapters[0].gl_info) /* Helper functions for providing vertex data to opengl. The arrays are initialized based on @@ -4098,6 +4104,54 @@ void fillGLAttribFuncs(WineD3D_GL_Info *gl_info) { normal_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func; normal_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func; normal_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func; + + multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) GL_EXTCALL(glMultiTexCoord1fvARB); + multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) GL_EXTCALL(glMultiTexCoord2fvARB); + multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) GL_EXTCALL(glMultiTexCoord3fvARB); + multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) GL_EXTCALL(glMultiTexCoord4fvARB); + multi_texcoord_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_SHORT2] = (void *) GL_EXTCALL(glMultiTexCoord2svARB); + multi_texcoord_funcs[WINED3DDECLTYPE_SHORT4] = (void *) GL_EXTCALL(glMultiTexCoord4svARB); + multi_texcoord_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_texcoord_func; + if (GL_SUPPORT(NV_HALF_FLOAT)) + { + multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) GL_EXTCALL(glMultiTexCoord2hvNV); + multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) GL_EXTCALL(glMultiTexCoord4hvNV); + } else { + multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_texcoord_func; + multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_texcoord_func; + } + + texcoord_funcs[WINED3DDECLTYPE_FLOAT1] = (void *) glTexCoord1fv; + texcoord_funcs[WINED3DDECLTYPE_FLOAT2] = (void *) glTexCoord2fv; + texcoord_funcs[WINED3DDECLTYPE_FLOAT3] = (void *) glTexCoord3fv; + texcoord_funcs[WINED3DDECLTYPE_FLOAT4] = (void *) glTexCoord4fv; + texcoord_funcs[WINED3DDECLTYPE_D3DCOLOR] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_UBYTE4] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_SHORT2] = (void *) glTexCoord2sv; + texcoord_funcs[WINED3DDECLTYPE_SHORT4] = (void *) glTexCoord4sv; + texcoord_funcs[WINED3DDECLTYPE_UBYTE4N] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_SHORT2N] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_SHORT4N] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_USHORT2N] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_USHORT4N] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_UDEC3] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_DEC3N] = (void *) invalid_func; + if (GL_SUPPORT(NV_HALF_FLOAT)) + { + texcoord_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) GL_EXTCALL(glTexCoord2hvNV); + texcoord_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) GL_EXTCALL(glTexCoord4hvNV); + } else { + texcoord_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_func; + texcoord_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_func; + } } #define PUSH1(att) attribs[nAttribs++] = (att); diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c index 17007188f33..95af758bf18 100644 --- a/dlls/wined3d/drawprim.c +++ b/dlls/wined3d/drawprim.c @@ -343,20 +343,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData position = sd->u.s.position.lpData + streamOffset[sd->u.s.position.streamNo]; } - /* The texture coordinate types are not so easy to map into a common function signature - we're - * not using the vector functions here - */ if(FIXME_ON(d3d_draw)) { - for (textureNo = 0; textureNo < GL_LIMITS(textures); ++textureNo) { - DWORD type = sd->u.s.texCoords[textureNo].dwType; - if (sd->u.s.texCoords[textureNo].lpData && - type != WINED3DDECLTYPE_FLOAT1 && - type != WINED3DDECLTYPE_FLOAT2 && - type != WINED3DDECLTYPE_FLOAT3 && - type != WINED3DDECLTYPE_FLOAT4) { - FIXME("Implement fixed function texture coordinates from %s\n", debug_d3ddecltype(type)); - } - } if(specular && This->stateBlock->renderState[WINED3DRS_FOGENABLE] && (This->stateBlock->renderState[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE || sd->u.s.position_transformed )&& This->stateBlock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) { @@ -423,11 +410,9 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData /* Query tex coords */ if (This->stateBlock->textures[textureNo] != NULL || pixelShader) { - int coordIdx = This->stateBlock->textureState[textureNo][WINED3DTSS_TEXCOORDINDEX]; int texture_idx = This->texUnitMap[textureNo]; - float *ptrToCoords = NULL; - float s = 0.0, t = 0.0, r = 0.0, q = 0.0; + void *ptrToCoords; if (coordIdx > 7) { VTRACE(("tex: %d - Skip tex coords, as being system generated\n", textureNo)); @@ -439,7 +424,6 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData if (texture_idx == -1) continue; - ptrToCoords = (float *)(texCoords[coordIdx] + (SkipnStrides * sd->u.s.texCoords[coordIdx].dwStride)); if (texCoords[coordIdx] == NULL) { TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo); if (GL_SUPPORT(ARB_MULTITEXTURE)) { @@ -448,54 +432,13 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData glTexCoord4f(0, 0, 0, 1); } continue; - } else { - int coordsToUse = sd->u.s.texCoords[coordIdx].dwType + 1; /* 0 == WINED3DDECLTYPE_FLOAT1 etc */ - - /* The coords to supply depend completely on the fvf / vertex shader */ - switch (coordsToUse) { - case 4: q = ptrToCoords[3]; /* drop through */ - case 3: r = ptrToCoords[2]; /* drop through */ - case 2: t = ptrToCoords[1]; /* drop through */ - case 1: s = ptrToCoords[0]; - } - - switch (coordsToUse) { /* Supply the provided texture coords */ - case WINED3DTTFF_COUNT1: - VTRACE(("tex:%d, s=%f\n", textureNo, s)); - if (GL_SUPPORT(ARB_MULTITEXTURE)) { - GL_EXTCALL(glMultiTexCoord1fARB(GL_TEXTURE0_ARB + texture_idx, s)); - } else { - glTexCoord1f(s); - } - break; - case WINED3DTTFF_COUNT2: - VTRACE(("tex:%d, s=%f, t=%f\n", textureNo, s, t)); - if (GL_SUPPORT(ARB_MULTITEXTURE)) { - GL_EXTCALL(glMultiTexCoord2fARB(GL_TEXTURE0_ARB + texture_idx, s, t)); - } else { - glTexCoord2f(s, t); - } - break; - case WINED3DTTFF_COUNT3: - VTRACE(("tex:%d, s=%f, t=%f, r=%f\n", textureNo, s, t, r)); - if (GL_SUPPORT(ARB_MULTITEXTURE)) { - GL_EXTCALL(glMultiTexCoord3fARB(GL_TEXTURE0_ARB + texture_idx, s, t, r)); - } else { - glTexCoord3f(s, t, r); - } - break; - case WINED3DTTFF_COUNT4: - VTRACE(("tex:%d, s=%f, t=%f, r=%f, q=%f\n", textureNo, s, t, r, q)); - if (GL_SUPPORT(ARB_MULTITEXTURE)) { - GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, s, t, r, q)); - } else { - glTexCoord4f(s, t, r, q); - } - break; - default: - FIXME("Should not get here as coordsToUse is two bits only (%x)!\n", coordsToUse); - } } + + ptrToCoords = texCoords[coordIdx] + (SkipnStrides * sd->u.s.texCoords[coordIdx].dwStride); + if (GL_SUPPORT(ARB_MULTITEXTURE)) + multi_texcoord_funcs[sd->u.s.texCoords[coordIdx].dwType](GL_TEXTURE0_ARB + texture_idx, ptrToCoords); + else + texcoord_funcs[sd->u.s.texCoords[coordIdx].dwType](ptrToCoords); } } /* End of textures */ diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 094bc25a01c..d4c6273c686 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -537,11 +537,13 @@ void primitiveDeclarationConvertToStridedData( DWORD get_flexible_vertex_size(DWORD d3dvtVertexType); typedef void (WINE_GLAPI *glAttribFunc)(void *data); -typedef void (WINE_GLAPI *glTexAttribFunc)(GLuint unit, void *data); +typedef void (WINE_GLAPI *glMultiTexCoordFunc)(GLenum unit, void *data); extern glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED]; extern glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED]; extern glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED]; extern glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED]; +extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3DDECLTYPE_UNUSED]; +extern glAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED]; #define eps 1e-8 diff --git a/include/wine/wined3d_gl.h b/include/wine/wined3d_gl.h index 3101c17ba4a..5e55a0d018f 100644 --- a/include/wine/wined3d_gl.h +++ b/include/wine/wined3d_gl.h @@ -1670,9 +1670,15 @@ typedef void (WINE_GLAPI *PGLFNBLENDEQUATIONPROC) (GLenum mode); typedef void (WINE_GLAPI *WINED3D_PFNGLACTIVETEXTUREARBPROC) (GLenum texture); typedef void (WINE_GLAPI *WINED3D_PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (WINE_GLAPI *WINED3D_PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); /* GL_ARB_texture_cube_map */ #ifndef GL_ARB_texture_cube_map @@ -3413,9 +3419,15 @@ typedef enum _GL_SupportedExt { USE_GL_FUNC(WINED3D_PFNGLACTIVETEXTUREARBPROC, glActiveTextureARB, ARB_MULTITEXTURE, NULL )\ USE_GL_FUNC(WINED3D_PFNGLCLIENTACTIVETEXTUREARBPROC, glClientActiveTextureARB, ARB_MULTITEXTURE, NULL )\ USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD1FARBPROC, glMultiTexCoord1fARB, ARB_MULTITEXTURE, NULL )\ + USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD1FVARBPROC, glMultiTexCoord1fvARB, ARB_MULTITEXTURE, NULL )\ USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD2FARBPROC, glMultiTexCoord2fARB, ARB_MULTITEXTURE, NULL )\ + USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD2FVARBPROC, glMultiTexCoord2fvARB, ARB_MULTITEXTURE, NULL )\ USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD3FARBPROC, glMultiTexCoord3fARB, ARB_MULTITEXTURE, NULL )\ + USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD3FVARBPROC, glMultiTexCoord3fvARB, ARB_MULTITEXTURE, NULL )\ USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD4FARBPROC, glMultiTexCoord4fARB, ARB_MULTITEXTURE, NULL )\ + USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD4FVARBPROC, glMultiTexCoord4fvARB, ARB_MULTITEXTURE, NULL )\ + USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD2SVARBPROC, glMultiTexCoord2svARB, ARB_MULTITEXTURE, NULL )\ + USE_GL_FUNC(WINED3D_PFNGLMULTITEXCOORD4SVARBPROC, glMultiTexCoord4svARB, ARB_MULTITEXTURE, NULL )\ /* GL_ARB_occlusion_query */ \ USE_GL_FUNC(PGLFNGENQUERIESARBPROC, glGenQueriesARB, ARB_OCCLUSION_QUERY, NULL )\ USE_GL_FUNC(PGLFNDELETEQUERIESARBPROC, glDeleteQueriesARB, ARB_OCCLUSION_QUERY, NULL )\