stateblock.c revision 114410893548b9522c46fdcbd8f63385eb8bfb68
/*
* state block implementation
*
* Copyright 2002 Raphael Junqueira
* Copyright 2004 Jason Edmeades
* Copyright 2005 Oliver Stieber
* Copyright 2007 Stefan Dösinger for CodeWeavers
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Sun elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
#include "config.h"
#include "wined3d_private.h"
/***************************************
* Stateblock helper functions follow
**************************************/
/** Allocates the correct amount of space for pixel and vertex shader constants,
*/
/* Allocate space for floating point constants */
object->pixelShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(pshader_constantsF));
object->vertexShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(vshader_constantsF));
object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(vshader_constantsF));
object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(pshader_constantsF));
return WINED3D_OK;
fail:
ERR("Failed to allocate memory\n");
return E_OUTOFMEMORY;
}
/** Copy all members of one stateblock to another */
static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES *dest, const SAVEDSTATES *source)
{
/* Single values */
/* Fixed size arrays */
/* Dynamically sized arrays */
memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF));
memcpy(dest->vertexShaderConstantsF, source->vertexShaderConstantsF, bsize * GL_LIMITS(vshader_constantsF));
}
{
}
/** Set all members of a stateblock savedstate to the given value */
/* Single values */
/* Fixed size arrays */
if (value)
{
int i;
}
else
{
states->streamSource = 0;
states->streamFreq = 0;
states->pixelShaderConstantsB = 0;
states->pixelShaderConstantsI = 0;
states->vertexShaderConstantsB = 0;
states->vertexShaderConstantsI = 0;
}
/* Dynamically sized arrays */
}
void stateblock_copy(
int l;
/* IUnknown fields */
/* IWineD3DStateBlock information */
/* Saved states */
/* Single items */
/* Dest->lights = This->lights; */
/* Lights */
for(l = 0; l < LIGHTMAP_SIZE; l++) {
}
}
}
/* Fixed size arrays */
memcpy(Dest->textureState, This->textureState, sizeof(DWORD) * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
memcpy(Dest->samplerState, This->samplerState, sizeof(DWORD) * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
/* Dynamically sized arrays */
memcpy(Dest->vertexShaderConstantF, This->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
memcpy(Dest->pixelShaderConstantF, This->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
}
/**********************************************************
* IWineD3DStateBlockImpl IUnknown parts follows
**********************************************************/
static HRESULT WINAPI IWineD3DStateBlockImpl_QueryInterface(IWineD3DStateBlock *iface,REFIID riid,LPVOID *ppobj)
{
return S_OK;
}
return E_NOINTERFACE;
}
return refCount;
}
if (!refCount) {
int counter;
/* type 0 represents the primary stateblock, so free all the resources */
/* NOTE: according to MSDN: The application is responsible for making sure the texture references are cleared down */
/* release our 'internal' hold on the texture */
TRACE("Texture still referenced by stateblock, applications has leaked Stage = %u Texture = %p\n", counter, This->textures[counter]);
}
}
}
}
{
TRACE("Vertex buffer still referenced by stateblock, applications has leaked Stream %u, buffer %p\n", counter, This->streamSource[counter]);
}
}
}
}
}
}
return refCount;
}
/**********************************************************
* IWineD3DStateBlockImpl parts follows
**********************************************************/
static HRESULT WINAPI IWineD3DStateBlockImpl_GetParent(IWineD3DStateBlock *iface, IUnknown **pParent) {
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DStateBlockImpl_GetDevice(IWineD3DStateBlock *iface, IWineD3DDevice** ppDevice){
return WINED3D_OK;
}
static inline void record_lights(IWineD3DStateBlockImpl *This, IWineD3DStateBlockImpl *targetStateBlock) {
UINT i;
/* Lights... For a recorded state block, we just had a chain of actions to perform,
* so we need to walk that chain and update any actions which differ
*/
for(i = 0; i < LIGHTMAP_SIZE; i++) {
struct list *e, *f;
/* Look up the light in the destination */
}
if(src->enabledChanged) {
/* Need to double check because enabledChanged does not catch enabled -> disabled -> enabled
* or disabled -> enabled -> disabled changes
*/
/* Light disabled */
/* Light enabled */
}
}
break;
}
}
if(updated) {
/* Found a light, all done, proceed with next hash entry */
continue;
/* Otherwise assign defaul params */
} else {
/* Not enabled by default */
}
}
}
}
unsigned int i, j;
/* If not recorded, then update can just recapture */
/* Recorded => Only update 'changed' values */
TRACE("Updating vertex shader from %p to %p\n", This->vertexShader, targetStateBlock->vertexShader);
}
/* Vertex Shader Float Constants */
for (j = 0; j < This->num_contained_vs_consts_f; ++j) {
i = This->contained_vs_consts_f[j];
}
/* Vertex Shader Integer Constants */
for (j = 0; j < This->num_contained_vs_consts_i; ++j) {
i = This->contained_vs_consts_i[j];
}
/* Vertex Shader Boolean Constants */
for (j = 0; j < This->num_contained_vs_consts_b; ++j) {
i = This->contained_vs_consts_b[j];
}
/* Pixel Shader Float Constants */
for (j = 0; j < This->num_contained_ps_consts_f; ++j) {
i = This->contained_ps_consts_f[j];
}
/* Pixel Shader Integer Constants */
for (j = 0; j < This->num_contained_ps_consts_i; ++j) {
i = This->contained_ps_consts_i[j];
}
/* Pixel Shader Boolean Constants */
for (j = 0; j < This->num_contained_ps_consts_b; ++j) {
i = This->contained_ps_consts_b[j];
}
/* Others + Render & Texture */
for (i = 0; i < This->num_contained_transform_states; i++) {
TRACE("Updating transform %u\n", i);
}
TRACE("Updating pIndexData to %p, baseVertexIndex to %d\n",
}
TRACE("Updating vertex declaration from %p to %p\n", This->vertexDecl, targetStateBlock->vertexDecl);
}
sizeof(WINED3DMATERIAL)) != 0) {
TRACE("Updating material\n");
}
sizeof(WINED3DVIEWPORT)) != 0) {
TRACE("Updating viewport\n");
}
&This->scissorRect,
sizeof(targetStateBlock->scissorRect)))
{
TRACE("Updating scissor rect\n");
}
{
if (!(map & 1)) continue;
{
TRACE("Updating stream source %u to %p, stride to %u\n",
}
}
{
if (!(map & 1)) continue;
{
TRACE("Updating stream frequency %u to %u flags to %#x\n",
}
}
{
if (!(map & 1)) continue;
{
TRACE("Updating clipplane %u\n", i);
}
}
/* Render */
for (i = 0; i < This->num_contained_render_states; i++) {
This->renderState[This->contained_render_states[i]] = targetStateBlock->renderState[This->contained_render_states[i]];
}
/* Texture states */
for (j = 0; j < This->num_contained_tss_states; j++) {
}
/* Samplers */
/* TODO: move over to using memcpy */
{
if (!(map & 1)) continue;
}
for (j = 0; j < This->num_contained_sampler_states; j++) {
}
}
memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
}
for(i = 0; i < MAX_STREAMS; i++) {
}
}
}
}
memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
}
for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
This->samplerState[j][SavedVertexStates_S[i]] = targetStateBlock->samplerState[j][SavedVertexStates_S[i]];
}
}
for (j = 0; j < MAX_TEXTURES; j++) {
for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
This->textureState[j][SavedVertexStates_R[i]] = targetStateBlock->textureState[j][SavedVertexStates_R[i]];
}
}
for(i = 0; i < MAX_STREAMS; i++) {
}
}
}
memcpy(This->pixelShaderConstantB, targetStateBlock->pixelShaderConstantB, sizeof(This->pixelShaderConstantI));
memcpy(This->pixelShaderConstantI, targetStateBlock->pixelShaderConstantI, sizeof(This->pixelShaderConstantF));
memcpy(This->pixelShaderConstantF, targetStateBlock->pixelShaderConstantF, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
}
for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) {
for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
This->samplerState[j][SavedPixelStates_S[i]] = targetStateBlock->samplerState[j][SavedPixelStates_S[i]];
}
}
for (j = 0; j < MAX_TEXTURES; j++) {
for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
This->textureState[j][SavedPixelStates_R[i]] = targetStateBlock->textureState[j][SavedPixelStates_R[i]];
}
}
}
}
return WINED3D_OK;
}
UINT i;
for(i = 0; i < LIGHTMAP_SIZE; i++) {
struct list *e;
}
if(light->enabledChanged) {
}
}
}
}
/*Copy thing over to updateBlock is isRecording otherwise StateBlock,
should really perform a delta so that only the changes get updated*/
UINT i;
UINT j;
}
/* Vertex Shader Constants */
for (i = 0; i < This->num_contained_vs_consts_f; i++) {
}
for (i = 0; i < This->num_contained_vs_consts_i; i++) {
}
for (i = 0; i < This->num_contained_vs_consts_b; i++) {
}
}
/* Pixel Shader Constants */
for (i = 0; i < This->num_contained_ps_consts_f; i++) {
}
for (i = 0; i < This->num_contained_ps_consts_i; i++) {
}
for (i = 0; i < This->num_contained_ps_consts_b; i++) {
}
/* Render */
for (i = 0; i <= This->num_contained_render_states; i++) {
}
/* Texture states */
for (i = 0; i < This->num_contained_tss_states; i++) {
((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[stage][state] = This->textureState[stage][state];
/* TODO: Record a display list to apply all gl states. For now apply by brute force */
}
/* Sampler states */
for (i = 0; i < This->num_contained_sampler_states; i++) {
((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[stage][state] = This->samplerState[stage][state];
}
for (i = 0; i < This->num_contained_transform_states; i++) {
}
{
}
}
}
}
}
}
/* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
{
if (map & 1) IWineD3DDevice_SetStreamSource(pDevice, i, This->streamSource[i], 0, This->streamStride[i]);
}
{
if (map & 1) IWineD3DDevice_SetStreamSourceFreq(pDevice, i, This->streamFreq[i] | This->streamFlags[i]);
}
{
if (!(map & 1)) continue;
}
{
float clip[4];
if (!(map & 1)) continue;
}
for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
}
for (i = 0; i < MAX_CONST_I; i++) {
}
for (i = 0; i < MAX_CONST_B; i++) {
}
for(i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
IWineD3DDevice_SetRenderState(pDevice, SavedVertexStates_R[i], This->renderState[SavedVertexStates_R[i]]);
}
for(j = 0; j < MAX_TEXTURES; j++) {
for(i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
}
}
for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
}
}
for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
for(i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) {
}
}
for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
}
for (i = 0; i < MAX_CONST_I; i++) {
}
for (i = 0; i < MAX_CONST_B; i++) {
}
for(i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
IWineD3DDevice_SetRenderState(pDevice, SavedPixelStates_R[i], This->renderState[SavedPixelStates_R[i]]);
}
for(j = 0; j < MAX_TEXTURES; j++) {
for(i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
}
}
for(j = 0; j < MAX_FRAGMENT_SAMPLERS; j++) {
for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
}
}
for(j = MAX_FRAGMENT_SAMPLERS; j < MAX_COMBINED_SAMPLERS; j++) {
for(i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) {
}
}
for (i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
}
for (i = 0; i < MAX_CONST_I; i++) {
}
for (i = 0; i < MAX_CONST_B; i++) {
}
for (i = 0; i < GL_LIMITS(pshader_constantsF); i++) {
}
for (i = 0; i < MAX_CONST_I; i++) {
}
for (i = 0; i < MAX_CONST_B; i++) {
}
for(i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) {
}
for(j = 0; j < MAX_TEXTURES; j++) {
for (i = 0; i <= WINED3D_HIGHEST_TEXTURE_STATE; ++i)
{
}
}
/* Skip unused values between TEXTURE8 and WORLD0 ? */
for(i = 1; i <= HIGHEST_TRANSFORMSTATE; i++) {
}
/* TODO: Proper implementation using SetStreamSource offset (set to 0 for the moment)\n") */
for (i=0; i<MAX_STREAMS; i++) {
}
for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){
UINT sampler = j < MAX_FRAGMENT_SAMPLERS ? j : WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS;
for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE; ++i)
{
}
}
for (i = 0; i < GL_LIMITS(clipplanes); i++) {
float clip[4];
}
}
for(j = 0; j < MAX_TEXTURES - 1; j++) {
if(((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][WINED3DTSS_COLOROP] == WINED3DTOP_DISABLE) {
break;
}
}
return WINED3D_OK;
}
union {
DWORD d;
} lp;
union {
float f;
DWORD d;
} tmpfloat;
unsigned int i;
/* Note this may have a large overhead but it should only be executed
once, in order to initialize the complete state of the device and
all opengl equivalents */
TRACE("(%p) -----------------------> Setting up device defaults... %p\n", This, This->wineD3DDevice);
/* TODO: make a special stateblock type for the primary stateblock (it never gets applied so it doesn't need a real type) */
/* Set some of the defaults for lights, transforms etc */
for (i = 0; i < 256; ++i) {
}
TRACE("Render states\n");
/* Render states: */
} else {
}
tmpfloat.f = 0.0f;
tmpfloat.f = 1.0f;
tmpfloat.f = 1.0f;
tmpfloat.f = 1.0f;
tmpfloat.f = 1.0f;
tmpfloat.f = 0.0f;
tmpfloat.f = 0.0f;
tmpfloat.f = 1.0f;
tmpfloat.f = 0.0f;
/* states new in d3d9 */
tmpfloat.f = 1.0f;
tmpfloat.f = 0.0f;
tmpfloat.f = 1.0f;
tmpfloat.f = 0.0f;
/* clipping status */
/* Texture Stage States - Put directly into state block, we will call function below */
for (i = 0; i < MAX_TEXTURES; i++) {
TRACE("Setting up default texture states for texture Stage %d\n", i);
}
/* Sampler states*/
for (i = 0 ; i < MAX_COMBINED_SAMPLERS; i++) {
TRACE("Setting up default samplers states for sampler %d\n", i);
This->samplerState[i][WINED3DSAMP_ELEMENTINDEX ] = 0; /* TODO: Indicates which element of a multielement texture to use */
This->samplerState[i][WINED3DSAMP_DMAPOFFSET ] = 0; /* TODO: Vertex offset in the presampled displacement map */
}
/* Note: This avoids calling SetTexture, so pretend it has been called */
}
/* check the return values, because the GetBackBuffer call isn't valid for ddraw */
{
/* Set the default scissor rect values */
scissorrect.left = 0;
scissorrect.top = 0;
}
/* Set the default viewport */
vp.X = 0;
vp.Y = 0;
}
TRACE("-----------------------> Device defaults now set up...\n");
return WINED3D_OK;
}
/**********************************************************
* IWineD3DStateBlock VTbl follows
**********************************************************/
{
/* IUnknown */
/* IWineD3DStateBlock */
};