1package com.jogamp.opengl.util.glsl.sdk;
3import com.jogamp.common.util.IOUtil;
5import com.jogamp.opengl.*;
6import com.jogamp.opengl.util.glsl.*;
34 throws IOException, UnsupportedEncodingException, InterruptedException
42 }
else if(resourceName.endsWith(
".frag")) {
48 }
else if(resourceName.endsWith(
".vert")) {
52 final String justName =
basename(resourceName);
53 outName = justName.substring(0, justName.length() - suffixLen) +
55 final URL resourceURL = IOUtil.getResource(resourceName, this.getClass().getClassLoader(),
null).getURL();
56 final String dirName =
dirname(resourceURL.getPath());
58 outName = dirName + File.separator +
"bin" + File.separator +
64 public void processOneShader(
final String resourceName,
final String outName,
final int type)
65 throws IOException, UnsupportedEncodingException, InterruptedException
67 final URL resourceURL = IOUtil.getResource(resourceName, this.getClass().getClassLoader(),
null).getURL();
68 final String dirName =
dirname(resourceURL.getPath());
70 final CharSequence shader =
ShaderCode.readShaderSource(
null, resourceName,
false);
72 System.err.println(
"Can't find shader source " + resourceName +
" - ignored");
75 System.err.println(
"Preprocessing: "+ resourceName+
", in dir: "+dirName);
76 final String justName =
basename(resourceName);
86 throw new GLException(
"Unknown shader type: "+type);
88 final File outputFile =
new File(outName);
91 final File tmpDir =
new File(dirName+File.separator+
"tmp");
93 final File tmpFile =
new File(tmpDir, justName);
94 final Writer writer =
new BufferedWriter(
new FileWriter(tmpFile));
95 writer.write(shader.toString(), 0, shader.length());
98 System.err.println(
"Preprocessed: "+ tmpFile.getAbsolutePath());
102 System.err.println(
"SDK: "+ processorDir.getAbsolutePath() +
", compiler: "+processor);
104 System.err.println(
"Output: "+ outputFile.getAbsolutePath());
107 final Process process = Runtime.getRuntime().exec(
new String[] {
108 processorDir.getAbsolutePath() + File.separator + processor,
109 tmpFile.getAbsolutePath(),
110 outputFile.getAbsolutePath()
112 new IOUtil.StreamMonitor(
new InputStream[] { process.getInputStream(), process.getErrorStream() }, System.out, null );
118 protected static String
basename(
final String path) {
119 int lastSlash = path.lastIndexOf(
"/");
121 lastSlash = path.lastIndexOf(
"\\");
127 basename = path.substring(lastSlash + 1);
132 protected static String
dirname(
final String path) {
133 int lastSlash = path.lastIndexOf(
"/");
135 lastSlash = path.lastIndexOf(
"\\");
141 dirname = path.substring(0, lastSlash + 1);
146 public void run(
final String[] args) {
148 for (
int i = 0; i < args.length; i++) {
151 }
catch (
final Exception e) {
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Convenient shader code class to use and instantiate vertex or fragment programs.
static String getFileSuffix(final boolean binary, final int type)
Returns a unique suffix for shader resources as follows:
static String getBinarySubPath(final int binFormat)
Returns a unique relative path for binary shader resources as follows:
Precompiles a shader into a vendor binary format.
static String dirname(final String path)
void processOneShader(final String resourceName)
abstract File getSDKCompilerDir()
void run(final String[] args)
void processOneShader(final String resourceName, final String outName, final int type)
static String basename(final String path)
abstract String getVertexShaderCompiler()
abstract int getBinaryFormat()
abstract String getFragmentShaderCompiler()
static final int GL_VERTEX_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_EXT_vertex_shader, GL_ARB_vertex_shader Alias for: GL_VERTEX_SH...
static final int GL_FRAGMENT_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ATI_fragment_shader, GL_ARB_fragment_shader Alias for: GL_FRAGM...