Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Solved] Multiple render passes, different programs, texturing problems  (Read 4078 times)
0 Members and 1 Guest are viewing this topic.
Offline thedanisaur

JGO Knight


Medals: 59



« Posted 2016-04-26 19:09:09 »

I have two different programs, and four different shaders:
3d program -> 3d vertex shader, 3d fragment shader
2d program -> 2d vertex shader, 2d fragment shader

I render using the 3d program first, 2d second. I'm using 4 textures for the 3D scene and 5 for the 2D overlay (3 of the textures are shared). This results in the last texture from the 2d overlay to use the texture at index zero instead. However, if I have the same amount of textures (4 & 4, 3 & 3, etc..) for both passes then the problem looks like it goes away (get the expected results).

Here's the sampler usage in the 2d & 3d programs:

1  
2  
3  
4  
uniform sampler2D diffuse_maps[16];

color += texture(diffuse_maps[int(tex_index)], tex_coord);
}



Note: not sure if it's relevant, but if I add another uniform to the 3d vertex shader openGL throws a 1282: invalid operation error when I try to bind my textures:

1  
2  
3  
4  
5  
6  
7  
8  
   private void bindTextures(GL3 gl)
   {
      for(int i = 0; i < m_textures.size(); i++)
      {
         m_shader.bindTexture(gl, i, m_textures.get(i).m_id);
         m_shader.setUniform1i(gl, "diffuse_maps["+i+"]", i);
      }
   }


