Skip to content

Commit 1ba6063

Browse files
committed
minor
1 parent 80a2061 commit 1ba6063

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

src/main/java/cleargl/ClearGLWindow.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ public void close() throws GLException {
196196
try {
197197

198198
try {
199-
mAnimator.stop();
199+
runOnEDT(false, () -> {
200+
mAnimator.stop();
201+
});
202+
200203
} catch (final Throwable e) {
201204
System.err.println(e.getLocalizedMessage());
202205
}

src/main/java/cleargl/GLFramebuffer.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.LinkedHashMap;
55
import java.util.List;
66
import java.util.Map;
7-
87
import com.jogamp.opengl.GL4;
98

109
/**
@@ -46,7 +45,8 @@ public boolean hasColorAttachment() {
4645
return backingTextures.size() > 0;
4746
}
4847

49-
private void addFloatBufferInternal(final GL4 gl, final String name, final int channelCount, final int channelDepth) {
48+
private void addFloatBufferInternal(final GL4 gl, final String name, final int channelCount,
49+
final int channelDepth) {
5050
if (!initialized) {
5151
return;
5252
}
@@ -76,14 +76,15 @@ public void addFloatRGBuffer(final GL4 gl, final String name, final int channelD
7676
}
7777

7878
public void addFloatRGBBuffer(final GL4 gl, final String name, final int channelDepth) {
79-
addFloatBufferInternal(gl, name, 3, channelDepth);
79+
addFloatBufferInternal(gl, name, 3, channelDepth);
8080
}
8181

8282
public void addFloatRGBABuffer(final GL4 gl, final String name, final int channelDepth) {
83-
addFloatBufferInternal(gl, name, 4, channelDepth);
83+
addFloatBufferInternal(gl, name, 4, channelDepth);
8484
}
8585

86-
private void addUnsignedByteBufferInternal(final GL4 gl, final String name, final int channelCount, final int channelDepth) {
86+
private void addUnsignedByteBufferInternal(final GL4 gl, final String name, final int channelCount,
87+
final int channelDepth) {
8788
if (!initialized) {
8889
return;
8990
}
@@ -105,9 +106,9 @@ private void addUnsignedByteBufferInternal(final GL4 gl, final String name, fina
105106
}
106107

107108

108-
public void addUnsignedByteRBuffer(final GL4 gl, final String name, final int channelDepth) {
109-
addUnsignedByteBufferInternal(gl, name, 1, channelDepth);
110-
}
109+
public void addUnsignedByteRBuffer(final GL4 gl, final String name, final int channelDepth) {
110+
addUnsignedByteBufferInternal(gl, name, 1, channelDepth);
111+
}
111112

112113
public void addUnsignedByteRGBuffer(final GL4 gl, final String name, final int channelDepth) {
113114
addUnsignedByteBufferInternal(gl, name, 2, channelDepth);
@@ -118,7 +119,7 @@ public void addUnsignedByteRGBBuffer(final GL4 gl, final String name, final int
118119
}
119120

120121
public void addUnsignedByteRGBABuffer(final GL4 gl, final String name, final int channelDepth) {
121-
addUnsignedByteBufferInternal(gl, name, 4, channelDepth);
122+
addUnsignedByteBufferInternal(gl, name, 4, channelDepth);
122123
}
123124

124125
public void addDepthBuffer(final GL4 gl, final String name, final int depth) {
@@ -179,13 +180,13 @@ public void setReadBuffers(final GL4 gl) {
179180
public int bindTexturesToUnitsWithOffset(final GL4 gl, final int offset) {
180181
int totalUnits = 0;
181182

182-
for(Map.Entry<String, GLTexture> entry: backingTextures.entrySet()) {
183+
for (Map.Entry<String, GLTexture> entry : backingTextures.entrySet()) {
183184
gl.glActiveTexture(GL4.GL_TEXTURE0 + offset + totalUnits);
184185
gl.glBindTexture(GL4.GL_TEXTURE_2D, entry.getValue().getId());
185186
totalUnits++;
186187
}
187188

188-
for(Map.Entry<String, GLTexture> entry: depthBuffers.entrySet()) {
189+
for (Map.Entry<String, GLTexture> entry : depthBuffers.entrySet()) {
189190
gl.glActiveTexture(GL4.GL_TEXTURE0 + offset + totalUnits);
190191
gl.glBindTexture(GL4.GL_TEXTURE_2D, entry.getValue().getId());
191192
totalUnits++;
@@ -197,7 +198,7 @@ public int bindTexturesToUnitsWithOffset(final GL4 gl, final int offset) {
197198
public List<Integer> getTextureIds(final GL4 gl) {
198199
final ArrayList<Integer> list = new ArrayList<>();
199200

200-
for (Map.Entry<String, GLTexture> entry: backingTextures.entrySet()) {
201+
for (Map.Entry<String, GLTexture> entry : backingTextures.entrySet()) {
201202
list.add(entry.getValue().getId());
202203
}
203204

@@ -218,7 +219,7 @@ public void resize(final GL4 gl, final int newWidth, final int newHeight) {
218219
final LinkedHashMap<String, GLTexture> newBackingTextures = new LinkedHashMap<>();
219220
final LinkedHashMap<String, GLTexture> newDepthBuffers = new LinkedHashMap<>();
220221

221-
for (Map.Entry<String, GLTexture> entry: backingTextures.entrySet()) {
222+
for (Map.Entry<String, GLTexture> entry : backingTextures.entrySet()) {
222223
final GLTexture newT = new GLTexture(gl,
223224
entry.getValue().getNativeType(),
224225
entry.getValue().getChannels(),
@@ -235,7 +236,7 @@ public void resize(final GL4 gl, final int newWidth, final int newHeight) {
235236
0);
236237
}
237238

238-
for (Map.Entry<String, GLTexture> entry: depthBuffers.entrySet()) {
239+
for (Map.Entry<String, GLTexture> entry : depthBuffers.entrySet()) {
239240
final GLTexture newT = new GLTexture(gl,
240241
entry.getValue().getNativeType(),
241242
-1,
@@ -289,17 +290,19 @@ public String toString() {
289290
info = new StringBuilder("GLFramebuffer " + framebufferId[0] + "\n|\n");
290291

291292
for (final GLTexture att : backingTextures.values()) {
292-
info.append(String.format("+-\tColor Attachment %s, %dx%d/%d*%d, 0x%s\n", Integer.toHexString(att.getId()),
293-
att.getWidth(), att.getHeight(), att.getChannels(), att.getBitsPerChannel(),
294-
Integer.toHexString(att.getInternalFormat())));
293+
info.append(
294+
String.format("+-\tColor Attachment %s, %dx%d/%d*%d, 0x%s\n", Integer.toHexString(att.getId()),
295+
att.getWidth(), att.getHeight(), att.getChannels(), att.getBitsPerChannel(),
296+
Integer.toHexString(att.getInternalFormat())));
295297
}
296298

297299
info.append("|\n");
298300

299301
for (final GLTexture att : depthBuffers.values()) {
300-
info.append(String.format("+-\tDepth Attachment %s, %dx%d/%d*%d, 0x%s\n", Integer.toHexString(att.getId()),
301-
att.getWidth(), att.getHeight(), att.getChannels(), att.getBitsPerChannel(),
302-
Integer.toHexString(att.getInternalFormat())));
302+
info.append(
303+
String.format("+-\tDepth Attachment %s, %dx%d/%d*%d, 0x%s\n", Integer.toHexString(att.getId()),
304+
att.getWidth(), att.getHeight(), att.getChannels(), att.getBitsPerChannel(),
305+
Integer.toHexString(att.getInternalFormat())));
303306
}
304307
}
305308
return info.toString();

src/main/java/cleargl/GLTexture.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,31 @@ public GLTexture(final GL4 pGL,
132132

133133
mTextureTarget = mTextureDepth == 1 ? GL4.GL_TEXTURE_2D
134134
: GL4.GL_TEXTURE_3D;
135-
switch(mNumberOfChannels) {
135+
switch (mNumberOfChannels) {
136136
case 1:
137-
if(mType == GLTypeEnum.UnsignedShort) {
137+
if (mType == GLTypeEnum.UnsignedShort) {
138138
mTextureOpenGLFormat = GL4.GL_RED_INTEGER;
139139
} else {
140140
mTextureOpenGLFormat = GL4.GL_RED;
141141
}
142142
break;
143143
case 2:
144-
if(mType == GLTypeEnum.UnsignedShort) {
144+
if (mType == GLTypeEnum.UnsignedShort) {
145145
mTextureOpenGLFormat = GL4.GL_RG_INTEGER;
146146
} else {
147147
mTextureOpenGLFormat = GL4.GL_RG;
148148
}
149149
break;
150150
case 3:
151-
if(mType == GLTypeEnum.UnsignedShort) {
151+
if (mType == GLTypeEnum.UnsignedShort) {
152152
mTextureOpenGLFormat = GL4.GL_RGB_INTEGER;
153153
} else {
154154
mTextureOpenGLFormat = GL4.GL_RGB;
155155
}
156156
break;
157157
case 4:
158158
default:
159-
if(mType == GLTypeEnum.UnsignedShort) {
159+
if (mType == GLTypeEnum.UnsignedShort) {
160160
mTextureOpenGLFormat = GL4.GL_RGBA_INTEGER;
161161
} else {
162162
mTextureOpenGLFormat = GL4.GL_RGBA;
@@ -205,7 +205,7 @@ public GLTexture(final GL4 pGL,
205205
: GL4.GL_R16F;
206206
mBytesPerChannel = 2;
207207
} else if (mType == GLTypeEnum.UnsignedShort) {
208-
switch(mNumberOfChannels) {
208+
switch (mNumberOfChannels) {
209209
case 1:
210210
mTextureOpenGLInternalFormat = GL4.GL_R16UI;
211211
break;
@@ -226,7 +226,7 @@ public GLTexture(final GL4 pGL,
226226
: GL4.GL_R32F;
227227
mBytesPerChannel = 4;
228228
} else if (mType == GLTypeEnum.UnsignedInt) {
229-
switch(mNumberOfChannels) {
229+
switch (mNumberOfChannels) {
230230
case 1:
231231
mTextureOpenGLInternalFormat = GL4.GL_R32UI;
232232
break;
@@ -249,10 +249,10 @@ public GLTexture(final GL4 pGL,
249249
mBytesPerChannel = 4;
250250
break;
251251
case 2:
252-
if(precision == 16) {
252+
if (precision == 16) {
253253
mTextureOpenGLInternalFormat = GL4.GL_RG16F;
254254
mBytesPerChannel = 4;
255-
} else if(precision == 32) {
255+
} else if (precision == 32) {
256256
mTextureOpenGLInternalFormat = GL4.GL_RG32F;
257257
mBytesPerChannel = 4;
258258
}
@@ -290,7 +290,7 @@ public GLTexture(final GL4 pGL,
290290
mGL.glGenTextures(1, mTextureId, 0);
291291
bind();
292292

293-
if(mTextureTarget == GL4.GL_TEXTURE_2D) {
293+
if (mTextureTarget == GL4.GL_TEXTURE_2D) {
294294
mGL.glTexParameteri(mTextureTarget,
295295
GL4.GL_TEXTURE_MAG_FILTER,
296296
pLinearInterpolation ? GL4.GL_LINEAR
@@ -300,7 +300,7 @@ public GLTexture(final GL4 pGL,
300300
mMipMapLevels > 1 ? (pLinearInterpolation ? GL4.GL_LINEAR_MIPMAP_LINEAR
301301
: GL4.GL_NEAREST_MIPMAP_NEAREST)
302302
: (pLinearInterpolation ? GL4.GL_LINEAR
303-
: GL4.GL_NEAREST));
303+
: GL4.GL_NEAREST));
304304
mGL.glTexParameteri(mTextureTarget,
305305
GL4.GL_TEXTURE_WRAP_S,
306306
GL4.GL_REPEAT);
@@ -404,15 +404,15 @@ public void clear() {
404404
bind();
405405

406406
final int lNeededSize = mTextureWidth * mTextureHeight
407-
* mTextureDepth
407+
* mTextureDepth
408408
* mBytesPerChannel
409409
* mNumberOfChannels;
410410

411411
// empty buffer
412412
final Buffer lEmptyBuffer = ByteBuffer.allocateDirect(lNeededSize)
413413
.order(ByteOrder.nativeOrder());
414414

415-
if(mTextureTarget == GL4.GL_TEXTURE_2D) {
415+
if (mTextureTarget == GL4.GL_TEXTURE_2D) {
416416
mGL.glTexSubImage2D(mTextureTarget,
417417
0,
418418
0,
@@ -468,7 +468,7 @@ public void copyFrom(final Buffer pBuffer,
468468
bind();
469469
pBuffer.rewind();
470470

471-
if(mTextureTarget == GL4.GL_TEXTURE_2D) {
471+
if (mTextureTarget == GL4.GL_TEXTURE_2D) {
472472
mGL.glTexSubImage2D(mTextureTarget,
473473
pLODLevel,
474474
0,
@@ -580,7 +580,7 @@ public void dumpToFile(final ByteBuffer buf) {
580580
}
581581

582582
public static GLTexture loadFromFile(final GL4 gl, final String filename, final boolean linearInterpolation,
583-
final int mipmapLevels) {
583+
final int mipmapLevels) {
584584
return loadFromFile(gl, filename, linearInterpolation, true, mipmapLevels);
585585
}
586586

@@ -642,16 +642,17 @@ public static GLTexture loadFromFile(final GL4 gl, final String filename, final
642642
texHeight *= 2;
643643
}
644644

645-
int levels = Math.min(maxMipmapLevels, 1 + (int)Math.floor(Math.log(Math.max(texWidth, texHeight)/Math.log(2.0))));
645+
int levels = Math.min(maxMipmapLevels,
646+
1 + (int) Math.floor(Math.log(Math.max(texWidth, texHeight) / Math.log(2.0))));
646647

647-
if(!generateMipmaps) {
648+
if (!generateMipmaps) {
648649
levels = 1;
649650
}
650651

651652
int channelCount = bi.getColorModel().getNumComponents();
652653

653654
// work around a Java2D issue
654-
if(channelCount == 3 && filename.substring(filename.lastIndexOf(".")).toLowerCase().endsWith("png")) {
655+
if (channelCount == 3 && filename.substring(filename.lastIndexOf(".")).toLowerCase().endsWith("png")) {
655656
channelCount = 4;
656657
}
657658

0 commit comments

Comments
 (0)