Multitexturing - Finding number of texture units.

Started by Mojomonkey, February 29, 2004, 21:12:32

Previous topic - Next topic

Mojomonkey

I'm trying to find the number of texture units that a card has using the following:

IntBuffer buf = ByteBuffer.allocateDirect(4).asIntBuffer();
GL.glGetInteger(GL.GL_MAX_TEXTURE_UNITS_ARB, buf);
int numTexUnits = buf.get();


Which gives:

java.lang.OutOfMemoryError: Java heap space

So, I'm guessing I don't understand your implementation of glGetInteger.

Any help would be appreciated. Thanks.
ever send a man to do a monkey's work.

elias

That's very weird indeed. Which LWJGL version are you using? What OS? And are you sure the error is at the GL call?

- elias

Mojomonkey

Using the unofficial LWJGL, I guess the 0.89 build? It's the EAX supported one. Windows XP, Radeon 9700 Pro.

I'm fairly certain that this is the problem because when I replace:

IntBuffer buf = ByteBuffer.allocateDirect(4).asIntBuffer();
GL.glGetInteger(GL.GL_MAX_TEXTURE_UNITS_ARB, buf);
int numTexUnits = buf.get();

with

int numTexUnits = 4;

it works fine.

so it might not be the GL call, but the allocateDirect? I'm not sure.
ever send a man to do a monkey's work.

elias

Try leaving the GL call out and only allocate the buffer. I've had OOM problems with the direct buffers before, because they don't trigger a gc if they overflow the heap. The easiest solution is a System.gc() && Runtime.runFinalizations() (or whatever it's called) before the allocation. But that might not be your problem at all of course.

Note: I'm suspicious because we never really allocate anything in LWJGL, and surely not in glGetInteger. The test will show.

- elias

Mojomonkey

interesting, the culprit is:

nt numTexUnits = buf.get();

allocating the buffer worked fine, getting the integer for GL_MAX_TEXTURE_UNTIS_ARB worked fine, but trying to get the result died.
ever send a man to do a monkey's work.

Mojomonkey

Well, tried rewinding the buffer, tried setting the marker, tried only getting the first byte, tried everything to no avail. Can some write a little test app that just gets the number of texture units of their card and tell me what I'm doing stupid? I know it's a dumb little error, but I'm missing it.
ever send a man to do a monkey's work.

cfmdobbie

The only thing I can see that's missing is .order(ByteOrder.nativeOrder()), but it shouldn't cause a problem like that, should it?  Does it function any differently using GL_MAX_TEXTURE_UNITS instead of the ARB version?
ellomynameis Charlie Dobbie.

Mojomonkey

Sure enough, setting to native order worked. Thanks!
ever send a man to do a monkey's work.

cfmdobbie

Request for 0.9:  A "BufferUtils" class as follows:

package org.lwjgl.whatever;

import java.nio.*;

public class BufferUtils
{
	public static FloatBuffer newFloatBuffer(int size) {
		return ByteBuffer.allocateDirect(size * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
	}

	public static IntBuffer newIntBuffer(int size) {
		return ByteBuffer.allocateDirect(size * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
	}
}


There are way too many unnecessary problems appearing with non-direct, non-native-ordered, non-multiplied-by-four (or any combination thereof) buffers.  Include this class and remove all that duplicated and non-obvious crap once and for all. :D
ellomynameis Charlie Dobbie.