bindTexture and setUniform

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
   
   public void bindTexture(GL3 gl, int unit, int id)
   {
      gl.glActiveTexture(GL3.GL_TEXTURE0 + unit);
                //ERROR!!!!!!!!!!!!!!!!!!!! occurs on the line below
      gl.glBindTexture(GL3.GL_TEXTURE_2D, id);//<---ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                //ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   }
   
   public void setUniform1i(GL3 gl, String name, int x)
   {
      gl.glUniform1i(wrapLocation(m_uniforms, name), x);
   }
   
   private Integer wrapLocation(HashMap<String, Integer> map, String name)
   {
      Integer location = map.get(name);
      if(location == null)
      {
         Logger.log(WARNING, "Could not bind shader var: " + name, getName());
         return -1;
      }
      return location;
   }

Every village needs an idiot Cool
Offline ziozio
« Reply #1 - Posted 2016-04-27 05:24:19 »

you should provide the code in m_shader
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #2 - Posted 2016-04-27 06:36:42 »

I don't know what you mean, do you want to see the entire shader class? Maybe I should've been more clear, I have reformatted the first post, the methods called (bindTexture and setUniform) are already there.

Every village needs an idiot Cool
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elect

JGO Knight


Medals: 42



« Reply #3 - Posted 2016-04-27 06:45:57 »

I have two different programs, and four different shaders:
3d program -> 3d vertex shader, 3d fragment shader
2d program -> 2d vertex shader, 2d fragment shader

The number of dimension isn't a valid distinction for shaders, they are not aware of dimensions.

I render using the 3d program first, 2d second. I'm using 4 textures for the 3D scene and 5 for the 2D overlay (3 of the textures are shared). This results in the last texture from the 2d overlay to use the texture at index zero instead. However, if I have the same amount of textures (4 & 4, 3 & 3, etc..) for both passes then the problem looks like it goes away (get the expected results).

Instead of what?

It's not clear if 4 represents the number of texture and the first x textures or not.

Note: not sure if it's relevant, but if I add another uniform to the 3d vertex shader openGL throws a 1282: invalid operation error when I try to bind my textures:

Check exactly on which call you get the error, do something like this

ziozio is right, we need more code
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #4 - Posted 2016-04-27 06:58:17 »

The number of dimension isn't a valid distinction for shaders, they are not aware of dimensions.
I don't understand what you mean here...

I render using the 3d program first, 2d second. I'm using 4 textures for the 3D scene and 5 for the 2D overlay (3 of the textures are shared). This results in the last texture from the 2d overlay to use the texture at index zero instead. However, if I have the same amount of textures (4 & 4, 3 & 3, etc..) for both passes then the problem looks like it goes away (get the expected results).

Instead of what?

It's not clear if 4 represents the number of texture and the first x textures or not.


The textures are generally numbered 1, 6, 7, 8, 9 in openGL. They are bound using glActiveTexture() between 0-4.

Note: not sure if it's relevant, but if I add another uniform to the 3d vertex shader openGL throws a 1282: invalid operation error when I try to bind my textures:

Check exactly on which call you get the error, do something like this

ziozio is right, we need more code


Please have a look at my first post again, I have added more comments so you can see exactly which line the error occurs on. (Note that the error is only thrown if the number of textures being used by both renderers differs in number (quantity), doesn't matter which textures are used or if I share textures between them).


Anyway here's more code:


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
407  
408  
409  
410  
411  
412  
413  
package Roasted.Graphics.Renderer;

import static Roasted.Utilities.Logger.LogLevel.DEBUG;
import static Roasted.Utilities.Logger.LogLevel.ERROR;
import static Roasted.Utilities.Logger.LogLevel.WARNING;

import java.io.File;
import java.io.FileNotFoundException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

import javax.media.opengl.GL3;

import Roasted.Graphics.IGraphicGL;
import Roasted.Utilities.EXIT_CODE;
import Roasted.Utilities.Logger;
import Roasted.Utilities.SStringOperations;

public class Shader implements IGraphicGL
{
   private enum LOC_TYPE
   {
      ATTRIB,
      UNIFORM,
      UNIFORM_BUFFER;
   };
   
   private class ShaderMethod
   {
      @SuppressWarnings("rawtypes")
      private Class[]    m_classes;
      private Object[]    m_params;
      private String       m_method_name;
     
      public ShaderMethod(String method_name, Object[] params, @SuppressWarnings("rawtypes") Class[] classes)
      {
         m_method_name = method_name;
         m_params = params;
         m_classes = classes;
      }
     
      @SuppressWarnings("rawtypes")
      public Class[] getClasses()
      {
         return m_classes;
      }
     
      public String getMethodName()
      {
         return m_method_name;
      }
     
      public Object[] getParams()
      {
         return m_params;
      }
     
   }

   public static final int          MAX_TEXTURES = 16;
   
   private static String             sm_path = "res/shaders/";

   private boolean                m_valid;
   private int                   m_handle;
   private String                   m_name;
   private String                   m_vert_shader_path;
   private String                   m_frag_shader_path;
   private Thread                   m_thread;
   private ArrayList<ShaderMethod>    m_methods;
   private HashMap<String, Integer>    m_attribs;
   private HashMap<String, Integer>    m_uniforms;
   private HashMap<String, Integer>    m_uniform_blocks;
   
   public Shader(String vert_shader_path, String frag_shader_path)
   {
      m_name = vert_shader_path.substring(0, vert_shader_path.indexOf("."));
      m_vert_shader_path = vert_shader_path;
      m_frag_shader_path = frag_shader_path;
      m_uniforms = new HashMap<String, Integer>();
      m_attribs = new HashMap<String, Integer>();
      m_uniform_blocks = new HashMap<String, Integer>();
      m_methods = new ArrayList<ShaderMethod>();
   }
   
   private void bindAttributes(GL3 gl)
   {
      bindLocation(gl, LOC_TYPE.ATTRIB, m_attribs, "vert_pos");
      bindLocation(gl, LOC_TYPE.ATTRIB, m_attribs, "tex_coord");
      bindLocation(gl, LOC_TYPE.ATTRIB, m_attribs, "tex_index");
      bindLocation(gl, LOC_TYPE.ATTRIB, m_attribs, "color");
      bindLocation(gl, LOC_TYPE.ATTRIB, m_attribs, "matrix_index");
   }
   
   private void bindLocation(GL3 gl, LOC_TYPE type, HashMap<String, Integer> map, String name)
   {
      int location = -1;
      switch(type)
      {
         case ATTRIB:
            location = gl.glGetAttribLocation(m_handle, name);
            break;
         case UNIFORM:
            location = gl.glGetUniformLocation(m_handle, name);
            break;
         case UNIFORM_BUFFER:
            location = gl.glGetUniformBlockIndex(m_handle, name);
            break;
         default:
            Logger.log(ERROR, "LOC_TYPE doesn't exist, could not bind to " + name, getName());
            System.exit(EXIT_CODE.SHADER_FAILURE.err_code);
            break;
      }
      map.put(name, location);
   }
   
   public void bindTexture(GL3 gl, int unit, int id)
   {
      gl.glActiveTexture(GL3.GL_TEXTURE0 + unit);
      gl.glBindTexture(GL3.GL_TEXTURE_2D, id);
   }
   
   private void bindUniformBufferObjects(GL3 gl)
   {
      bindLocation(gl, LOC_TYPE.UNIFORM_BUFFER, m_uniform_blocks, "matrixbuffers");
   }
   
   private void bindUniforms(GL3 gl)
   {
      bindLocation(gl, LOC_TYPE.UNIFORM, m_uniforms, "model_matrix");
      bindLocation(gl, LOC_TYPE.UNIFORM, m_uniforms, "view_matrix");
      bindLocation(gl, LOC_TYPE.UNIFORM, m_uniforms, "projection_matrix");
      bindLocation(gl, LOC_TYPE.UNIFORM, m_uniforms, "light_pos");
      for(int i = 0; i < MAX_TEXTURES; i++)
         bindLocation(gl, LOC_TYPE.UNIFORM, m_uniforms, "diffuse_maps["+i+"]");
   }
   
   private int buildShader(GL3 gl, int shader_type, String shader_location)
   {
      File shader_file = new File(sm_path + shader_location);
      int shader_handle = gl.glCreateShader(shader_type);//grab a handle

      //Find the vert file to load
      ArrayList<String> src_array = new ArrayList<String>();
      Scanner file_scanner = null;
      try { file_scanner = new Scanner(shader_file); }
      catch (FileNotFoundException e) { Logger.log(ERROR, m_name + " not found!", getName()); }

      //Put the code into an array
      file_scanner.useDelimiter("\n");//Use the return char during scanning
      while(file_scanner.hasNext())
      {
         String temp = file_scanner.next() + "\n";
         src_array.add(temp);
      }
     
      file_scanner.close();

      //Convert the array over to a String array so we can compile it
      String[] shader_source = new String[src_array.size()];
      shader_source = src_array.toArray(shader_source);
      int [] lengths= new int[shader_source.length];
      for(int i = 0; i < shader_source.length; i++)
      {
         lengths[i] = shader_source[i].length();
      }

      //Compile the shader
      gl.glShaderSource(shader_handle, lengths.length, shader_source, lengths, 0);        
      gl.glCompileShader(shader_handle);
      checkForShaderErrors(gl, shader_handle, shader_type, shader_location);
      gl.glAttachShader(m_handle, shader_handle);
     
      return shader_handle;
   }
   
   private void checkForProgramErrors(GL3 gl, int status_type)
   {  
      int[] result = new int[1];
      gl.glGetProgramiv(m_handle, status_type, result, 0);
      if(result[0] == GL3.GL_FALSE)
      {
         if(status_type == GL3.GL_LINK_STATUS)
            Logger.log(ERROR, "Failed to link", getName());
         if(status_type == GL3.GL_VALIDATE_STATUS)
            Logger.log(ERROR, "Failed to validate", getName());
         int[] info_log_length = new int[1];
         gl.glGetProgramiv(m_handle,  GL3.GL_INFO_LOG_LENGTH, info_log_length, 0);
         byte[] info_log = new byte[info_log_length[0]];
         gl.glGetProgramInfoLog(m_handle, info_log.length, info_log_length, 0, info_log, 0);
         
//         for(int i = 0; i < info_log.length; i++)
//            System.err.print((char)info_log[i]);
         Logger.log(DEBUG, SStringOperations.byteArrayToString(info_log), getName());

         if(status_type == GL3.GL_LINK_STATUS)
         {
            Logger.log(ERROR, "Unable to continue, exiting!", getName());
            System.exit(EXIT_CODE.SHADER_FAILURE.err_code);
         }
      }
   }
   
   private void checkForShaderErrors(GL3 gl, int shader_handle, int shader_type, String shader_location)
   {  
      int[] result = new int[1];
      gl.glGetShaderiv(shader_handle, GL3.GL_COMPILE_STATUS, result, 0);
      if(result[0] == GL3.GL_FALSE)
      {
         Logger.log(ERROR, "Failed to compile", getName());
         int[] info_log_length = new int[1];
         gl.glGetShaderiv(shader_handle,  GL3.GL_INFO_LOG_LENGTH, info_log_length, 0);
         byte[] info_log = new byte[info_log_length[0]];
         gl.glGetShaderInfoLog(shader_handle, info_log.length, info_log_length, 0, info_log, 0);
         
//         for(int i = 0; i < info_log.length; i++)
//            System.err.print((char)info_log[i]);

         Logger.log(ERROR, SStringOperations.byteArrayToString(info_log), getName());
         Logger.log(ERROR, "Unable to continue, exiting!", getName());
         System.exit(EXIT_CODE.SHADER_FAILURE.err_code);
      }
   }
   
   @Override
   public void cleanup(GL3 gl)
   {
      gl.glDeleteShader(m_handle);
   }
   
   public void disable(GL3 gl)
   {
      gl.glUseProgram(0);
   }
   
   public void enable(GL3 gl)
   {
      gl.glUseProgram(m_handle);
   }

   public int getAttribLocation(String name)
   {
      return wrapLocation(m_attribs, name);
   }
   
   public String getName()
   {
      return m_name;
   }
   
   @Override
   public Thread getThread()
   {
      return m_thread;
   }
   
   public int getUniformLocation(String name)
   {
      return wrapLocation(m_uniforms, name);
   }
   
   public int getUniformBlockLocation(String name)
   {
      return wrapLocation(m_uniform_blocks, name);
   }
   
   @Override
   public void init(GL3 gl)
   {
      m_handle = gl.glCreateProgram();
     
      int v = buildShader(gl, GL3.GL_VERTEX_SHADER, m_vert_shader_path);
      int f = buildShader(gl, GL3.GL_FRAGMENT_SHADER, m_frag_shader_path);
     
      linkProgram(gl, v, f);
     
      //Bind the attributes before we link
      bindAttributes(gl);
      //Bind uniforms after link
      bindUniforms(gl);
      //Bind UBOs
      bindUniformBufferObjects(gl);
   }
   
   private void linkProgram(GL3 gl, int v, int f)
   {
      gl.glLinkProgram(m_handle);
      checkForProgramErrors(gl, GL3.GL_LINK_STATUS);
      gl.glValidateProgram(m_handle);
      checkForProgramErrors(gl, GL3.GL_VALIDATE_STATUS);
      m_valid = gl.glIsProgram(m_handle);//Determine if the shader is valid for our uses.
     
      //So, I guess that you can and should do this?
      gl.glDetachShader(m_handle, v);
      gl.glDetachShader(m_handle, f);
   }

   public void setPath(String path)
   {
      sm_path = path;
   }
   
   @Override
   public void setThread(Thread thread)
   {
      m_thread = thread;
   }
   
   public void setUniform1f(GL3 gl, String name, float x)
   {
      gl.glUniform1f(wrapLocation(m_uniforms, name), x);
   }
   
   public void setUniform1fv(GL3 gl, String name, int count, float[] value)
   {
      gl.glUniform1fv(wrapLocation(m_uniforms, name), count, value, 0);
   }
   
   public void setUniform1i(GL3 gl, String name, int x)
   {
      gl.glUniform1i(wrapLocation(m_uniforms, name), x);
   }
   
   public void setUniform1iv(GL3 gl, String name, int count, int[] value)
   {
      gl.glUniform1iv(wrapLocation(m_uniforms, name), count, value, 0);
   }
   
   public void setUniform2f(GL3 gl, String name, float x, float y)
   {
      gl.glUniform2f(wrapLocation(m_uniforms, name), x, y);
   }
   
   /**
    * Use only if a GL instance is not available in the thread.
    * @param uniform_name
    * @param x
    * @param y
    */

   public void setUniform2f(String uniform_name, float x, float y)
   {
      Object[] params = new Object[]{ null, uniform_name, x, y };
      @SuppressWarnings("rawtypes")
      Class[] classes = new Class[]{ GL3.class, String.class, float.class, float.class };
      m_methods.add(new ShaderMethod("setUniform2f", params, classes));
   }

   public void setUniform3f(GL3 gl, String name, float x, float y, float z)
   {
      gl.glUniform3f(wrapLocation(m_uniforms, name), x, y, z);
   }

   public void setUniform4f(GL3 gl, String name, float x, float y, float z, float w)
   {
      gl.glUniform4f(wrapLocation(m_uniforms, name), x, y, z, w);
   }
   
   public void setUniformMatrix3f(GL3 gl, boolean row_major, String name, float[] matrix)
   {
      gl.glUniformMatrix3fv(wrapLocation(m_uniforms, name), 1, row_major, matrix, 0);//true means row major order
   }
   
   public void setUniformMatrix4f(GL3 gl, boolean row_major, String name, float[] matrix)
   {
      gl.glUniformMatrix4fv(wrapLocation(m_uniforms, name), 1, row_major, matrix, 0);//true means row major order
   }

   public void update(GL3 gl)
   {
      enable(gl);
      for(int i = 0; i < m_methods.size(); i++)
      {
         ShaderMethod shader_method = m_methods.get(i);
         Method method = null;
         try
         {
            method = getClass().getDeclaredMethod(shader_method.getMethodName(), shader_method.getClasses());
         }
         catch (NoSuchMethodException e) { e.printStackTrace(); System.exit(EXIT_CODE.SHADER_FAILURE.err_code); }
         catch (SecurityException e) { e.printStackTrace(); System.exit(EXIT_CODE.SHADER_FAILURE.err_code); }
         try
         {
            Object[] params = shader_method.getParams();
            params[0] = gl;
            method.invoke(this, params);
         }
         catch (IllegalAccessException e) { e.printStackTrace(); System.exit(EXIT_CODE.SHADER_FAILURE.err_code); }
         catch (IllegalArgumentException e) { e.printStackTrace(); System.exit(EXIT_CODE.SHADER_FAILURE.err_code); }
         catch (InvocationTargetException e) { e.printStackTrace(); System.exit(EXIT_CODE.SHADER_FAILURE.err_code); }
      }
      m_methods.clear();
   }

   public boolean valid()
   {
      return m_valid;
   }
   
   private Integer wrapLocation(HashMap<String, Integer> map, String name)
   {
      Integer location = map.get(name);
      if(location == null)
      {
         Logger.log(WARNING, "Could not bind shader var: " + name, getName());
         return -1;
      }
      return location;
   }

}

Every village needs an idiot Cool
Offline elect

JGO Knight


Medals: 42



« Reply #5 - Posted 2016-04-27 07:53:55 »

I don't understand what you mean here...

Calling a vertex shader 3d or 2d makes no sense.

I render using the 3d program first, 2d second. I'm using 4 textures for the 3D scene and 5 for the 2D overlay (3 of the textures are shared). This results in the last texture from the 2d overlay to use the texture at index zero instead. However, if I have the same amount of textures (4 & 4, 3 & 3, etc..) for both passes then the problem looks like it goes away (get the expected results).

The textures are generally numbered 1, 6, 7, 8, 9 in openGL. They are bound using glActiveTexture() between 0-4.

So, you are using texture unit [0-3] for the 3d scene and [0-4] for the 2d overlay? This would make 4 shared textures

Please have a look at my first post again, I have added more comments so you can see exactly which line the error occurs on. (Note that the error is only thrown if the number of textures being used by both renderers differs in number (quantity), doesn't matter which textures are used or if I share textures between them).

Api doc:

- GL_INVALID_OPERATION is generated if texture was previously created with a target that doesn't match that of target.

Check initialization and binding targets

Anyway, let me suggest you few tips about your code:

- I see you are doing a lot of things in your own and also you have a couple of function that have one line. Be aware that this largely increase the error window... you may easily reduce overhead and dimension of that class, increasing readability and debugging, with a couple of things

- you are using a very outdated jogl, I can see the old location of GL3, import javax.media.opengl.GL3;

- if you can, you should upgrade to OpenGL 4, that offers also explicit location, this way you don't have to deal at all with locations..  Otherwise, unless you have to deal with tens of uniforms, HashMap is overkill, just use an integer array indexed by semantic final ints

- you should use samplers

- if your textures have all the same size and level (mipmap) number, you may use directly a sampler2DArray

- bindUniformBufferObjects doesn't actually bind them, it just retrieves the uniform block index (same for bindUniforms).. actually since you are supposed to bind it just once, you may completly skip the uniform block index in this way

- you may remove completely buildShader, checkForProgramErrors and checkForShaderErrors and delegate the whole shit to jogl in few lines of code, like here

- you should avoid all one line functions, such as cleanup, disable, enable, setUniform1f, setUniform1fv, setUniform1i, setUniform1iv, setUniform2f, setUniform3f, setUniform4f, setUniformMatrix3f, setUniformMatrix4f

- in init(gl3), you link your program and then //Bind the attributes before we link
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #6 - Posted 2016-04-27 17:42:53 »

Still confused as to why this is happening, but I have a work around.

If I call glActiveTexture() 0-MAX and bind either a texture or 0 (where MAX is the maximum supported texture units) on the first render pass then the subsequent render passes do not break.

@elect, thanks for pointing out I needed to upgrade JOGL.

Notes:
To clarify by render pass I mean calling glDrawElements() not rendering a new frame.
MAX could also be the maximum amount of textures used in all render passes.

Every village needs an idiot Cool
Offline elect

JGO Knight


Medals: 42



« Reply #7 - Posted 2016-04-27 20:28:45 »

Still confused as to why this is happening, but I have a work around.

Simplified and clean code may really help you a lot, don't underestimate it

If I call glActiveTexture() 0-MAX and bind either a texture or 0 (where MAX is the maximum supported texture units) on the first render pass then the subsequent render passes do not break.

glActiveTexture defines the "hook" on which any sequent texture binding call will bound the texture of the given id to.

This is one of the best resource you can access over this topic, I suggest you to read it carefully until you understand how texturing works in GL (3.x)


@elect, thanks for pointing out I needed to upgrade JOGL.

You are welcome Smiley
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #8 - Posted 2016-05-27 05:08:29 »

This issue is solved.

It is quite important to enable your program before binding textures...I was enabling the program after binding textures in my batch renderers which caused the problems.

Every village needs an idiot Cool
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
Ecumene (48 views)
2017-09-30 02:57:34

theagentd (72 views)
2017-09-26 18:23:31

cybrmynd (182 views)
2017-08-02 12:28:51

cybrmynd (180 views)
2017-08-02 12:19:43

cybrmynd (187 views)
2017-08-02 12:18:09

Sralse (193 views)
2017-07-25 17:13:48

Archive (744 views)
2017-04-27 17:45:51

buddyBro (876 views)
2017-04-05 03:38:00

CopyableCougar4 (1423 views)
2017-03-24 15:39:42

theagentd (1316 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!