vrtc / jgltut (public) (License: GPLv3) (since 2020-10-12) (hash sha1)
Implement [gltut](https://paroj.github.io/gltut/) examples with [LWJGL3](https://www.lwjgl.org/).
List of commits:
Subject Hash Author Date (UTC)
feat: Read shader source from Java resource 9131cd0d7c83773d686e60f07e2a562222b9784b Vladyslav Bondarenko 2020-10-07 23:32:42
feat: Render white triangle on navy background 771bf33b7a05d2f43c30b57c59f0e6e80a4d7070 Vladyslav Bondarenko 2020-10-07 22:57:25
feat!: Improve mock renderer fd45e6ac8a05602140bc30a9153f1e10c4815db1 Vladyslav Bondarenko 2020-10-07 16:29:47
Feat: add mock renderer a9270982088c680cd9b2462fd14ddbc048b314bd Vladyslav Bondarenko 2020-09-26 12:37:55
Initial commit 860d5debdc468cc159f2cbba261e5d8abb0abe38 Vladyslav Bondarenko 2020-09-21 12:45:18
Commit 9131cd0d7c83773d686e60f07e2a562222b9784b - feat: Read shader source from Java resource
Author: Vladyslav Bondarenko
Author date (UTC): 2020-10-07 23:32
Committer name: Vladyslav Bondarenko
Committer date (UTC): 2020-10-07 23:32
Parent(s): 771bf33b7a05d2f43c30b57c59f0e6e80a4d7070
Signer:
Signing key:
Signing status: N
Tree: c496bff29f83737ea5d11b40ec5fab438694b5bc
File Lines added Lines deleted
bin/build.sh 2 2
share/glslang/org.jgltut.tutaa/org/jgltut/tutaa/ShaderRendererAA.frag 0 0
share/glslang/org.jgltut.tutaa/org/jgltut/tutaa/ShaderRendererAA.vert 0 0
src/org.jgltut.tutaa/src/org/jgltut/tutaa/RendererAA.java 5 18
src/org.jgltut.tutaa/src/org/jgltut/tutaa/ShaderReader.java 17 3
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 share/glslang/org.jgltut.tutaa/org/jgltut/tutaa/ShaderRendererAA.frag renamed from share/glslang/org.jgltut.tutaa/ShaderRendererAA.frag (similarity 100%)
File share/glslang/org.jgltut.tutaa/org/jgltut/tutaa/ShaderRendererAA.vert renamed from share/glslang/org.jgltut.tutaa/ShaderRendererAA.vert (similarity 100%)
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 =
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/vrtc/jgltut

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/vrtc/jgltut

Clone this repository using git:
git clone git://git.rocketgit.com/user/vrtc/jgltut

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main