Example #1
0
void 
Surface::setFilterEnable(const bool in_enabled, const bool in_hardenState)
{
   
   if (in_hardenState == true) {
      DWORD filterMode = (in_enabled == true) ? D3DFILTER_LINEAR : D3DFILTER_NEAREST;
      setRenderState(D3DRENDERSTATE_TEXTUREMAG, filterMode);
      setRenderState(D3DRENDERSTATE_TEXTUREMIN, filterMode);
   }
}
Example #2
0
void 
Surface::setWrapEnable(const bool in_enabled, const bool in_hardenState)
{
   if (in_hardenState == true) {
      if (in_enabled == true) {
         setRenderState(D3DRENDERSTATE_TEXTUREADDRESS, D3DTADDRESS_WRAP);
      } else {
         setRenderState(D3DRENDERSTATE_TEXTUREADDRESS, D3DTADDRESS_CLAMP);
      }
   } else {
      isWrapEnabled = in_enabled;
   }
}
Example #3
0
void 
Surface::setShadeEnable(const bool in_enabled, const bool in_hardenState)
{
   if (in_hardenState == true) {
      if (in_enabled == true) {
         setRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE);
      } else {
         setRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_DECAL);
      }
   } else {
      isShadeEnabled = in_enabled;
   }
}
Example #4
0
	void Renderer::init()
	{
		// Temp Should set to default OpenGL states.
		memset(m_aeState, 0, sizeof(unsigned int)*STATE_COUNT);
		m_aeState[STATE_BLEND_DST] = ONE;
		m_aeState[STATE_BLEND_SRC] = ONE;

		//////////////////////////////////////////////////////////////////////////
		// Temp settings for testing - these will be encapsulated elsewhere
		setClearColour(Vec4(0.0f, 0.0f, 0.0f, 0.0f));
		setRenderState(STATE_DEPTH_TEST, TRUE);
		setRenderState(STATE_BLEND_SRC, SRC_ALPHA);
		setRenderState(STATE_BLEND_DST, ONE_MINUS_SRC_ALPHA);
		//////////////////////////////////////////////////////////////////////////
	}
Example #5
0
	void GUIWindow::open()
	{
		enableBit(state, GUIRECT_OPEN);
		setRenderState(true);
		refresh();
		std::cout << "\nWindow opened: " << header->getString();
	}
Example #6
0
//------------------------------------------------------------------------------
// NAME 
//    void 
//    Surface::setColorKey(const bool in_enabled)
//    
// DESCRIPTION 
//    Enable the color key on the surface if flag is true, disable otherwise...
//    
// NOTES 
//    
//------------------------------------------------------------------------------
void 
Surface::setColorKey(const bool in_enabled, const bool in_hardenState)
{
   if (in_hardenState == true)
      setRenderState(D3DRENDERSTATE_COLORKEYENABLE, in_enabled);
   else
      transparencyEnabled = in_enabled;
}
Example #7
0
void	RenderTargetD3D9::switchTo3D()
{
    if( !m_b2D ) return;
    m_b2D = false;

    m_RenderState2D = m_RenderState;
    setRenderState(m_RenderState3D);
}
Example #8
0
void 
Surface::setFogEnable(const bool in_enabled, const bool in_hardenState)
{
   if (in_hardenState == true)
      setRenderState(D3DRENDERSTATE_FOGENABLE, in_enabled);
   else
      isFogEnabled = in_enabled;
}
Example #9
0
	void GUIWindow::close()
	{
		disableBit(state, GUIRECT_OPEN);
		disableBit(state, GUIRECT_MOUSE_HOVER);
		disableBit(state, GUIRECT_MOUSE_HOVER_CONTAINER);
		disable();
		setRenderState(false);
		std::cout << "\nWindow closed: " << header->getString();
	}
