bool GLComputeEvaluator::_PatchKernel::Compile(BufferDescriptor const &srcDesc, BufferDescriptor const &dstDesc, BufferDescriptor const &duDesc, BufferDescriptor const &dvDesc, int workGroupSize) { // create stencil kernel if (program) { glDeleteProgram(program); } bool derivatives = (duDesc.length > 0 || dvDesc.length > 0); const char *kernelDef = derivatives ? "#define OPENSUBDIV_GLSL_COMPUTE_KERNEL_EVAL_PATCHES\n" "#define OPENSUBDIV_GLSL_COMPUTE_USE_DERIVATIVES\n" : "#define OPENSUBDIV_GLSL_COMPUTE_KERNEL_EVAL_PATCHES\n"; if (program) { glDeleteProgram(program); } program = compileKernel(srcDesc, dstDesc, duDesc, dvDesc, kernelDef, workGroupSize); if (program == 0) return false; // cache uniform locations uniformSrcOffset = glGetUniformLocation(program, "srcOffset"); uniformDstOffset = glGetUniformLocation(program, "dstOffset"); uniformPatchArray = glGetUniformLocation(program, "patchArray"); uniformDuDesc = glGetUniformLocation(program, "duDesc"); uniformDvDesc = glGetUniformLocation(program, "dvDesc"); return true; }
VolumeRaycasterCL::VolumeRaycasterCL() : KernelOwner() , workGroupSize_(size2_t(8, 8)) , useGLSharing_(true) , outputOffset_(0) , outputSize_(1) , camera_(nullptr) , samplingRate_(2.f) , background_(nullptr) , defaultBackground_(uvec2(1), DataVec4UInt8::get()) , lightStruct_(sizeof(utilcl::LightParameters), DataUInt8::get(), BufferUsage::STATIC, nullptr, CL_MEM_READ_ONLY) , kernel_(nullptr) { light_.ambientColor = vec4(1.f); light_.diffuseColor = vec4(1.f); light_.specularColor = vec4(1.f); light_.specularExponent = 110.f; light_.position = vec4(0.7f); light_.shadingMode = ShadingMode::Phong; compileKernel(); }
void VolumeRaycasterCL::setLightingProperties(ShadingMode::Modes mode, const vec3& lightPosition, const vec3& ambientColor, const vec3& diffuseColor, const vec3& specularColor, float specularExponent) { light_.position = vec4(lightPosition, 1.f); light_.ambientColor = vec4(ambientColor, 1.f); light_.diffuseColor = vec4(diffuseColor, 1.f); light_.specularColor = vec4(specularColor, 1.f); light_.specularExponent = specularExponent; if (mode != light_.shadingMode) { light_.shadingMode = mode; compileKernel(); } if (kernel_) { try { // Update data before returning it lightStruct_.upload(&light_, sizeof(utilcl::LightParameters)); kernel_->setArg(8, lightStruct_); } catch (cl::Error& err) { LogError(getCLErrorString(err)); } } }