void RenderChain::set_shaders(CGprogram &fPrg, CGprogram &vPrg) { #ifdef HAVE_CG cgD3D9BindProgram(fPrg); cgD3D9BindProgram(vPrg); #endif }
static INLINE void d3d9_cg_bind_program(void *data) { struct shader_pass *pass = (struct shader_pass*)data; if (!pass) return; cgD3D9BindProgram((CGprogram)pass->fprg); cgD3D9BindProgram((CGprogram)pass->vprg); }
//--------------------------------------------------------------------------------- // bind vertex/fragment program // PSGL specific //--------------------------------------------------------------------------------- void FFxProgram::bind() { if (!mProgram) return; #ifdef WIN32 if (GDD->GetClassID() == ClassIDZDisplayDeviceDX9) { HRESULT hr = cgD3D9BindProgram(mProgram); /* if (mProfile == CG_PROFILE_VS_2_0) { HRESULT hr = GDD->GetD3D9Device()->SetVertexShader((IDirect3DVertexShader9*)mDXShader->GetBufferPointer()); int a = 1; } else { GDD->GetD3D9Device()->SetPixelShader((IDirect3DPixelShader9*)mDXShader->GetBufferPointer()); } */ } else #endif { cgGLEnableProfile(mProfile); cgGLBindProgram(mProgram); } }
void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& pMaterial, const SMaterial& pLastMaterial, bool pResetRS, IMaterialRendererServices* pService) { Material = pMaterial; if (pMaterial.MaterialType != pLastMaterial.MaterialType || pResetRS) { if (VertexProgram) cgD3D9BindProgram(VertexProgram); if (FragmentProgram) cgD3D9BindProgram(FragmentProgram); /*if (GeometryProgram) cgD3D9BindProgram(GeometryProgram);*/ if (BaseMaterial) BaseMaterial->OnSetMaterial(pMaterial, pMaterial, true, this); } if (CallBack) CallBack->OnSetMaterial(pMaterial); Driver->setBasicRenderStates(pMaterial, pLastMaterial, pResetRS); }
void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services) { Material = material; if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { if (VertexProgram) cgD3D9BindProgram(VertexProgram); if (FragmentProgram) cgD3D9BindProgram(FragmentProgram); /*if (GeometryProgram) cgD3D9BindProgram(GeometryProgram);*/ if (BaseMaterial) BaseMaterial->OnSetMaterial(material, material, true, this); } if (CallBack) CallBack->OnSetMaterial(material); Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); }
static void CALLBACK OnFrameRender(IDirect3DDevice9* pDev, double time, float elapsedTime, void* userContext) { pDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR(0.1f, 0.3f, 0.6f, 0.0f), 1.0f, 0); if (SUCCEEDED(pDev->BeginScene())) { #if 0 pDev->SetTransform(D3DTS_WORLD, &g_matrixWorld); pDev->SetTransform(D3DTS_VIEW, &g_matrixView); pDev->SetTransform(D3DTS_PROJECTION, &g_matrixProjection); pDev->SetLight(0, &g_light); pDev->LightEnable(0, TRUE); pDev->SetMaterial(&g_material); //pDev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); pDev->SetRenderState(D3DRS_SPECULARENABLE,TRUE); #else cgD3D9BindProgram(g_cgVertexProgram); checkForCgError("binding vertex program"); #endif cgSetParameterValuefc(g_cgWorldMatrix, 16, g_matrixWorld.m[0]); cgSetParameterValuefc(g_cgWorldViewProjMatrix, 16, g_matrixWorldViewProj.m[0]); cgSetParameterValuefc(g_cgAmbient, 3, (float*)&g_light.Ambient); cgSetParameterValuefc(g_cgLightColor, 3, (float*)&g_light.Diffuse); cgSetParameterValuefc(g_cgLightPos, 3, (float*)&g_light.Position); cgSetParameterValuefc(g_cgEyePos, 3, (float*)&g_eyePos); cgSetParameterValuefc(g_cgKe, 3, (float*)&g_material.Emissive); cgSetParameterValuefc(g_cgKa, 3, (float*)&g_material.Ambient); cgSetParameterValuefc(g_cgKd, 3, (float*)&g_material.Diffuse); cgSetParameterValuefc(g_cgKs, 3, (float*)&g_material.Specular); cgSetParameterValuefc(g_cgShininess, 3, &g_material.Power); g_pMeshSphere->DrawSubset(0); pDev->EndScene(); } }
static INLINE void renderchain_set_shaders(CGprogram frag, CGprogram vert) { cgD3D9BindProgram(frag); cgD3D9BindProgram(vert); }
static INLINE void renderchain_set_shaders(void *data, CGprogram *fPrg, CGprogram *vPrg) { cgD3D9BindProgram(*fPrg); cgD3D9BindProgram(*vPrg); }
void CD3DCG::Render(LPDIRECT3DTEXTURE9 &origTex, D3DXVECTOR2 textureSize, D3DXVECTOR2 inputSize, D3DXVECTOR2 viewportSize, D3DXVECTOR2 windowSize) { LPDIRECT3DSURFACE9 pRenderSurface = NULL,pBackBuffer = NULL; frameCnt++; if(!shaderLoaded) return; /* save back buffer render target */ pDevice->GetRenderTarget(0,&pBackBuffer); /* pass 0 represents the original texture */ shaderPasses[0].tex = origTex; shaderPasses[0].outputSize = inputSize; shaderPasses[0].textureSize = textureSize; calculateMatrix(); for(int i=1;i<shaderPasses.size();i++) { switch(shaderPasses[i].scaleParams.scaleTypeX) { case CG_SCALE_ABSOLUTE: shaderPasses[i].outputSize.x = (double)shaderPasses[i].scaleParams.absX; break; case CG_SCALE_SOURCE: shaderPasses[i].outputSize.x = shaderPasses[i-1].outputSize.x * shaderPasses[i].scaleParams.scaleX; break; case CG_SCALE_VIEWPORT: shaderPasses[i].outputSize.x = viewportSize.x * shaderPasses[i].scaleParams.scaleX; break; default: shaderPasses[i].outputSize.x = viewportSize.x; } switch(shaderPasses[i].scaleParams.scaleTypeY) { case CG_SCALE_ABSOLUTE: shaderPasses[i].outputSize.y = (double)shaderPasses[i].scaleParams.absY; break; case CG_SCALE_SOURCE: shaderPasses[i].outputSize.y = shaderPasses[i-1].outputSize.y * shaderPasses[i].scaleParams.scaleY; break; case CG_SCALE_VIEWPORT: shaderPasses[i].outputSize.y = viewportSize.y * shaderPasses[i].scaleParams.scaleY; break; default: shaderPasses[i].outputSize.y = viewportSize.y; } float texSize = npot(max(shaderPasses[i].outputSize.x,shaderPasses[i].outputSize.y)); /* make sure the render target exists and has an appropriate size, then set as current render target with last pass as source */ ensureTextureSize(shaderPasses[i].tex,shaderPasses[i].textureSize,D3DXVECTOR2(texSize,texSize),true); shaderPasses[i].tex->GetSurfaceLevel(0,&pRenderSurface); pDevice->SetTexture(0, shaderPasses[i-1].tex); pDevice->SetRenderTarget(0,pRenderSurface); pRenderSurface->Release(); /* set vertex declaration of current pass, update vertex buffer and set base streams */ pDevice->SetVertexDeclaration(shaderPasses[i].vertexDeclaration); setVertexStream(shaderPasses[i].vertexBuffer, shaderPasses[i-1].outputSize,shaderPasses[i-1].textureSize,shaderPasses[i].outputSize); pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, shaderPasses[i].linearFilter?D3DTEXF_LINEAR:D3DTEXF_POINT); pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, shaderPasses[i].linearFilter?D3DTEXF_LINEAR:D3DTEXF_POINT); /* shader vars need to be set after the base vertex streams have been set so they can override them */ setShaderVars(i); cgD3D9BindProgram(shaderPasses[i].cgVertexProgram); checkForCgError("Binding vertex program"); cgD3D9BindProgram(shaderPasses[i].cgFragmentProgram); checkForCgError("Binding fragment program"); /* viewport defines output size */ setViewport(0,0,shaderPasses[i].outputSize.x,shaderPasses[i].outputSize.y); pDevice->BeginScene(); pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); pDevice->EndScene(); } /* take oldes PREV out of deque, make sure it has the same size as the current texture and then set it up as new original texture */ prevPass &oldestPrev = prevPasses.back(); ensureTextureSize(oldestPrev.tex,oldestPrev.textureSize,textureSize,false); if(oldestPrev.vertexBuffer) oldestPrev.vertexBuffer->Release(); origTex = oldestPrev.tex; prevPasses.pop_back(); /* push current original with corresponding vertex buffer to front of PREV deque */ shaderPasses[0].vertexBuffer = shaderPasses[1].vertexBuffer; prevPasses.push_front(prevPass(shaderPasses[0])); /* create new vertex buffer so that next render call will not overwrite the PREV */ pDevice->CreateVertexBuffer(sizeof(VERTEX)*4,D3DUSAGE_WRITEONLY,0,D3DPOOL_MANAGED,&shaderPasses[1].vertexBuffer,NULL); /* set up last pass texture, backbuffer and viewport for final display pass without shaders */ pDevice->SetTexture(0, shaderPasses.back().tex); pDevice->SetRenderTarget(0,pBackBuffer); pBackBuffer->Release(); RECT displayRect=CalculateDisplayRect(shaderPasses.back().outputSize.x,shaderPasses.back().outputSize.y,windowSize.x,windowSize.y); setViewport(displayRect.left,displayRect.top,displayRect.right - displayRect.left,displayRect.bottom - displayRect.top); setVertexStream(shaderPasses.back().vertexBuffer, shaderPasses.back().outputSize,shaderPasses.back().textureSize, D3DXVECTOR2(displayRect.right - displayRect.left,displayRect.bottom - displayRect.top)); pDevice->SetVertexShader(NULL); pDevice->SetPixelShader(NULL); }