Beispiel #1
0
/////////////////////////////////////
// Name:	
// Purpose:	
// Output:	
// Return:	
/////////////////////////////////////
PUBLIC RETCODE OBJDisplay(hOBJ obj)
{
	assert(obj);
	assert(obj->theMdl);

	//set up culling
	if(TESTFLAGS(obj->theMdl->status, MDL_BACKFACECCW))
		g_p3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
	else
		g_p3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);

	//Vertex shaders are a complex topic, but you can do some amazing things with them
    //For this example we're not creating one, so we tell Direct3D that we're just
    //using a plain vertex format.
    g_p3DDevice->SetVertexShader(GFXVERTEXFLAG);

	//push world stack and set this object's world mtx
	g_pWrldStack->Push();
	g_pWrldStack->MultMatrix(&obj->wrldMtx.mtxWrld);

	//do transformations
    g_p3DDevice->SetTransform(D3DTS_WORLD, g_pWrldStack->GetTop());

	//draw the darn thing
	//this will do all sorts of pain in the ass for us, which is awesome!
	// Set and draw each of the materials in the mesh
    for( unsigned int i=0; i<obj->theMdl->numMaterial; i++ )
    {
		if(obj->theMdl->materials)
			g_p3DDevice->SetMaterial( &obj->theMdl->materials[i] );

		if(obj->theMdl->textures)
			if(obj->theMdl->textures[i])
				TextureSet(obj->theMdl->textures[i], 0);

        _GFXCheckError(obj->curMesh->DrawSubset(i),
		true, "Error in OBJDisplay");

		g_p3DDevice->SetTexture(0,0);
    }

	//display this object's children within it's world mtx
	for(LISTPTR::iterator j = obj->objNode->begin(); j != obj->objNode->end(); ++j)
		OBJDisplay((hOBJ)(*j));

	//take this junk out!
	g_pWrldStack->Pop();

	return RETCODE_SUCCESS;
}
Beispiel #2
0
bool RESGen::CheckWadUse(const StringMap::const_iterator &wadfileIt)
{
	WadCache::const_iterator wadIt = wadcache.find(wadfileIt->first);

	if(wadIt == wadcache.end())
	{
		// Haven't read this wad yet
		if(!CacheWad(wadfileIt->second))
		{
			// Failed to read wad
			// Cache this failure with an empty set to prevent wad being marked
			// as used
			wadcache[wadfileIt->first] = TextureSet();
			return false;
		}

		wadIt = wadcache.find(wadfileIt->first);
	}

	assert(wadIt != wadcache.end());

	bool bWadUsed = false;

	const TextureSet& textureSet = wadIt->second;

	StringMap::iterator it = texturelist.begin();

	// Look through all unfound textures and remove any that appear in this wad
	while(it != texturelist.end())
	{
		TextureSet::const_iterator textureIt = textureSet.find(it->first);

		if(textureIt != textureSet.end())
		{
			// found a texture, so wad is used
			bWadUsed = true;

			// update texture list
			it = texturelist.erase(it);
		}
		else
		{
			++it;
		}
	}

	return bWadUsed;
}
Beispiel #3
0
/////////////////////////////////////
// Name:	SkyBoxRender
// Purpose:	renders the skybox
// Output:	sky box rendered
// Return:	success if success
/////////////////////////////////////
PUBLIC RETCODE SkyBoxRender()
{
	if(!_SkyBoxValid()) //that means skybox hasn't been initialized
		return RETCODE_SUCCESS;

	//////////////////////////////////////////////////
	DWORD txtValU, txtValV;

	GFXGetSampleState(0, D3DSAMP_ADDRESSU, &txtValU);
	GFXGetSampleState(0, D3DSAMP_ADDRESSV, &txtValV);

	if(txtValU != D3DTADDRESS_CLAMP)
		GFXSetSampleState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);

	if(txtValV != D3DTADDRESS_CLAMP)
		GFXSetSampleState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
	//////////////////////////////////////////////////

	if(GFXIsLightEnabled())
	   g_p3DDevice->SetRenderState(D3DRS_LIGHTING,FALSE);

	g_p3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);

	/////////////////////////////////////////////////
	D3DXMATRIX viewMtx;

	g_p3DDevice->GetTransform(D3DTS_VIEW, &viewMtx);

	D3DXMATRIX skyViewMtx(viewMtx);

	skyViewMtx._41 = 0; skyViewMtx._42 = 0; skyViewMtx._43 = 0;

	g_p3DDevice->SetTransform(D3DTS_VIEW, &skyViewMtx);

	g_p3DDevice->SetTransform(D3DTS_WORLD, &g_skyTrans);
	/////////////////////////////////////////////////

	/////////////////////////////////////////////////
	g_p3DDevice->SetFVF(GFXSKYVERTEXFLAG);

	for(int i = 0; i < eSkyNumSide; i++)
	{
		//set texture
		TextureSet(g_skyTextures[i], 0);

		g_p3DDevice->SetStreamSource(0, g_pSkyVtxBuff[i], 0, sizeof(skyVertex));

	
		_GFXCheckError(g_p3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2),
		true, "SkyBoxRender");

		g_p3DDevice->SetStreamSource(0,0,0,0);
		g_p3DDevice->SetTexture(0,0);
	}
	/////////////////////////////////////////////////

	g_p3DDevice->SetTransform(D3DTS_VIEW, &viewMtx);

	//enable light again, if flag is set
    if(GFXIsLightEnabled())
	   g_p3DDevice->SetRenderState(D3DRS_LIGHTING,TRUE);

	g_p3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

	GFXSetSampleState(0, D3DSAMP_ADDRESSU, txtValU);
	GFXSetSampleState(0, D3DSAMP_ADDRESSV, txtValV);

	return RETCODE_SUCCESS;
}
Beispiel #4
0
PROTECTED RETCODE fxGas2Func(hPARFX thisPARFX, DWORD message, LPARAM dumbParam, WPARAM otherParam)
{
	switch(message)
	{
	case PARFXM_CREATE:
		{
			float center[eMaxPt];
			hOBJ obj = OBJQuery(&thisPARFX->objKey);
			fxGas2_init *init = (fxGas2_init *)dumbParam;

			if(!init) return RETCODE_FAILURE;

			//set up the main particle
			if(MemAlloc(&thisPARFX->data, sizeof(fxGas2), M_ZERO) != RETCODE_SUCCESS)
			{ ASSERT_MSG(0, "Unable to allocate gas data", "fxGas2Func"); return RETCODE_FAILURE; }

			fxGas2 *data = (fxGas2 *)thisPARFX->data;

			data->gasTxt	  = init->gasTxt; TextureAddRef(data->gasTxt);
			data->size		  = init->size;
			data->maxParticle = init->maxParticle;

			//translate the bounds if obj is specified
			if(obj)
				OBJGetLoc(obj, center);
			else
				memcpy(center, init->center, sizeof(float)*eMaxPt);

			//allocate the particle gases
			if(MemAlloc((void**)&data->bunchOgas, sizeof(fxGas2_par)*data->maxParticle, M_ZERO) != RETCODE_SUCCESS)
			{ ASSERT_MSG(0, "Unable to allocate gas particles", "fxGas2Func"); return RETCODE_FAILURE; }

			//create vertex buffer
			//_GFXCheckError(HRESULT hr, bool displayMsg, const char *header)
			if(_GFXCheckError(g_p3DDevice->CreateVertexBuffer(sizeof(fxGas_vtx)*data->maxParticle,
				D3DUSAGE_POINTS, FXGASVTXFLAG, D3DPOOL_MANAGED, &data->gasVtx), true, "fxGas2Func"))
				return RETCODE_FAILURE;

			//initialize each gas particle
			for(int i = 0; i < data->maxParticle; i++)
				_fxGas2InitParticle(init, center, &data->bunchOgas[i]);
		}
		break;
	
	case PARFXM_UPDATE:
		{
			fxGas2 *data = (fxGas2 *)thisPARFX->data;

			fxGas_vtx *pGasVtx;

			if(FAILED(data->gasVtx->Lock(0,0, (BYTE**)&pGasVtx, 0)))
			{ ASSERT_MSG(0, "Unable to lock gas particle vtx", "fxGas2Func"); return RETCODE_FAILURE; }

			data->numAlive=0;

			for(int i = 0; i < data->maxParticle; i++)
			{
				if(_fxGas2UpdateParticle(&data->bunchOgas[i], data->size))
				{
					memcpy(&pGasVtx[i], &data->bunchOgas[i].curVtx, sizeof(fxGas_vtx));
					data->numAlive++;
				}
			}

			data->gasVtx->Unlock();

			if(data->numAlive==0)
				return RETCODE_BREAK;
		}
		break;

	case PARFXM_DISPLAY:
		{
			//push world stack and set this object's world mtx
			g_pWrldStack->Push();
			g_pWrldStack->LoadIdentity();

			//do transformations
			g_p3DDevice->SetTransform(D3DTS_WORLD, g_pWrldStack->GetTop());

			DWORD srcBlend, destBlend;

			fxGas2 *data = (fxGas2 *)thisPARFX->data;

			//disable light
			if(!TESTFLAGS(g_FLAGS, GFX_LIGHTDISABLE))
				g_p3DDevice->SetRenderState(D3DRS_LIGHTING,FALSE);

			TextureSet(data->gasTxt, 0);

			g_p3DDevice->GetRenderState( D3DRS_SRCBLEND, &srcBlend );
			g_p3DDevice->GetRenderState( D3DRS_DESTBLEND, &destBlend );

			g_p3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
			g_p3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

			g_p3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
			g_p3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
			g_p3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  TRUE );
			g_p3DDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.08f) );
			g_p3DDevice->SetRenderState( D3DRS_POINTSIZE_MAX, FtoDW(1000.0f) );
			g_p3DDevice->SetRenderState( D3DRS_POINTSCALE_A,  FtoDW(0.00f) );
			g_p3DDevice->SetRenderState( D3DRS_POINTSCALE_B,  FtoDW(0.00f) );
			g_p3DDevice->SetRenderState( D3DRS_POINTSCALE_C,  FtoDW(1.00f) );

			g_p3DDevice->SetStreamSource( 0, data->gasVtx, sizeof(fxGas_vtx) );
			g_p3DDevice->SetVertexShader( FXGASVTXFLAG );

			if(FAILED(g_p3DDevice->DrawPrimitive( D3DPT_POINTLIST, 0, data->numAlive)))
			{ ASSERT_MSG(0, "Failed to draw particles", "fxGasFunc"); return RETCODE_FAILURE; }

			g_p3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
			g_p3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, FALSE );
			g_p3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  FALSE );

			g_p3DDevice->SetRenderState( D3DRS_SRCBLEND, srcBlend );
			g_p3DDevice->SetRenderState( D3DRS_DESTBLEND, destBlend );

			//enable light again, if flag is set
			if(!TESTFLAGS(g_FLAGS, GFX_LIGHTDISABLE))
				g_p3DDevice->SetRenderState(D3DRS_LIGHTING,TRUE);

			TextureSet(0, 0);

			//take this junk out!
			g_pWrldStack->Pop();
		}
		break;

	case PARFXM_DESTROY:
		{
			fxGas2 *data = (fxGas2 *)thisPARFX->data;

			if(data)
			{
				if(data->bunchOgas)
					MemFree((void**)&data->bunchOgas);

				TextureDestroy(&data->gasTxt);

				if(data->gasVtx)
					data->gasVtx->Release();
			}
		}
		break;
	}

	return RETCODE_SUCCESS;
}