void ProgramInstance::apply() const { DP_ASSERT( m_unsetShaderStorageBlocks.empty() && m_unsetUniforms.empty() ); GLint programID = m_program->getGLId(); glUseProgram( programID ); for ( std::map<size_t,ImageUniformData>::const_iterator it = m_imageUniforms.begin() ; it != m_imageUniforms.end() ; ++it ) { DP_ASSERT( it->second.texture ); glBindImageTexture( m_program->getActiveUniform( it->first ).unit, it->second.texture->getGLId(), 0, GL_FALSE, 0, it->second.access, it->second.texture->getInternalFormat() ); } for ( std::map<size_t,SamplerUniformData>::const_iterator it = m_samplerUniforms.begin() ; it != m_samplerUniforms.end() ; ++it ) { DP_ASSERT( it->second.texture ); GLint unit = m_program->getActiveUniform( it->first ).unit; glActiveTexture( GL_TEXTURE0 + unit ); glBindTexture( it->second.texture->getTarget(), it->second.texture->getGLId() ); glBindSampler( unit , it->second.sampler->getGLId() ); } for ( size_t i=0 ; i<m_shaderStorageBuffers.size() ; i++ ) { DP_ASSERT( m_shaderStorageBuffers[i] ); glBindBufferBase( GL_SHADER_STORAGE_BUFFER, m_program->getShaderStorageBlocks()[i].binding, m_shaderStorageBuffers[i]->getGLId() ); } for ( std::map<size_t,std::vector<char>>::const_iterator it = m_uniforms.begin() ; it != m_uniforms.end() ; ++it ) { Program::Uniform const& uniform = m_program->getActiveUniform( it->first ); setProgramUniform( uniform.type, programID, uniform.location, it->second ); } for ( size_t i=0 ; i<m_uniformBuffers.size() ; i++ ) { DP_ASSERT( m_uniformBuffers[i] ); glBindBufferBase( GL_UNIFORM_BUFFER, m_program->getActiveUniformBlocks()[i].binding, m_uniformBuffers[i]->getGLId() ); } }
inline void setProgramUniformSampler(GLSLProgramId aProgramId, GLSLUniformLocation aSamplerLocation, int aSampler) { setProgramUniform(aProgramId, aSamplerLocation, aSampler); }
void CD3DCG::setShaderVars(int pass) { D3DXVECTOR2 inputSize = shaderPasses[pass-1].outputSize; D3DXVECTOR2 textureSize = shaderPasses[pass-1].textureSize; D3DXVECTOR2 outputSize = shaderPasses[pass].outputSize; /* mvp paramater */ CGparameter cgpModelViewProj = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, "modelViewProj"); if(cgpModelViewProj) cgD3D9SetUniformMatrix(cgpModelViewProj,&mvp); #define setProgramUniform(pass,varname,floats)\ {\ CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\ CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\ if(cgpf)\ cgD3D9SetUniform(cgpf,floats);\ if(cgpv)\ cgD3D9SetUniform(cgpv,floats);\ }\ #define setTextureParameter(pass,varname,val,linear)\ {\ CGparameter cgpf = cgGetNamedParameter(shaderPasses[pass].cgFragmentProgram, varname);\ if(cgpf) {\ cgD3D9SetTexture(cgpf,val);\ cgD3D9SetSamplerState(cgpf, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);\ cgD3D9SetSamplerState(cgpf, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);\ cgD3D9SetSamplerState(cgpf, D3DSAMP_MINFILTER, linear?D3DTEXF_LINEAR:D3DTEXF_POINT);\ cgD3D9SetSamplerState(cgpf, D3DSAMP_MAGFILTER, linear?D3DTEXF_LINEAR:D3DTEXF_POINT);\ }\ }\ #define setTexCoordsParameter(pass,varname,val)\ {\ CGparameter cgpv = cgGetNamedParameter(shaderPasses[pass].cgVertexProgram, varname);\ if(cgpv) {\ unsigned long index = cgGetParameterResourceIndex(cgpv);\ pDevice->SetStreamSource(shaderPasses[pass].parameterMap[index].streamNumber,val,0,sizeof(VERTEX));\ }\ }\ /* IN paramater */ setProgramUniform(pass,"IN.video_size",&inputSize); setProgramUniform(pass,"IN.texture_size",&textureSize); setProgramUniform(pass,"IN.output_size",&outputSize); setProgramUniform(pass,"IN.frame_count",&frameCnt); float frameDirection = GUI.rewinding?-1.0f:1.0f; setProgramUniform(pass,"IN.frame_direction",&frameDirection); /* ORIG parameter */ setProgramUniform(pass,"ORIG.video_size",shaderPasses[0].outputSize); setProgramUniform(pass,"ORIG.texture_size",shaderPasses[0].textureSize); setTextureParameter(pass,"ORIG.texture",shaderPasses[0].tex,shaderPasses[1].linearFilter); setTexCoordsParameter(pass,"ORIG.tex_coord",shaderPasses[1].vertexBuffer); /* PREV parameter */ if(prevPasses[0].tex) { setProgramUniform(pass,"PREV.video_size",prevPasses[0].imageSize); setProgramUniform(pass,"PREV.texture_size",prevPasses[0].textureSize); setTextureParameter(pass,"PREV.texture",prevPasses[0].tex,shaderPasses[1].linearFilter); setTexCoordsParameter(pass,"PREV.tex_coord",prevPasses[0].vertexBuffer); } /* PREV1-6 parameters */ for(int i=1;i<prevPasses.size();i++) { if(!prevPasses[i].tex) break; char varname[100]; sprintf(varname,"PREV%d.video_size",i); setProgramUniform(pass,varname,prevPasses[i].imageSize); sprintf(varname,"PREV%d.texture_size",i); setProgramUniform(pass,varname,prevPasses[i].textureSize); sprintf(varname,"PREV%d.texture",i); setTextureParameter(pass,varname,prevPasses[i].tex,shaderPasses[1].linearFilter); sprintf(varname,"PREV%d.tex_coord",i); setTexCoordsParameter(pass,varname,prevPasses[i].vertexBuffer); } /* LUT parameters */ for(int i=0;i<lookupTextures.size();i++) { setTextureParameter(pass,lookupTextures[i].id,lookupTextures[i].tex,lookupTextures[i].linearFilter); } /* PASSX parameters, only for third pass and up */ if(pass>2) { for(int i=1;i<pass-1;i++) { char varname[100]; sprintf(varname,"PASS%d.video_size",i); setProgramUniform(pass,varname,shaderPasses[i].outputSize); sprintf(varname,"PASS%d.texture_size",i); setProgramUniform(pass,varname,shaderPasses[i].textureSize); sprintf(varname,"PASS%d.texture",i); setTextureParameter(pass,varname,shaderPasses[i].tex,shaderPasses[i+1].linearFilter); sprintf(varname,"PASS%d.tex_coord",i); setTexCoordsParameter(pass,varname,shaderPasses[i+1].vertexBuffer); } } }