Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Sunday, December 31, 2000

#VTM_iPhone Open GL 2.0

Here a my notes on Jeff LeMarche's presentation on "Open GL ES: From 1.1 to 2.0 - Introduction to the Programmable Pipeline"

Jeff_lamarche@Mac.com

Pres will show high level concepts. Assuming a passing familiarity with OpenGL.

Quick history of OpenGL

Since 1981- OpenGL ES a subset. Silicon Graphics Iris workstations.

OOP was not standard, computers not powerful. Consumers' computers couldn't manage 3d

IrisGL

By 1992, SGI made it open source, rewrote some. VoilĂ  OpenGL!

Switched from being a hardware co. To software co.

SGI did not survive. But OpenGL thrived.

By 2006, started a mobile version was created. Took out performance detrimental features.

Apple now pushing us towards version 2.0. Original iPhone had graphics capability of a sega dreamcast.

OpenGL ES doesn't try to be forward or backward compatibility.

Fixed pipeline vs. Programmable pipeline

So, WTF is a pipeline? All that happens from when you tell open gl to draw until it actually does it.

Your app runs on the CPU; pipeline happens on GPU.

Fixed pipeline is conceptually easy, and it let's you work exclusively in your app and language.

But... You're limited to the way the pipeline does things - frozen, and can't update features. You have very little control and it's hard to optimize. Doesn't take advantage of better chips.

Programmable pipeline

Start with vertex data and any other you want. In part of process, there are hooks out for the vertex shaded and fragment shaded - and you have to write both of them! See picture in his slide.

Shaders are an inaccurate name. They don't just do shading. Shaders are extremely short programs (30 lines) in a specialty shader language.

Shaders are not compiled when you build. Compiled at runtime. Allows GLSL to be device independent.

Vertex shader is the first to run. Runs once per vertex in drawing. Takes starting location of the vertex and returns final location of vertex. Assigns it to the variable gl_Position.

fragment shader runs once per fragment -WTF is a fragment? It's a potential pixel. Every object along the ray from the eye to the pixel. Not every pixel has a fragment, but every fragment has one pixel. Ok in most situations, pixel:fragment is 1:1.

Fragment shader has one output - rgba into variable gl_FragColor.

Two types of data to send to the shaders - uniforms and attributes. Uniform is a single piece of data that is the same for both shaders. Like constants.

Btw, everything is a float

Attributes - one element for every vertex. It goes only to the vertex shader. You must provide one attribute when using the programmable pipeline. Usually, this will be the xyz coordinate of each vertex. But you can add more ( colors, textures, etc.) on a per-pixel basis.

But if color is only avail in vertex, how do we get it to fragment shader?

"varying". - a special variable passed between the vertex and fragment shader. The value set is automatically interpolated between vertex to send to fragment shader.

Shaders don't take arguments. To access an attribute or uniform, decal it at the top.

Example GLSL code - too much to type. See slide.

What you lose in 2.0
Projection matrix & modelview matrices
Projection is 3d to 2d transformation. Modelview is the matrix used to rotate, scale and translate objects
Uses a glfloat[16] for matricies.
Lose: Glmultimatrix()
Gain: Accelerate framework vDSP_mmul
More code I can't type
Lose: glOrthof()
Gain: type in some short code.
Lose: glFrustrum()
Gain: type in some short code
Lose: gluPerspective()
Gain: type in some short code
Lose: glRotatef()
Lose: glTranslate()
Lose: glScale()
Lose: glTexCoordPointer, glNormalPointer,GlColorPointer

Lose: glLightfv()
No easy substitute. Calculations done in shader. Many different approaches, too much to cover in presentation.

Lighting is the pain point. Need to know at least well enough to copy and paste intelligently.


Very challenging, but quite interesting. I suspect this is the sort of thing one would want to download a working copy and use this lesson to help dissect it. Jeff may be going to post such a working copy - check out his blog!


Maybe I forgot from the start of the presentation, but I find myself wondering (5 minutes later) when this switch will be required and/or available?



- Posted using BlogPress from my iPad