Is Opengl Development GPU Dependant?

后端 未结 5 2073
执念已碎
执念已碎 2020-12-09 23:12

I am developing an android application in opengl ES2.0.In this Application I used to draw multiple lines and circles by touch event in GL surfaceView.

As opengl depen

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 23:55

    Okay, here it goes again: ^1

    OpenGL is not a scene graph. OpenGL does not maintain a scene, knows about objects or keeps tracks of geometry. OpenGL is a drawing API. You give it a canvas (in form of a Window or a PBuffer) and order it to draw points, lines or triangles and OpenGL does exactly that. Once a primitive (=point, line, triangle) has been drawn, OpenGL has no recollection about it whatsoever. If something changes, you have to redraw the whole thing.

    The proper steps to redraw a scene are:

    1. Disable the stencil test, so that the following step operates on the whole window.

    2. Clear the framebuffer using glClear(bits), where bits is a bitmask specifying which parts of the canvas to clear. When rendering a new frame you want to clear everything so bits = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;

    3. set the viewport, build an apropriate projection matrix

    4. for each object in the scene load the right modelview matrix, set uniforms, select the vertex arrays and make the drawing call.

    5. finish the rendering by flushing the pipeline. If using a single buffered window glFinish(), if using a double buffered window call SwapBuffers. In case of higher level frameworks this may be performed by the framework.

    Important Once the drawing has been finished on a double buffered window, you must not continue to send drawing operations, as by performing the buffer swap the contents of the back buffer you're drawing to are undefined. Hence you must start the drawing anew, beginning with clearing the framebuffer (steps 1 and 2).

    What your code misses are exactly those two steps. Also I have the impression that you're performing OpenGL drawing calls in direct reaction to input events, possibly in the input event handlers themself. Don't do this!. Instead use the input events to add to a list of primitives (lines in your case) to draw, then send a redraw event, which makes the framework call the drawing function. In the drawing function iterate over that list to draw the desired lines.

    Redrawing the whole scene is canonical in OpenGL!


    [1] (geesh, I'm getting tired of having to write this every 3rd question or so…)

提交回复
热议问题