File bin/build.sh changed (mode: 100755) (index 2668c04..c9f93aa) |
... |
... |
BASEDIR="${DIR}/../" |
6 |
6 |
|
|
7 |
7 |
echo '# verify' |
echo '# verify' |
8 |
8 |
glslangValidator "${BASEDIR}conf/glslangValidator.conf" \ |
glslangValidator "${BASEDIR}conf/glslangValidator.conf" \ |
9 |
|
"${BASEDIR}share/glslang/org.jgltut.tutaa/ShaderRendererAA.vert" \ |
|
10 |
|
"${BASEDIR}share/glslang/org.jgltut.tutaa/ShaderRendererAA.frag" |
|
|
9 |
|
"${BASEDIR}share/glslang/org.jgltut.tutaa/org/jgltut/tutaa/ShaderRendererAA.vert" \ |
|
10 |
|
"${BASEDIR}share/glslang/org.jgltut.tutaa/org/jgltut/tutaa/ShaderRendererAA.frag" |
11 |
11 |
|
|
12 |
12 |
echo '# compile' |
echo '# compile' |
13 |
13 |
mkdir -p "${BASEDIR}share/classes/" |
mkdir -p "${BASEDIR}share/classes/" |
File src/org.jgltut.tutaa/src/org/jgltut/tutaa/RendererAA.java changed (mode: 100644) (index 83071d7..be9e130) |
... |
... |
final class RendererAA extends Renderer |
77 |
77 |
|
|
78 |
78 |
|
|
79 |
79 |
final var spb = new ShaderProgramBuilder(); |
final var spb = new ShaderProgramBuilder(); |
80 |
|
spb.setShaderFragSrc(SHADER_FRAG); |
|
81 |
|
spb.setShaderVertSrc(SHADER_VERT); |
|
|
80 |
|
final var sr = new ShaderReader(); |
|
81 |
|
final String shaderFragSrc = sr.<RendererAA>apply(RendererAA.class, ShaderType.FRAG); |
|
82 |
|
spb.setShaderFragSrc(shaderFragSrc); |
|
83 |
|
final String shaderVertSrc = sr.<RendererAA>apply(RendererAA.class, ShaderType.VERT); |
|
84 |
|
spb.setShaderVertSrc(shaderVertSrc); |
82 |
85 |
final var sp = spb.get(); |
final var sp = spb.get(); |
83 |
86 |
final var renderer = new RendererAA( |
final var renderer = new RendererAA( |
84 |
87 |
floatBuffer, stack, bufferHandle, sp, vao); |
floatBuffer, stack, bufferHandle, sp, vao); |
|
... |
... |
final class RendererAA extends Renderer |
90 |
93 |
} |
} |
91 |
94 |
} |
} |
92 |
95 |
|
|
93 |
|
private final static String SHADER_VERT = |
|
94 |
|
"#version 330 core\n" + |
|
95 |
|
"layout(location = 0) in vec4 position;\n" + |
|
96 |
|
"void main()\n" + |
|
97 |
|
"{\n" + |
|
98 |
|
" gl_Position = position;\n" + |
|
99 |
|
"}\n"; |
|
100 |
|
|
|
101 |
|
private final static String SHADER_FRAG = |
|
102 |
|
"#version 330 core\n" + |
|
103 |
|
"out vec4 outputColor;\n" + |
|
104 |
|
"void main()\n" + |
|
105 |
|
"{\n" + |
|
106 |
|
" outputColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);\n" + |
|
107 |
|
"}\n"; |
|
108 |
|
|
|
109 |
96 |
private final FloatBuffer floatBuffer; |
private final FloatBuffer floatBuffer; |
110 |
97 |
private final MemoryStack memoryStack; |
private final MemoryStack memoryStack; |
111 |
98 |
private final ShaderProgram program; |
private final ShaderProgram program; |
File src/org.jgltut.tutaa/src/org/jgltut/tutaa/ShaderReader.java changed (mode: 100644) (index 505ffa4..04c6671) |
... |
... |
final class ShaderReader |
13 |
13 |
{ |
{ |
14 |
14 |
} |
} |
15 |
15 |
|
|
|
16 |
|
/** |
|
17 |
|
* Read shader source file into string object. |
|
18 |
|
* |
|
19 |
|
* Shader source file must be placed in the same package |
|
20 |
|
* as renderer class definition that intends to use it. |
|
21 |
|
*/ |
16 |
22 |
public final <T> String apply(final Class<T> rendererType, |
public final <T> String apply(final Class<T> rendererType, |
17 |
23 |
final ShaderType shaderType) |
final ShaderType shaderType) |
18 |
24 |
throws IllegalArgumentException, IllegalStateException |
throws IllegalArgumentException, IllegalStateException |
|
... |
... |
final class ShaderReader |
25 |
31 |
throw new IllegalArgumentException("empty argument"); |
throw new IllegalArgumentException("empty argument"); |
26 |
32 |
} |
} |
27 |
33 |
|
|
28 |
|
final String resourceName = "Shader" + |
|
29 |
|
rendererType.getSimpleName() + "." + |
|
30 |
|
shaderType.getFileExtension(); |
|
|
34 |
|
final String n = "Shader" + rendererType.getSimpleName() + "." + |
|
35 |
|
shaderType.getFileExtension(); |
|
36 |
|
final String resourceName = |
|
37 |
|
n.substring(0, Math.min(n.length(), 256)); |
|
38 |
|
|
31 |
39 |
final int capacity = 2048; |
final int capacity = 2048; |
32 |
40 |
final String resourceContent; |
final String resourceContent; |
33 |
41 |
try (final InputStream stream = |
try (final InputStream stream = |
34 |
42 |
rendererType.getResourceAsStream(resourceName)) { |
rendererType.getResourceAsStream(resourceName)) { |
|
43 |
|
if (null == stream) { |
|
44 |
|
throw new IllegalStateException( |
|
45 |
|
"could not find resource " + |
|
46 |
|
resourceName); |
|
47 |
|
} |
35 |
48 |
/* Use ByteBuffer#allocate specifically |
/* Use ByteBuffer#allocate specifically |
36 |
49 |
* to ensure backing array is available. */ |
* to ensure backing array is available. */ |
37 |
50 |
final ByteBuffer buffer = ByteBuffer.allocate(capacity); |
final ByteBuffer buffer = ByteBuffer.allocate(capacity); |
|
... |
... |
final class ShaderReader |
53 |
66 |
buffer.arrayOffset(), a); |
buffer.arrayOffset(), a); |
54 |
67 |
a = stream.available(); |
a = stream.available(); |
55 |
68 |
} |
} |
|
69 |
|
buffer.flip(); |
56 |
70 |
buffer.compact(); |
buffer.compact(); |
57 |
71 |
|
|
58 |
72 |
final String charsetName = |
final String charsetName = |