Commit 59af5c4a authored by H. Verbeet's avatar H. Verbeet Committed by Alexandre Julliard

wined3d: Move fields common to vertex shaders and pixel shaders to IWineD3DBaseShader.

parent 04ed9c2a
......@@ -1620,7 +1620,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexShader(IWineD3DDevice *iface, CONS
IWineD3DVertexShaderImpl *object; /* NOTE: impl usage is ok, this is a create */
HRESULT hr = D3D_OK;
D3DCREATEOBJECTINSTANCE(object, VertexShader)
object->shader_ins = IWineD3DVertexShaderImpl_shader_ins;
object->baseShader.shader_ins = IWineD3DVertexShaderImpl_shader_ins;
TRACE("(%p) : Created Vertex shader %p\n", This, *ppVertexShader);
......@@ -1665,7 +1665,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_CreatePixelShader(IWineD3DDevice *iface, CONST
HRESULT hr = D3D_OK;
D3DCREATEOBJECTINSTANCE(object, PixelShader)
object->shader_ins = IWineD3DPixelShaderImpl_shader_ins;
object->baseShader.shader_ins = IWineD3DPixelShaderImpl_shader_ins;
hr = IWineD3DPixelShader_SetFunction(*ppPixelShader, pFunction);
if (D3D_OK == hr) {
TRACE("(%p) : Created Pixel shader %p\n", This, *ppPixelShader);
......
......@@ -1797,13 +1797,13 @@ UINT numberOfvertices, UINT numberOfIndicies, GLenum glPrimType, const void *idx
TRACE("Using vertex shader\n");
/* Bind the vertex program */
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->prgId));
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.prgId));
checkGLcall("glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertexShader->prgId);");
/* Enable OpenGL vertex programs */
glEnable(GL_VERTEX_PROGRAM_ARB);
checkGLcall("glEnable(GL_VERTEX_PROGRAM_ARB);");
TRACE_(d3d_shader)("(%p) : Bound vertex program %u and enabled GL_VERTEX_PROGRAM_ARB\n", This, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->prgId);
TRACE_(d3d_shader)("(%p) : Bound vertex program %u and enabled GL_VERTEX_PROGRAM_ARB\n", This, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.prgId);
/* Vertex Shader 8 constants */
vertexDeclaration = (IWineD3DVertexDeclarationImpl *)((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->vertexDeclaration;
......@@ -1834,13 +1834,13 @@ UINT numberOfvertices, UINT numberOfIndicies, GLenum glPrimType, const void *idx
TRACE("Using pixel shader\n");
/* Bind the fragment program */
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->prgId));
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->baseShader.prgId));
checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, pixelShader->prgId);");
/* Enable OpenGL fragment programs */
glEnable(GL_FRAGMENT_PROGRAM_ARB);
checkGLcall("glEnable(GL_FRAGMENT_PROGRAM_ARB);");
TRACE_(d3d_shader)("(%p) : Bound fragment program %u and enabled GL_FRAGMENT_PROGRAM_ARB\n", This, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->prgId);
TRACE_(d3d_shader)("(%p) : Bound fragment program %u and enabled GL_FRAGMENT_PROGRAM_ARB\n", This, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->baseShader.prgId);
/* Update the constants */
for (i = 0; i < WINED3D_PSHADER_MAX_CONSTANTS; ++i) {
......@@ -2062,7 +2062,7 @@ void drawPrimitive(IWineD3DDevice *iface,
int useHW = FALSE;
if (This->stateBlock->vertexShader != NULL && wined3d_settings.vs_mode != VS_NONE
&&((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->function != NULL
&&((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.function != NULL
&& GL_SUPPORT(ARB_VERTEX_PROGRAM)) {
useVertexShaderFunction = TRUE;
} else {
......@@ -2071,7 +2071,7 @@ void drawPrimitive(IWineD3DDevice *iface,
if (wined3d_settings.ps_mode != PS_NONE && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)
&& This->stateBlock->pixelShader
&& ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->function) {
&& ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->baseShader.function) {
usePixelShaderFunction = TRUE;
}
......
......@@ -111,22 +111,22 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_GetFunction(IWineD3DPixelShader* impl, VO
FIXME("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
if (NULL == pData) {
*pSizeOfData = This->functionLength;
*pSizeOfData = This->baseShader.functionLength;
return D3D_OK;
}
if (*pSizeOfData < This->functionLength) {
*pSizeOfData = This->functionLength;
if (*pSizeOfData < This->baseShader.functionLength) {
*pSizeOfData = This->baseShader.functionLength;
return D3DERR_MOREDATA;
}
if (NULL == This->function) { /* no function defined */
if (NULL == This->baseShader.function) { /* no function defined */
TRACE("(%p) : GetFunction no User Function defined using NULL to %p\n", This, pData);
(*(DWORD **) pData) = NULL;
} else {
if (This->functionLength == 0) {
if (This->baseShader.functionLength == 0) {
}
TRACE("(%p) : GetFunction copying to %p\n", This, pData);
memcpy(pData, This->function, This->functionLength);
memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
}
return D3D_OK;
}
......@@ -745,9 +745,9 @@ CONST SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[] = {
inline static const SHADER_OPCODE* pshader_program_get_opcode(IWineD3DPixelShaderImpl *This, const DWORD code) {
DWORD i = 0;
DWORD version = This->version;
DWORD version = This->baseShader.version;
DWORD hex_version = D3DPS_VERSION(version/10, version%10);
const SHADER_OPCODE *shader_ins = This->shader_ins;
const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
/** TODO: use dichotomic search */
while (NULL != shader_ins[i].name) {
......@@ -1496,12 +1496,12 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha
}
/* TODO: change to resource.glObjectHandel or something like that */
GL_EXTCALL(glGenProgramsARB(1, &This->prgId));
GL_EXTCALL(glGenProgramsARB(1, &This->baseShader.prgId));
TRACE("Creating a hw pixel shader, prg=%d\n", This->prgId);
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, This->prgId));
TRACE("Creating a hw pixel shader, prg=%d\n", This->baseShader.prgId);
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, This->baseShader.prgId));
TRACE("Created hw pixel shader, prg=%d\n", This->prgId);
TRACE("Created hw pixel shader, prg=%d\n", This->baseShader.prgId);
/* Create the program and check for errors */
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(pgmStr), pgmStr));
if (glGetError() == GL_INVALID_OPERATION) {
......@@ -1509,7 +1509,7 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
FIXME("HW PixelShader Error at position %d: %s\n",
errPos, debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
This->prgId = -1;
This->baseShader.prgId = -1;
}
}
#if 1 /* if were using the data buffer of device then we don't need to free it */
......@@ -1719,7 +1719,7 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, C
if (NULL != pToken) {
while (D3DPS_END() != *pToken) {
if (pshader_is_version_token(*pToken)) { /** version */
This->version = (((*pToken >> 8) & 0x0F) * 10) + (*pToken & 0x0F);
This->baseShader.version = (((*pToken >> 8) & 0x0F) * 10) + (*pToken & 0x0F);
TRACE("ps_%lu_%lu\n", (*pToken >> 8) & 0x0F, (*pToken & 0x0F));
++pToken;
++len;
......@@ -1733,7 +1733,7 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, C
len += comment_len + 1;
continue;
}
if (!This->version) {
if (!This->baseShader.version) {
WARN("(%p) : pixel shader doesn't have a valid version identifier\n", This);
}
curOpcode = pshader_program_get_opcode(This, *pToken);
......@@ -1793,9 +1793,9 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, C
TRACE("\n");
}
}
This->functionLength = (len + 1) * sizeof(DWORD);
This->baseShader.functionLength = (len + 1) * sizeof(DWORD);
} else {
This->functionLength = 1; /* no Function defined use fixed function vertex processing */
This->baseShader.functionLength = 1; /* no Function defined use fixed function vertex processing */
}
/* Generate HW shader in needed */
......@@ -1809,10 +1809,10 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, C
TRACE("(%p) : Copying the function\n", This);
/* copy the function ... because it will certainly be released by application */
if (NULL != pFunction) {
This->function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->functionLength);
memcpy((void *)This->function, pFunction, This->functionLength);
This->baseShader.function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->baseShader.functionLength);
memcpy((void *)This->baseShader.function, pFunction, This->baseShader.functionLength);
} else {
This->function = NULL;
This->baseShader.function = NULL;
}
/* TODO: Some proper return values for failures */
......
......@@ -693,7 +693,7 @@ CONST SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[] = {
inline static const SHADER_OPCODE* vshader_program_get_opcode(IWineD3DVertexShaderImpl *This, const DWORD code) {
DWORD i = 0;
const SHADER_OPCODE *shader_ins = This->shader_ins;
const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
/** TODO: use dichotomic search or hash table */
while (NULL != shader_ins[i].name) {
......@@ -1694,9 +1694,9 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS
if (GL_SUPPORT(ARB_VERTEX_PROGRAM)) {
/* Create the hw shader */
/* TODO: change to resource.glObjectHandel or something like that */
GL_EXTCALL(glGenProgramsARB(1, &This->prgId));
TRACE("Creating a hw vertex shader, prg=%d\n", This->prgId);
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, This->prgId));
GL_EXTCALL(glGenProgramsARB(1, &This->baseShader.prgId));
TRACE("Creating a hw vertex shader, prg=%d\n", This->baseShader.prgId);
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, This->baseShader.prgId));
/* Create the program and check for errors */
GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(pgmStr)/*pgmLength*/, pgmStr));
......@@ -1705,7 +1705,7 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
FIXME("HW VertexShader Error at position %d: %s\n",
errPos, debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
This->prgId = -1;
This->baseShader.prgId = -1;
}
}
#if 1 /* if were using the data buffer of device then we don't need to free it */
......@@ -1733,7 +1733,7 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_ExecuteSW(IWineD3DVertexShader* iface, W
WINED3DSHADERVECTOR d;
WINED3DSHADERVECTOR s[3];
/** parser datas */
const DWORD* pToken = This->function;
const DWORD* pToken = This->baseShader.function;
const SHADER_OPCODE* curOpcode = NULL;
/** functions parameters */
WINED3DSHADERVECTOR* p[4];
......@@ -1791,9 +1791,9 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_ExecuteSW(IWineD3DVertexShader* iface, W
/* TODO: Think of a name for 0x80000000 and replace its use with a constant */
while (*pToken & 0x80000000) {
if (i == 0) {
FIXME("unrecognized opcode: pos=%d token=%08lX\n", (pToken - 1) - This->function, *(pToken - 1));
FIXME("unrecognized opcode: pos=%d token=%08lX\n", (pToken - 1) - This->baseShader.function, *(pToken - 1));
}
FIXME("unrecognized opcode param: pos=%d token=%08lX what=", pToken - This->function, *pToken);
FIXME("unrecognized opcode param: pos=%d token=%08lX what=", pToken - This->baseShader.function, *pToken);
vshader_program_dump_param(*pToken, i);
TRACE("\n");
++i;
......@@ -2088,22 +2088,22 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_GetFunction(IWineD3DVertexShader* impl,
FIXME("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
if (NULL == pData) {
*pSizeOfData = This->functionLength;
*pSizeOfData = This->baseShader.functionLength;
return D3D_OK;
}
if (*pSizeOfData < This->functionLength) {
*pSizeOfData = This->functionLength;
if (*pSizeOfData < This->baseShader.functionLength) {
*pSizeOfData = This->baseShader.functionLength;
return D3DERR_MOREDATA;
}
if (NULL == This->function) { /* no function defined */
if (NULL == This->baseShader.function) { /* no function defined */
TRACE("(%p) : GetFunction no User Function defined using NULL to %p\n", This, pData);
(*(DWORD **) pData) = NULL;
} else {
if(This->functionLength == 0){
if(This->baseShader.functionLength == 0){
}
TRACE("(%p) : GetFunction copying to %p\n", This, pData);
memcpy(pData, This->function, This->functionLength);
memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
}
return D3D_OK;
}
......@@ -2187,9 +2187,9 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_SetFunction(IWineD3DVertexShader *iface,
TRACE("\n");
}
}
This->functionLength = (len + 1) * sizeof(DWORD);
This->baseShader.functionLength = (len + 1) * sizeof(DWORD);
} else {
This->functionLength = 1; /* no Function defined use fixed function vertex processing */
This->baseShader.functionLength = 1; /* no Function defined use fixed function vertex processing */
}
/* Generate HW shader in needed */
......@@ -2201,10 +2201,10 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_SetFunction(IWineD3DVertexShader *iface,
/* copy the function ... because it will certainly be released by application */
if (NULL != pFunction) {
This->function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->functionLength);
memcpy((void *)This->function, pFunction, This->functionLength);
This->baseShader.function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->baseShader.functionLength);
memcpy((void *)This->baseShader.function, pFunction, This->baseShader.functionLength);
} else {
This->function = NULL;
This->baseShader.function = NULL;
}
return D3D_OK;
}
......
......@@ -1170,6 +1170,27 @@ typedef struct SHADER_OPCODE {
} SHADER_OPCODE;
/*****************************************************************************
* IDirect3DBaseShader implementation structure
*/
typedef struct IWineD3DBaseShaderClass
{
DWORD version;
CONST SHADER_OPCODE *shader_ins;
CONST DWORD *function;
UINT functionLength;
GLuint prgId;
} IWineD3DBaseShaderClass;
typedef struct IWineD3DBaseShaderImpl {
/* IUnknown */
const IWineD3DBaseShaderVtbl *lpVtbl;
LONG ref;
/* IWineD3DBaseShader */
IWineD3DBaseShaderClass baseShader;
} IWineD3DBaseShaderImpl;
/*****************************************************************************
* IDirect3DVertexShader implementation structure
*/
typedef struct IWineD3DVertexShaderImpl {
......@@ -1177,16 +1198,14 @@ typedef struct IWineD3DVertexShaderImpl {
const IWineD3DVertexShaderVtbl *lpVtbl;
LONG ref; /* Note: Ref counting not required */
IUnknown *parent;
IWineD3DDeviceImpl *wineD3DDevice;
/* IWineD3DBaseShader */
IWineD3DBaseShaderClass baseShader;
/* IWineD3DVertexShaderImpl */
CONST SHADER_OPCODE *shader_ins;
CONST DWORD *function;
UINT functionLength;
IUnknown *parent;
IWineD3DDeviceImpl *wineD3DDevice;
DWORD usage;
DWORD version;
/* vertex declaration array mapping */
BOOL namedArrays; /* don't map use named functions */
......@@ -1197,7 +1216,6 @@ typedef struct IWineD3DVertexShaderImpl {
/* FIXME: This needs to be populated with some flags of VS_CONSTANT_NOT_USED, VS_CONSTANT_CONSTANT, VS_CONSTANT_INTEGER, VS_CONSTANT_BOOLEAN, VS_CONSTANT_FLOAT, a half byte bitmap will be the best option, but I'll keep it as chards for siplicity */
/* run time datas... */
VSHADERDATA *data;
GLuint prgId;
IWineD3DVertexDeclaration *vertexDeclaration;
#if 0 /* needs reworking */
/* run time datas */
......@@ -1216,19 +1234,17 @@ typedef struct IWineD3DPixelShaderImpl {
const IWineD3DPixelShaderVtbl *lpVtbl;
LONG ref; /* Note: Ref counting not required */
/* IWineD3DBaseShader */
IWineD3DBaseShaderClass baseShader;
/* IWineD3DPixelShaderImpl */
IUnknown *parent;
IWineD3DDeviceImpl *wineD3DDevice;
/* IWineD3DPixelShaderImpl */
const SHADER_OPCODE *shader_ins;
CONST DWORD *function;
UINT functionLength;
DWORD version;
CHAR constants[WINED3D_PSHADER_MAX_CONSTANTS];
/* run time data */
PSHADERDATA *data;
GLuint prgId;
#if 0 /* needs reworking */
PSHADERINPUTDATA input;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment