18

Each glDraw* is a draw call. 1 glDrawArrays is 1 draw call. 1 glDrawElements is 1 draw call. It doesn't matter (so far as draw call count is concerned) how many vertices or indices you use, 1 glDraw* is 1 draw call. The simple cases of drawing quads (assuming the GL version you use hasn't removed quads) or triangles are not a good example for comparing ...


16

The problem with using texture atlases and adjacent texels leaking has to do with the way linear texture filtering works. For any point in the texture that is not sampled exactly at the center of a texel, linear sampling will sample 4 adjacent texels and compute the value at the location you asked as the weighted (based on distance from the sample point) ...


15

I like this kind of things explained visually. In OnpenGL we have 2D coordinates that go from -1 to +1 for both the X and Y axis. Then this image needs to be mapped to window coordinates. Let's imagine that we have window that has a dark color as back ground, and we have white as the clear color. The most common case is having viewport and scissor cover ...


13

TL; DR: If you multiply stuff together, you need to start with a 1 Forget about matrices for a second, let's talk about numbers. Suppose to rotate by 90, you multiply by 90. So P' = 90*P Now you do other transforms - a rotation R, a translation T, a scale S and so on. So P' = T*R*S*P Since you will apply all these transforms to a lot of points, you want ...


10

The performance cost of branching can be not trivially small too. In your case all vertices and fragments being drawn will be taking the same path through your shaders, so on modern desktop hardware it would not be as bad as it could be, but you're using ES2 which implies that you're not using modern desktop hardware. The worst case with branching will go ...


9

I'd like to add another answer to this that was passed on to me a year or two back by Chris Pruett (Replica Island, Wind-Up Knight, etc). It's especially useful here in 2013 since setPreserveEglContextOnPause(true) doesn't seem to work on 4.3. (I could be wrong about that but that's how it looks to me right now as I update game code last touched in 2011). ...


7

It's easy to produce an effect like this in a pixel shader, using threshold animation. The idea is that you have a monochrome texture and apply a threshold value to it; wherever the texture is lower than the threshold, the material is colored, and where the texture is higher than the threshold the material is blank. You animate the threshold value from 0 ...


7

If I call glDeleteTextures, will it release memory immediately? glDeleteTextures After a texture is deleted, it has no contents or dimensionality, and its name is free for reuse. This says absolutely nothing about the backing storage for a texture, i.e the memory used for it. From that we can infer that behaviour is entirely up to the GL implementation....


7

First of all, you are very confused. There is OpenGL ES 2.0, and there is desktop OpenGL 2.0 and 2.1. These are very different things, which run on entirely different platforms. ES runs on primarily mobile hardware, while desktop GL runs primarily on desktop hardware. The core/compatibility distinction only exists for desktop GL, not OpenGL ES. Raspberry ...


6

glScissors accomplishes clipping of geometry against a portion of the screen. You would want this, for example, if you were rendering a GUI box that had smoothly scrolling text inside it. You want to clip all geometry outside the portion of the screen covered the by the GUI, but keep partial text or polygons which are still inside. glViewport maps the ...


6

Instead of using an ImageView and transparent GLSurfaceView you should instead render your background using a fullscreen quad (just like you do with your sprites, but sized to fit the entire screen). Render this fullscreen background first (very important) and then also remove the gl.glClear(GL10.GL_COLOR_BUFFER_BIT); call in from onDrawFrame. You no longer ...


6

Any drawing API function called from the CPU will be submitted to the GPU command ring buffer to be executed later by the GPU. This means that OpenGL functions are mostly non-blocking functions. So the CPU and the GPU will be working in parallel. The most important thing to note is that your application can be CPU or GPU bound. once you call glFinish the ...


6

I'm not too familiar with what features aren't supported by OpenGL ES but the way I see it you have a couple options. A quick and easy way to get a black outline effect around an object is to scale the object up slightly and render it completely black. You can then render the regular version of the model again. Another way would be to use an edge ...


6

ATI made an announcement that the sine / cosine instructions in their newest GPUs now requires only a single clock cycle... in 2004! Modern GPUs in fact have special function units specifically for calculating trigonometric functions. So any hand-written sine or cosine function is unlikely to perform any better than the intrinsic sin() / cos() function, no ...


5

Identity matrix does nothing. It looks like this: 1,0,0,0 0,1,0,0 0,0,1,0 0,0,0,1 And that just multiplies everything by 1 if applied to other matrices or vectors. Read more about matrices An identity matrix could be used as a starting point for some calculations, or if your object is at the origo of the world with no rotations, then you would apply ...


5

Alpha mask texture approach In case your circle would always be the same size, using a second alpha mask texture would be the way to go. You would make it a grayscale mask texture and use its value as the alpha value while drawing. Using a texture had the benefit of having anti-aliasing built into the mask (ie. at the borders of your circle, the pixels can ...


5

I suggest you save yourself a lot of pain and grab the ARM Mali OpenGL ES Emulator, or the PowerVR Graphics SDK v3.3. This way you will be ready to roll in minutes. This of course assumes that you do not need your ES setup to run natively on Windows machines, e.g. when your game goes to market. If you do need to the code to run natively on Windows, you ...


5

texture2D is the same as texture, but it's used in the older versions of glsl. Between glsl 120 and 130 they changed the function to texture and made it accept every kind of samplers, not just a sampler2D. There's no difference between them, so the problem is probably in your code.


4

Here's some guesses for you to experiment with: Batch count is mainly a CPU load optimization, and not a GPU one. Try measuring CPU performance instead, for example by adjusting the positions so everything get clipped off screen. I wouldn't be surprised if the driver realizes that each batch is actually pointing into a contiguous array and merges them all ...


4

First you'll need to be able to setup OpenGL ES for 2D rendering. Have a look at this answer on SO for some basic introductory info on how to setup and get a texture loaded and ready for 2D rendering. Once you have that going it is a simple matter of changing the bound texture at some interval. First, you will need some class members (globals): // these ...


4

OpenGL never updates the screen, technically. There is a window system API that is separate from GL (e.g. GLX, WGL, CGL, EGL) that does this. Buffer swaps using these APIs generally implicitly invoke glFlush (...) but in some implementations (e.g. the GDI rasterizer on Windows) it does a full glFinish (...):       *On the left ...


4

I agree that option 2 (two render threads running at different frequencies) would be the most "logical" way to deal with this kind of situation, but it makes a big assumption: the GPU and driver have to support—or rather, simulate—pre-emptive multitasking. What you want is that the UI drawing commands from thread 1 should get high priority and get finished ...


4

Well, OpenGL is a state machine, so inorder to plot function dependencies you need to plot a state machine, there is this one that models the most recent versions of OpenGL pipeline including ES2.0 and 4.0. Unfortuantely I couldn't find a diagram the plots function dependencies but I guess that can be mostly deduced from the state machine.


4

The amount of how many devices support different APIs is usually easy to figure out by looking at public hardware stats of popular engines, such as unity and unreal. I recommend using multiple sources of stats to get better view of actual share of different device capabilities.


4

Let's start by generating all unique vertices. You can then decide whether to index those vertices, or copy them into strips/fans, depending on your needs. Here's some example code showing how to organize these vertices into triangles for rendering. // One vertex at every latitude-longitude intersection, // plus one for the north pole and one for the south. /...


3

The cost of binding shaders may not be trivial, but it's not going to be your bottleneck unless you're rendering thousands of items without batching all the objects that use the same shaders. Though I'm not sure if this applies to mobile devices, but GPUs aren't horrendously slow with branches if the condition is between a constant and a uniform. Both are ...


3

I have had this exact problem. https://stackoverflow.com/questions/14713343/projection-theory-implimented-in-glsl First thing I suggjest is getting a book called "3D Math Primer for Graphics and Game Development", which goes into detail on the clip matrix derives the whole formula for both OpenGL and DirectX projections. (There is a slight difference, oddly ...


3

You could use a frame buffer object (FBO) -- basically think of it as "render to texture". You render your scene to the buffer rather than the screen. Then, after the scene is done you render simpler things like quads to the "real" screen, using the FBO as a texture sampler in your shaders. This means you could render multiple quads each using some subset of ...


3

You can use these vendor specific functions: wglGetCurrentContext() on Windows, aglGetCurrentContext() on OSX, glxGetCurrentContext() on unixoid systems with X and eglGetCurrentContext() on GLES based systems like iOS or Android They all return NULL (except for eglGetCurrentContext, which returns EGL_NO_CONTEXT) if there is no valid context currently ...


Only top voted, non community-wiki answers of a minimum length are eligible