Example #10
0
void Renderer::setActiveMaterial(mtl::Material* material)
{
    if (m_activeMaterial == material)
        return;

    if (m_renderStateHash != material->renderStateHash())
        setRenderState(material->renderState());

    material->syncParams();
    m_activeMaterial = material;
}
Example #11
0
//2d 3d切换
void	RenderTargetD3D9::switchTo2D()
{
    if( m_b2D ) return;
    m_b2D = true;

    m_RenderState2D.m_mtxProjection = Matrix4::orthogonalProjection(
                                          m_viewport.X, m_viewport.X+m_viewport.Width,
                                          m_viewport.Y + m_viewport.Height, m_viewport.Y,
                                          -1.0f, 1.0f);

    m_RenderState3D = m_RenderState;
    setRenderState(m_RenderState2D);
}
Example #12
0
void AnimationSprite::Draw(D3DXVECTOR3 const&position) const
{
	/*
	D3DXVECTOR3 p = position;
	p.x = (int)p.x;
	p.y = (int)p.y;
	p.z = (int)p.z;
	*/
	sprite->Begin(D3DXSPRITE_ALPHABLEND);
	setRenderState();
	sprite->Draw(texture[count / interval], &range, &center, &position, D3DCOLOR_ARGB(0xFF, 0xFF, 0xFF, 0xFF));
	sprite->End();
}
Example #13
0
void ShadowMapRenderer::BeginShadowMapPass()
{
	IDirect3DDevice9* d3dDevice = gEngine->GetDriver()->GetD3DDevice();

	d3dDevice->GetRenderTarget(0, &mPrevRenderTarget);
	d3dDevice->GetDepthStencilSurface(&mPrevDepthStencil);

	d3dDevice->SetRenderTarget(0, mShadowMapRTSurface);
	d3dDevice->SetDepthStencilSurface(mDepthStencilSurface);

	d3dDevice->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0);

	setRenderState();
	
	mShadowMapEffect->Begin(0, 0);
	mShadowMapEffect->BeginPass(0);
}
Example #14
0
void AnimationSprite::Draw(D3DXVECTOR3 const&position, float const angle) const
{
	sprite->Begin(D3DXSPRITE_ALPHABLEND);
	D3DXMATRIX matRotation;
	D3DXMatrixRotationZ(&matRotation, angle);
	D3DXMATRIX matTranslation;
	D3DXMatrixTranslation(&matTranslation, position.x, position.y, 0);
	D3DXMATRIX matWorld;
	D3DXMATRIX matIdentity;
	D3DXMatrixIdentity(&matIdentity);
	matWorld = matRotation*matTranslation;
	sprite->SetTransform(&matWorld);
	setRenderState();
	sprite->Draw(texture[count / interval], &range, &center, 0, D3DCOLOR_ARGB(0xFF, 0xFF, 0xFF, 0xFF));
	sprite->SetTransform(&matIdentity);
	sprite->End();
}
Example #15
0
void ShadowMapRenderer::ShadowMapGaussianBlur(int cascadeIndex)
{
	IDirect3DDevice9* d3dDevice = gEngine->GetDriver()->GetD3DDevice();

	d3dDevice->GetRenderTarget(0, &mPrevRenderTarget);
	d3dDevice->GetDepthStencilSurface(&mPrevDepthStencil);

	setRenderState();

	shadowMapGaussianBlurH();
	shadowMapGaussianBlurV(cascadeIndex);

	d3dDevice->SetRenderTarget(0, mPrevRenderTarget);
	d3dDevice->SetDepthStencilSurface(mPrevDepthStencil);

	SAFE_RELEASE(mPrevRenderTarget);		// GetRenderTarget方法会增加引用计数, 需要release, 否则设备无法恢复
	SAFE_RELEASE(mPrevDepthStencil);

}
Example #16
0
void ShadowMapRenderer::BeginShadowTexPass()
{
	gEngine->GetDriver()->GetD3DDevice()->GetRenderTarget(0, &mPrevRenderTarget);
	gEngine->GetDriver()->GetD3DDevice()->GetDepthStencilSurface(&mPrevDepthStencil);

	IDirect3DSurface9* shadowTexSurface = NULL; 
	mShadowTex->GetD3DTexture()->GetSurfaceLevel(0, &shadowTexSurface);

	gEngine->GetDriver()->GetD3DDevice()->SetRenderTarget(0, shadowTexSurface);
	gEngine->GetDriver()->GetD3DDevice()->SetDepthStencilSurface(mDepthStencilSurface);

	gEngine->GetDriver()->GetD3DDevice()->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0);

	setRenderState();

	mShadowTexEffect->Begin(0, 0);
	mShadowTexEffect->BeginPass(0);

	SAFE_RELEASE(shadowTexSurface);
}
Example #17
0
void AnimationSprite::Draw(D3DXVECTOR3 const&position, float const angle, float const scale, int const alpha) const
{
	sprite->Begin(D3DXSPRITE_ALPHABLEND);
	D3DXMATRIX matScale, matRotation, matTranslation, matWorld, matIdentity;
	D3DXMatrixScaling(&matScale, scale, scale, scale);
	D3DXMatrixRotationZ(&matRotation, angle);
	D3DXMatrixTranslation(&matTranslation, position.x, position.y, 0);
	D3DXMatrixIdentity(&matIdentity);
	matWorld = matScale * matRotation * matTranslation;
	sprite->SetTransform(&matWorld);
	setRenderState();
	if (additive)
	{
		sprite->Draw(texture[count / interval], &range, &center, 0, D3DCOLOR_ARGB(alpha, alpha, alpha, alpha));
	}
	else
	{
		sprite->Draw(texture[count / interval], &range, &center, 0, D3DCOLOR_ARGB(alpha, 0xFF, 0xFF, 0xFF));
	}
	sprite->SetTransform(&matIdentity);
	sprite->End();
}
Example #18
0
void 
Surface::setZEnable(const int in_state, const bool in_hardenState)
{
   if (in_hardenState == true) {
      if (in_state == GFX_NO_ZTEST) {
         setRenderState(D3DRENDERSTATE_ZENABLE, FALSE);
         setRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE);
      } else if (in_state == GFX_ZTEST_AND_WRITE) {
         setRenderState(D3DRENDERSTATE_ZENABLE,      TRUE);
         setRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE);
         setRenderState(D3DRENDERSTATE_ZFUNC,        D3DCMP_GREATEREQUAL);
      } else if (in_state == GFX_ZTEST) {
         setRenderState(D3DRENDERSTATE_ZENABLE,      TRUE);
         setRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE);
         setRenderState(D3DRENDERSTATE_ZFUNC,        D3DCMP_GREATEREQUAL);
      } else { // GFX_ZWRITE
         setRenderState(D3DRENDERSTATE_ZENABLE,      TRUE);
         setRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE);
         setRenderState(D3DRENDERSTATE_ZFUNC,        D3DCMP_ALWAYS);
      }
   } else {
      isZEnabled = in_state;
   }
}
void CircleSprite::privDraw()
{
	transform();
	setRenderState();
	draw();
}
Example #20
0
gxScene::gxScene( gxGraphics *g,gxCanvas *t ):
graphics(g),target(t),dir3dDev( g->dir3dDev ),
n_texs(0),tris_drawn(0){

	memset( d3d_rs,0x55,sizeof(d3d_rs) );
	memset( d3d_tss,0x55,sizeof(d3d_tss) );

	//nomalize normals
	setRS( D3DRENDERSTATE_NORMALIZENORMALS,TRUE );

	//vertex coloring
	setRS( D3DRENDERSTATE_COLORVERTEX,FALSE );
	setRS( D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,D3DMCS_COLOR1 );
	setRS( D3DRENDERSTATE_AMBIENTMATERIALSOURCE,D3DMCS_COLOR1 );
	setRS( D3DRENDERSTATE_EMISSIVEMATERIALSOURCE,D3DMCS_MATERIAL );
	setRS( D3DRENDERSTATE_SPECULARMATERIALSOURCE,D3DMCS_MATERIAL );

	//Alpha test
	setRS( D3DRENDERSTATE_ALPHATESTENABLE,false );
	setRS( D3DRENDERSTATE_ALPHAFUNC,D3DCMP_GREATER );
	setRS( D3DRENDERSTATE_ALPHAREF,128 );

	//source/dest blending modes
	setRS( D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA );
	setRS( D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA );

	//suss out caps
	can_wb=false;
	hw_tex_stages=1;
	D3DDEVICEDESC7 devDesc={0};
	if( dir3dDev->GetCaps( &devDesc )>=0 ){
		DWORD caps=devDesc.dpcTriCaps.dwRasterCaps;
		//texture stages
		hw_tex_stages=devDesc.wMaxSimultaneousTextures;
		//depth buffer mode
		if( (caps & D3DPRASTERCAPS_WBUFFER) && graphics->zbuffFmt.dwRGBBitCount==16 ) can_wb=true;
		//fog mode
		if( (caps&D3DPRASTERCAPS_FOGTABLE)&&(caps&D3DPRASTERCAPS_WFOG) ){
			setRS( D3DRENDERSTATE_FOGVERTEXMODE,D3DFOG_NONE );
			setRS( D3DRENDERSTATE_FOGTABLEMODE,D3DFOG_LINEAR );
		}else{
			setRS( D3DRENDERSTATE_FOGTABLEMODE,D3DFOG_NONE );
			setRS( D3DRENDERSTATE_FOGVERTEXMODE,D3DFOG_LINEAR );
		}
	}
	tex_stages=hw_tex_stages;

	caps_level=100;
	if( devDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP ){
		caps_level=110;
	}

	//default texture states
	for( int n=0;n<hw_tex_stages;++n ){
		setTSS( n,D3DTSS_COLORARG1,D3DTA_TEXTURE );
		setTSS( n,D3DTSS_COLORARG2,D3DTA_CURRENT );
		setTSS( n,D3DTSS_ALPHAARG1,D3DTA_TEXTURE );
		setTSS( n,D3DTSS_ALPHAARG2,D3DTA_CURRENT );
		setTSS( n,D3DTSS_MINFILTER,D3DTFN_LINEAR );
		setTSS( n,D3DTSS_MAGFILTER,D3DTFG_LINEAR );
		setTSS( n,D3DTSS_MIPFILTER,D3DTFP_LINEAR );
	}
	setHWMultiTex( true );

	//ATI lighting hack
	dir3dDev->LightEnable( 0,true );
	dir3dDev->LightEnable( 0,false );

	//globals
	sphere_mat._11=.5f;sphere_mat._22=-.5f;sphere_mat._33=.5f;
	sphere_mat._41=.5f;sphere_mat._42=.5f;sphere_mat._43=.5f;
	nullmatrix._11=nullmatrix._22=nullmatrix._33=nullmatrix._44=1;

	//set null renderstate
	memset(&material,0,sizeof(material));
	shininess=0;blend=BLEND_REPLACE;fx=0;
	for( int k=0;k<MAX_TEXTURES;++k ) memset( &texstate[k],0,sizeof(texstate[k]) );

	wbuffer=can_wb;
	dither=false;setDither( true );
	antialias=true;setAntialias( false );
	wireframe=true;setWireframe( false );
	flipped=true;setFlippedTris( false );
	ambient=~0;setAmbient( GRAY );
	ambient2=~0;setAmbient2( BLACK );
	fogcolor=~0;setFogColor( BLACK );
	fogrange_nr=fogrange_fr=0;setFogRange( 1,1000 );
	fogmode=FOG_LINEAR;setFogMode( FOG_NONE );
	zmode=-1;setZMode( ZMODE_NORMAL );
	memset(&projmatrix,0,sizeof(projmatrix));
	ortho_proj=true;frustum_nr=frustum_fr=frustum_w=frustum_h=0;setPerspProj( 1,1000,1,1 );
	memset(&viewport,0,sizeof(viewport));viewport.dvMaxZ=1;setViewport( 0,0,target->getWidth(),target->getHeight() );
	viewmatrix=nullmatrix;setViewMatrix( 0 );
	worldmatrix=nullmatrix;setWorldMatrix( 0 );

	//set default renderstate
	blend=fx=~0;shininess=1;
	RenderState state;memset(&state,0,sizeof(state));
	state.color[0]=state.color[1]=state.color[2]=state.alpha=1;
	state.blend=BLEND_REPLACE;
	setRenderState( state );
}
Example #21
0
void font_draw(meshset_t* fontmesh, uint32_t characterCount)
{
 	setRenderState(s_fontCtx.fontState);
 	setShaderParamBuffer(s_fontCtx.fontSettingsParam, s_fontCtx.fontSettingsBuffer);
	drawMeshSet(fontmesh, s_fontCtx.fontShader, characterCount*6);
}
Example #22
0
//------------------------------------------------------------------------------
// NAME 
//    void 
//    Surface::setDefaultRenderState()
//    
// DESCRIPTION 
//    Gets the current renderstate from the device, at least those that
//   we are interested in...
//    
// NOTES 
//    Assumes that all calls to GetRenderState succeed.
//------------------------------------------------------------------------------
void 
Surface::setDefaultRenderState()
{
   setRenderState(D3DRENDERSTATE_TEXTUREHANDLE,
                  defaultRenderState.textureHandle);
   setRenderState(D3DRENDERSTATE_TEXTUREADDRESS,
                  defaultRenderState.textureAddress);
   setRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE,
                  defaultRenderState.texturePerspective);
   setRenderState(D3DRENDERSTATE_WRAPU,
                  defaultRenderState.wrapU);
   setRenderState(D3DRENDERSTATE_WRAPV,
                  defaultRenderState.wrapV);
   setRenderState(D3DRENDERSTATE_ZENABLE,
                  defaultRenderState.zEnable);
   setRenderState(D3DRENDERSTATE_FILLMODE,
                  defaultRenderState.fillMode);
   setRenderState(D3DRENDERSTATE_SHADEMODE,
                  defaultRenderState.shadeMode);
   setRenderState(D3DRENDERSTATE_ZWRITEENABLE,
                  defaultRenderState.zWriteEnable);
   setRenderState(D3DRENDERSTATE_ALPHATESTENABLE,
                  defaultRenderState.alphaTestEnable);
   setRenderState(D3DRENDERSTATE_SRCBLEND,
                  defaultRenderState.srcBlend);
   setRenderState(D3DRENDERSTATE_DESTBLEND,
                  defaultRenderState.destBlend);
   setRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND,
                  defaultRenderState.textureMapBlend);
   setRenderState(D3DRENDERSTATE_CULLMODE,
                  defaultRenderState.cullMode);
   setRenderState(D3DRENDERSTATE_ZFUNC,
                  defaultRenderState.zFunc);
   setRenderState(D3DRENDERSTATE_ALPHAREF,
                  defaultRenderState.alphaRef);
   setRenderState(D3DRENDERSTATE_ALPHAFUNC,
                  defaultRenderState.alphaFunc);
   setRenderState(D3DRENDERSTATE_FOGENABLE,
                  defaultRenderState.fogEnable);
   setRenderState(D3DRENDERSTATE_FOGCOLOR,
                  defaultRenderState.fogColor);
   setRenderState(D3DRENDERSTATE_COLORKEYENABLE,
                  defaultRenderState.colorKeyEnable);
   setRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,
                  defaultRenderState.alphaBlendEnable);
   setRenderState(D3DRENDERSTATE_BLENDENABLE,
                  defaultRenderState.blendEnable);

   // Filter mode, device dependant, so not set from defaultRenderState...
   //
   setRenderState(D3DRENDERSTATE_TEXTUREMAG,
                  D3DDevDescVector[deviceMinorId].filterMode);
   setRenderState(D3DRENDERSTATE_TEXTUREMIN,
                  D3DDevDescVector[deviceMinorId].filterMode);
}