Sign in to follow this  

OpenGL Streaming image to a texture?

This topic is 2073 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, im messing around in c++, currently doing rendering related stuff (=badly designed opengl wrapper).

I wanted to try and make some kind of a deformable terrain which i then raycast on CPU, upload the image to a texture on GPU and put it in a fullscreen quad. I know it will probably go like 2 FPS on a 400*400 screen or something if i even get it working, but i need some interesting goal to even bother to program.

Currently i do something like this (not wrapped to a class or anything yet, i was just testing if it works):

[CODE]
while true
{
[add 1 to each component of each pixel of CPU-side texture]
[Upload texture to GPU using glTexSubImage2D or whatever it was]
[Draw my 2 triangles that cover the screen]
[Swap buffers]
}
[/CODE]


And i was wondering what can i do to increase performance. It is ok as i will obviously not be raycasting HD image, but i might also later want to draw polygons on top of it too, so id have to also have a depth texture for the raycasted thing, and possibly other stuff too to apply some effects.

I thought of these:
-Update the texture in many parts depending on how high the velocity of the "pixels" is at that point (initially the refresh rate for the whole thing, later something like a quadtree if i want multiple separate raycasted thingies moving in different directions?)

-Use some compression mechanism to not need as much bits per component

-Use PBO (i believe this will only help if its CPU limited?)


Any articles or anything that i can read to figure out how to implement for example the compression, and would it be any use?

I wont be doing anything complex as im not going to be trying to add polygons or anything to be rendered any time soon, but i want to try something simple before moving to coding the other stuff, and i want to get information about texture compression and stuff.

Thanks.

Share this post


Link to post
Share on other sites
You might want to look into using the GPU for the raycasting. You can accelerate that sort of thing by a massive amount using the GPU for your heavy lifting. On something like this it's not like raycasting on the GPU is going to be cutting into other GPU accelerated stuff.

I just did a quick search and saw this: [url="http://www.daimi.au.dk/~trier/?page_id=98"]http://www.daimi.au.dk/~trier/?page_id=98[/url]

Not entirely the same thing, but probably helpful. Some googling provides these links:
[url="http://www.cg.tuwien.ac.at/hostings/cescg/CESCG-2005/papers/VRVis-Scharsach-Henning.pdf"]http://www.cg.tuwien.ac.at/hostings/cescg/CESCG-2005/papers/VRVis-Scharsach-Henning.pdf[/url]
[url="http://www.virtualglobebook.com/3DEngineDesignForVirtualGlobesSection43.pdf"]http://www.virtualglobebook.com/3DEngineDesignForVirtualGlobesSection43.pdf[/url]
[url="http://www.it.ubi.pt/17epcg/Actas/artigos/17epcg_submission_8.pdf"]http://www.it.ubi.pt/17epcg/Actas/artigos/17epcg_submission_8.pdf[/url]

No idea how useful these would be, but there might be some techniques in those that help.

Share this post


Link to post
Share on other sites
A PBO is only going to be useful if you have some kind of delay between when you call glTexSubImage and when you use the texture; typically in the order of a frame or so. If you need to use the image in the same frame as you call glTexSubImage it's just going to add extra overhead.

A single glTexSubImage of a large rectangle per frame is also going to perform much better than many many small rectangles.

The key trick to fast glTexSubImage performance is to get your texture format parameters matching what the GPU is using internally. If they match it'll go up fast, if they don't it will need to take intermediate conversion steps which may happen in software and will slow things down.

The internalFormat parameter you supply to your original glTexImage call is not necessarily that which is actually used by the GPU - your implementation is free to substitute that with whatever it wants. Look on it as being a sort of "this is what I'd like the GPU to give me a reasonable match for" rather than "this is exactly what I want and I expect it to be exactly what I get".

So, with all that out of the way, the optimal parameters may require some testing on your part, but I've found these to work fastest across a broad range of hardware:

internalFormat: GL_RGBA8
format: GL_BGRA
type: GL_UNSIGNED_INT_8_8_8_8_REV

This can seem counter-intuitive; using 32-bit data instead of 24-bit surely sends more data and therefore should be slower? Not quite - it's a match for the GPU's internal storage, so like I said, it goes up directly without any intermediate steps needed. Those intermediate steps are always going to be much much slower than the overhead of the extra data.

It can also seem as though it's "wasting memory", but if you look at it from a certain perspective, it's actually not. Most GPUs don't actually have native internal support for 24-bit textures, and even if yours does, you're accepting some extra memory overhead in exchange for a much faster data transfer. So the memory isn't being "wasted" - it's being "[i]used[/i]". Used to get higher performance.

