11package cleargl ;
22
3- import java .nio .IntBuffer ;
43import java .util .ArrayList ;
54import java .util .LinkedHashMap ;
65import java .util .List ;
76import java .util .Map ;
87
9- import com .jogamp .opengl .GL ;
108import com .jogamp .opengl .GL4 ;
119
1210/**
@@ -53,20 +51,20 @@ private void addFloatBufferInternal(final GL4 gl, final String name, final int c
5351 return ;
5452 }
5553
56- gl .getGL ().glBindFramebuffer (GL .GL_FRAMEBUFFER , getId ());
54+ gl .getGL ().glBindFramebuffer (GL4 .GL_FRAMEBUFFER , getId ());
5755
5856 backingTextures .put (name , new GLTexture (
5957 gl ,
6058 GLTypeEnum .Float ,
6159 channelCount ,
6260 width , height , 1 , true , 1 , channelDepth ));
6361
64- gl .getGL (). getGL4 (). glFramebufferTexture (GL .GL_FRAMEBUFFER ,
62+ gl .glFramebufferTexture (GL4 .GL_FRAMEBUFFER ,
6563 getCurrentFramebufferColorAttachment (),
6664 backingTextures .get (name ).getId (),
6765 0 );
6866
69- gl .getGL ().glBindFramebuffer (GL .GL_FRAMEBUFFER , 0 );
67+ gl .getGL ().glBindFramebuffer (GL4 .GL_FRAMEBUFFER , 0 );
7068 }
7169
7270 public void addFloatRBuffer (final GL4 gl , final String name , final int channelDepth ) {
@@ -90,20 +88,20 @@ private void addUnsignedByteBufferInternal(final GL4 gl, final String name, fina
9088 return ;
9189 }
9290
93- gl .getGL ().glBindFramebuffer (GL .GL_FRAMEBUFFER , getId ());
91+ gl .getGL ().glBindFramebuffer (GL4 .GL_FRAMEBUFFER , getId ());
9492
9593 backingTextures .put (name , new GLTexture (
9694 gl ,
9795 GLTypeEnum .UnsignedByte ,
9896 channelCount ,
9997 width , height , 1 , true , 1 , channelDepth ));
10098
101- gl .getGL (). getGL4 (). glFramebufferTexture (GL .GL_FRAMEBUFFER ,
99+ gl .glFramebufferTexture (GL4 .GL_FRAMEBUFFER ,
102100 getCurrentFramebufferColorAttachment (),
103101 backingTextures .get (name ).getId (),
104102 0 );
105103
106- gl .getGL ().glBindFramebuffer (GL .GL_FRAMEBUFFER , 0 );
104+ gl .getGL ().glBindFramebuffer (GL4 .GL_FRAMEBUFFER , 0 );
107105 }
108106
109107
@@ -132,31 +130,31 @@ public void addDepthBuffer(final GL4 gl, final String name, final int depth, fin
132130 return ;
133131 }
134132
135- gl .getGL ().glBindFramebuffer (GL .GL_FRAMEBUFFER , getId ());
133+ gl .getGL ().glBindFramebuffer (GL4 .GL_FRAMEBUFFER , getId ());
136134
137135 depthBuffers .put (name , new GLTexture (
138136 gl ,
139137 GLTypeEnum .Float ,
140138 -1 ,
141139 width / scale , height / scale , 1 , true , 1 , depth ));
142140
143- gl .getGL (). getGL4 (). glFramebufferTexture (GL .GL_FRAMEBUFFER ,
144- GL .GL_DEPTH_ATTACHMENT ,
141+ gl .glFramebufferTexture (GL4 .GL_FRAMEBUFFER ,
142+ GL4 .GL_DEPTH_ATTACHMENT ,
145143 depthBuffers .get (name ).getId (),
146144 0 );
147145
148- gl .getGL ().glBindFramebuffer (GL .GL_FRAMEBUFFER , 0 );
146+ gl .getGL ().glBindFramebuffer (GL4 .GL_FRAMEBUFFER , 0 );
149147 }
150148
151149 public boolean checkDrawBuffers (final GL4 gl ) {
152150 if (!initialized ) {
153151 return false ;
154152 }
155153
156- gl .getGL4 ().glBindFramebuffer (GL .GL_FRAMEBUFFER , getId ());
157- final int status = gl .getGL (). getGL4 (). glCheckFramebufferStatus (GL .GL_FRAMEBUFFER );
154+ gl .getGL4 ().glBindFramebuffer (GL4 .GL_FRAMEBUFFER , getId ());
155+ final int status = gl .glCheckFramebufferStatus (GL4 .GL_FRAMEBUFFER );
158156
159- if (status != GL .GL_FRAMEBUFFER_COMPLETE ) {
157+ if (status != GL4 .GL_FRAMEBUFFER_COMPLETE ) {
160158 System .err .println ("Framebuffer " + framebufferId [0 ] + " is incomplete, " + Integer .toHexString (status ));
161159 return false ;
162160 }
@@ -167,29 +165,29 @@ public boolean checkDrawBuffers(final GL4 gl) {
167165 public void setDrawBuffers (final GL4 gl ) {
168166 final int attachments [] = new int [backingTextures .size ()];
169167 for (int i = 0 ; i < backingTextures .size (); i ++) {
170- attachments [i ] = GL .GL_COLOR_ATTACHMENT0 + i ;
168+ attachments [i ] = GL4 .GL_COLOR_ATTACHMENT0 + i ;
171169 }
172170
173- gl .getGL (). getGL4 (). glBindFramebuffer (GL .GL_DRAW_FRAMEBUFFER , getId ());
174- gl .getGL (). getGL4 (). glDrawBuffers (backingTextures .size (), IntBuffer . wrap ( attachments ) );
171+ gl .glBindFramebuffer (GL4 .GL_DRAW_FRAMEBUFFER , getId ());
172+ gl .glDrawBuffers (backingTextures .size (), attachments , 0 );
175173 }
176174
177175 public void setReadBuffers (final GL4 gl ) {
178- gl .getGL (). getGL4 (). glBindFramebuffer (GL .GL_READ_FRAMEBUFFER , getId ());
176+ gl .glBindFramebuffer (GL4 .GL_READ_FRAMEBUFFER , getId ());
179177 }
180178
181179 public int bindTexturesToUnitsWithOffset (final GL4 gl , final int offset ) {
182180 int totalUnits = 0 ;
183181
184182 for (Map .Entry <String , GLTexture > entry : backingTextures .entrySet ()) {
185- gl .glActiveTexture (GL .GL_TEXTURE0 + offset + totalUnits );
186- gl .glBindTexture (GL .GL_TEXTURE_2D , entry .getValue ().getId ());
183+ gl .glActiveTexture (GL4 .GL_TEXTURE0 + offset + totalUnits );
184+ gl .glBindTexture (GL4 .GL_TEXTURE_2D , entry .getValue ().getId ());
187185 totalUnits ++;
188186 }
189187
190188 for (Map .Entry <String , GLTexture > entry : depthBuffers .entrySet ()) {
191- gl .glActiveTexture (GL .GL_TEXTURE0 + offset + totalUnits );
192- gl .glBindTexture (GL .GL_TEXTURE_2D , entry .getValue ().getId ());
189+ gl .glActiveTexture (GL4 .GL_TEXTURE0 + offset + totalUnits );
190+ gl .glBindTexture (GL4 .GL_TEXTURE_2D , entry .getValue ().getId ());
193191 totalUnits ++;
194192 }
195193
@@ -207,15 +205,15 @@ public List<Integer> getTextureIds(final GL4 gl) {
207205 }
208206
209207 public void revertToDefaultFramebuffer (final GL4 gl ) {
210- gl .glBindFramebuffer (GL .GL_FRAMEBUFFER , 0 );
208+ gl .glBindFramebuffer (GL4 .GL_FRAMEBUFFER , 0 );
211209 }
212210
213211 public void resize (final GL4 gl , final int newWidth , final int newHeight ) {
214212 final int oldIds [] = framebufferId .clone ();
215213
216- gl .glBindFramebuffer (GL .GL_FRAMEBUFFER , 0 );
214+ gl .glBindFramebuffer (GL4 .GL_FRAMEBUFFER , 0 );
217215 gl .glGenFramebuffers (1 , framebufferId , 0 );
218- gl .glBindFramebuffer (GL .GL_FRAMEBUFFER , getId ());
216+ gl .glBindFramebuffer (GL4 .GL_FRAMEBUFFER , getId ());
219217
220218 final LinkedHashMap <String , GLTexture > newBackingTextures = new LinkedHashMap <>();
221219 final LinkedHashMap <String , GLTexture > newDepthBuffers = new LinkedHashMap <>();
@@ -231,7 +229,7 @@ public void resize(final GL4 gl, final int newWidth, final int newHeight) {
231229 newBackingTextures .put (entry .getKey (), newT );
232230 entry .getValue ().close ();
233231
234- gl .getGL (). getGL4 (). glFramebufferTexture (GL .GL_FRAMEBUFFER ,
232+ gl .glFramebufferTexture (GL4 .GL_FRAMEBUFFER ,
235233 getCurrentFramebufferColorAttachment (newBackingTextures .size ()),
236234 newBackingTextures .get (entry .getKey ()).getId (),
237235 0 );
@@ -247,8 +245,8 @@ public void resize(final GL4 gl, final int newWidth, final int newHeight) {
247245 newDepthBuffers .put (entry .getKey (), newT );
248246 entry .getValue ().close ();
249247
250- gl .getGL (). getGL4 (). glFramebufferTexture (GL .GL_FRAMEBUFFER ,
251- GL .GL_DEPTH_ATTACHMENT ,
248+ gl .glFramebufferTexture (GL4 .GL_FRAMEBUFFER ,
249+ GL4 .GL_DEPTH_ATTACHMENT ,
252250 newDepthBuffers .get (entry .getKey ()).getId (),
253251 0 );
254252 }
@@ -263,12 +261,12 @@ public void resize(final GL4 gl, final int newWidth, final int newHeight) {
263261 height = newHeight ;
264262
265263 gl .glDeleteFramebuffers (1 , oldIds , 0 );
266- gl .glBindFramebuffer (GL .GL_FRAMEBUFFER , 0 );
264+ gl .glBindFramebuffer (GL4 .GL_FRAMEBUFFER , 0 );
267265 }
268266
269267 public void destroy (GL4 gl ) {
270268 gl .glDeleteFramebuffers (1 , framebufferId , 0 );
271- gl .glBindFramebuffer (GL .GL_FRAMEBUFFER , 0 );
269+ gl .glBindFramebuffer (GL4 .GL_FRAMEBUFFER , 0 );
272270
273271 for (GLTexture bt : backingTextures .values ()) {
274272 bt .delete ();
@@ -328,10 +326,10 @@ public int getBoundBufferNum() {
328326 }
329327
330328 private int getCurrentFramebufferColorAttachment () {
331- return GL .GL_COLOR_ATTACHMENT0 + backingTextures .size () - 1 ;
329+ return GL4 .GL_COLOR_ATTACHMENT0 + backingTextures .size () - 1 ;
332330 }
333331
334332 private int getCurrentFramebufferColorAttachment (final int base ) {
335- return GL .GL_COLOR_ATTACHMENT0 + base - 1 ;
333+ return GL4 .GL_COLOR_ATTACHMENT0 + base - 1 ;
336334 }
337335}
0 commit comments