Java 类org.lwjgl.opencl.CLProgram 实例源码

项目:libgdx-opencl    文件:ShaderLoader.java   
/**
 * Loads a CL Shader.
 * It will load the files from the assets folder.
 * Structure should be like:
 * 
 * clshaders/[SHADERNAME]/shader.cl
 * 
 * This function handles include-preprocessing, so you can use #include "test.cl".
 * It will replace all includes with the contents of the given filename.
 * Important! When using like #include "/test.cl" it will search the file assets/test.cl in the internal storage.
 * If you use it like #include "test.cl" in a shader called test it will search in assets/shaders/test/test.cl.
 * 
 * @param shaderName
 * @return Null if the shader was not found
 */
public static CLProgram loadCLShader(String shaderName, CLContext clContext)
{
    String shaderPath = "clshaders/"+shaderName+"/";

    // Check if shader exists
    if (!Gdx.files.internal(shaderPath+"shader.cl").exists())
        return null;

    // Preprocessing
    String shaderCode = ShaderLoader.preprocessShader(Gdx.files.internal(shaderPath+"shader.cl").readString(), shaderPath);

    return JLibOpenCL.compileProgram(shaderCode, clContext);
}