Share this post


Link to post
Share on other sites
Yeah i tried BGRA and im currently using RGBA (as i didnt notice any difference)


Any estimates how many FPS i can get with 1920*1080 texture being uploaded each frame before it gets CPU limited? As i think it was using 25% processor time (which is a full core as i have a quad core i believe), but im not sure if thats just because its in debug mode or something.

Also, would i get any significant performance increase by using 2 textures instead of 1, with a loop like
[CODE]
while true
{
[draw frame to send]
[update texture1]
[swap textures 1 and 2]
[draw full screen quad using texture 1 (=texture 2 at start of loop)]
}
[/CODE]

EDIT: Oh, if i do it like above, would i gain benefit from using a PBO if i understood you right? Edited by Waterlimon

Share this post


Link to post
Share on other sites
[quote name='bobbias' timestamp='1337084539' post='4940374']
You might want to look into using the GPU for the raycasting. You can accelerate that sort of thing by a massive amount using the GPU for your heavy lifting. On something like this it's not like raycasting on the GPU is going to be cutting into other GPU accelerated stuff.

I just did a quick search and saw this: [url="http://www.daimi.au.dk/~trier/?page_id=98"]http://www.daimi.au....ier/?page_id=98[/url]

Not entirely the same thing, but probably helpful. Some googling provides these links:
[url="http://www.cg.tuwien.ac.at/hostings/cescg/CESCG-2005/papers/VRVis-Scharsach-Henning.pdf"]http://www.cg.tuwien...ach-Henning.pdf[/url]
[url="http://www.virtualglobebook.com/3DEngineDesignForVirtualGlobesSection43.pdf"]http://www.virtualgl...esSection43.pdf[/url]
[url="http://www.it.ubi.pt/17epcg/Actas/artigos/17epcg_submission_8.pdf"]http://www.it.ubi.pt...ubmission_8.pdf[/url]

No idea how useful these would be, but there might be some techniques in those that help.
[/quote]

I want to use an octree instead of a 3D grid so it might be too complex to implement properly for me on the GPU. If i for some reason NEED top performance, i could think about it but for now i think it will be more fun doing it on the CPU.

Share this post


Link to post
Share on other sites
[quote name='Waterlimon' timestamp='1337087108' post='4940387']
EDIT: Oh, if i do it like above, would i gain benefit from using a PBO if i understood you right?
[/quote]

Yeah, that should be PBO-friendly alright; so long as you're replacing the entire texture rect you can do this.

25% CPU usage on a quad-core machine does suggest that you're maxing out one core, but I doubt if it's coming from the texture upload. The primary bottlenecks there, once you get the parameters right, are going to be pipeline stalls and bandwidth. Instead I'd guess that you've just got a classic busy-wait loop, in which case maxing out a core is quite normal behaviour and not really indicative of performance.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Similar Content

    • By _OskaR
      Hi,
      I have an OpenGL application but without possibility to wite own shaders.
      I need to perform small VS modification - is possible to do it in an alternative way? Do we have apps or driver modifictions which will catch the shader sent to GPU and override it?
    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
    • By dpadam450
      I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.
       
      #define NUM_LIGHTS 2
      struct Light
      {
          vec3 position;
          vec3 diffuse;
          float attenuation;
      };
      uniform Light Lights[NUM_LIGHTS];
       
       
    • By pr033r
      Hello,
      I have a Bachelor project on topic "Implenet 3D Boid's algorithm in OpenGL". All OpenGL issues works fine for me, all rendering etc. But when I started implement the boid's algorithm it was getting worse and worse. I read article (http://natureofcode.com/book/chapter-6-autonomous-agents/) inspirate from another code (here: https://github.com/jyanar/Boids/tree/master/src) but it still doesn't work like in tutorials and videos. For example the main problem: when I apply Cohesion (one of three main laws of boids) it makes some "cycling knot". Second, when some flock touch to another it scary change the coordination or respawn in origin (x: 0, y:0. z:0). Just some streng things. 
      I followed many tutorials, change a try everything but it isn't so smooth, without lags like in another videos. I really need your help. 
      My code (optimalizing branch): https://github.com/pr033r/BachelorProject/tree/Optimalizing
      Exe file (if you want to look) and models folder (for those who will download the sources):
      http://leteckaposta.cz/367190436
      Thanks for any help...

  • Popular Now