More Info:
When I let my game run infinitely: artificial intelligence, water animation. It doesn't crash. |
In reply to this post by gouessej
I'll try other techniques to find and eliminate the bug.
If it persists, I'll come back. |
In reply to this post by gouessej
How am I supposed to use new vertices if I can only call .put(myVertices) only once.
This is what I do in my display() loop. BEGINING OF CODE. public void init(GLAutoDrawable drawable) { vbbElements = ByteBuffer .allocateDirect(myVertices.length * 4); vbbElements.order(ByteOrder.nativeOrder()); mVertexBufferElements = vbbElements.asFloatBuffer(); } public void display() { mVertexBufferElements.put(myVertices); mVertexBufferElements.position(0); } END OF CODE. Is this a safe operation? If not, how do I update the myVertices variable once it is passed as an argument? Moreover, it is my understanding that FloatBuffers are allocated outside the Java Heap when I use "ByteBuffer .allocateDirect(" which makes them resistant to Garbage Collector's removal. Please look at how Google does it here: http://developer.android.com/training/graphics/opengl/shapes.html. This approach I think makes it impossible to have new vertex values or indices or normal values, since the geometrical shapes would be defined once and once only on the constructor. Also, how do you jogampers do it? You don't seem to have any trouble with your graphics code! Any suggestions? |
Administrator
|
Hi
Sorry for my late reply, I have just finished repairing my computer (corruption of bios data, no IDE device detection). Think once again about what I said some weeks ago: tick(), update(), render(). As soon as you do that sequentially, you won't have threading problems. Calling put() on your direct NIO buffer is not enough, you have to send the data again if you use vertex arrays (glVertexPointer) or VBO (glBufferSubData or glBufferData). The direct NIO buffer is only in the GPU if you use glBufferData with null, this buffer and the data store are 2 different things. I already spoke about this problem with direct NIO buffers in my blog, look at the latest article about TUER. You have to track the direct NIO buffers and to destroy them by yourself when you're absolutely sure you don't need them anymore. You should reuse them as often as possible instead of creating new ones. Slicing is useful too for very small ones but less with Java 1.7 as they are no more page aligned. What's wrong with your example? You can still use get() to look at the data in the buffer, can't you? You can modify the content of a direct NIO buffer after creating it. I advise you to look at the source code of the classes Mesh and MeshData of Ardor3D.
Julien Gouesse | Personal blog | Website
|
Julien:
What do you mean by "Calling put() on your direct NIO buffer is not enough, you have to send the data again if you use vertex arrays (glVertexPointer) or VBO (glBufferSubData or glBufferData)."? Please, elaborate and tell me what's wrong with this code? public void init(GLAutoDrawable drawable) { vbbElements = ByteBuffer .allocateDirect(myVertices.length * 4); vbbElements.order(ByteOrder.nativeOrder()); mVertexBufferElements = vbbElements.asFloatBuffer(); } public void display() { mVertexBufferElements.put(myVertices); mVertexBufferElements.position(0); // Missing code here; to shorten this post gl.glFrontFace(GL2.GL_CCW); gl.glVertexPointer(3, GL2.GL_FLOAT, 0, myVertices); gl.glEnable(GL2.GL_TEXTURE_2D); gl.glColorPointer(4, GL2.GL_FLOAT, 0, mColorBufferElements); gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, mTexBufferElements); gl.glDrawElements(GL2.GL_TRIANGLES, cubeFillerIElements.length, GL2.GL_UNSIGNED_SHORT, mIndexBufferElements); gl.glPopMatrix(); } |
Administrator
|
Hi
Where is your call to glPushMatrix()? I see only glPopMatrix(), I assume you use it in the missing code. Your code seems correct, you use glVertexPointer(). I use interleaved arrays but what you do is fine too. Do you really need to update the content of your direct NIO buffer every frame? Do you use transforms? If you draw a moving object with a static model and a transform, you don't need to update the content of the direct NIO buffer every frame. Do you plan to use VBOs?
Julien Gouesse | Personal blog | Website
|
You know what? I'll import a texture tutorial from the google's android website and then post it here to be peer reviewed.
Because since my code is very object oriented all I need is: allocateVariablesIndicesColorsNormals(); customize(); and render(); All that should be about 10 lines of code. |
Free forum by Nabble | Edit this page |