OpenGL Multithread Drawing/Buffering

Started by UnikotE, February 03, 2014, 09:59:40

Previous topic - Next topic

UnikotE

Hello, i've started working with LWJGL and faced the problem that i need to draw many pixels on screen one by one, but using glBegin(GL_POINTS) not allows to draw it with FPS more than 10. I've decided to fill many TEXTUREs in threads, but i can't find which features alowws to do it.

So my question is how to speed up my drawing using multithreading with Texture filling in it, then give data to main thread to draw it, or... how to speed up all my problem anyhow I'll will be gratefull for any help.

Thanks.

Cornix

1) If you want somebody to be able to read your text dont use font-colors, or at least, dont use yellow as a color. Nobody on earth can read yellow on a white background.

2) If you want to fill the entire screen using points you are in for a very bad time. I dont know exactly what you want to do, but you are probably doing it wrong regardless.

3) In order to fill a texture you need to have the texture bound. Only a limited number of textures can be bound at any point in time (each to a different texture image unit). I dont know why you would need to do it multithreaded since its actually pretty fast nowadays, but if you really want it to be multithreaded you could outsource the filling of the buffers to a helper thread and only call the glTexImage command from the gl-thread.

There are plenty of tutorials about creating textures in opengl and there are tutorials about how to do it in lwjgl as well. Searching on the internet should yield promising results.

UnikotE

Thank you for feedback. It don't works for FPS. Actually my purpuse is to display a Color matrix 2000x1000(fullscreen).
   When i'm trying to divide matrix with a regions z.B. 128x128 and work with glTexImage2D in main thread i have 30 FPS, but it is too slow.

I've marked that drawing many textures is very fast, and running through array 1000x2000 is so slow, so i decided to divide cycles between threads. It multiples speed by 2.  But making textures in opengl thread takes(as i said above) much time. While working with debug Videocard feels good, summary  250/512 busy and usage is 20%. Is there way to prepare textures in threads? Actually i've tried to use GLContext with code

GLContext.useContext(glcontext);
					  	  			
	    			curTextureID = glGenTextures(); //Generate texture ID
	    	        glBindTexture(GL_TEXTURE_2D, curTextureID); //Bind texture ID
	    	        
	    	        //Setup wrap mode
	    	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
	    	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

	    	        //Setup texture scaling filtering
	    	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	    	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	    	        
	    	        //Send texel data to OpenGL
	    	        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bytebuf);
	    	       


But it have failed because  all threads use TextureID with #32. What i'm doing wrong?
Thanks.

Cornix

Are you actually creating a new texture in every frame? Because that is certainly not a good idea.

You only need to create the texture once and then you simply upload the new texel data every frame. You can keep the ByteBuffer too to save performance.
And if you create bigger textures you will need less texel uploads and less texture binds and thus your application will gain a huge performance boost.
Just use a 2048x1024 texture instead of many small ones.