简介2
OpenGL_ES是khronos协会从OpenGL裁剪定制而来的,专为手机,游戏机等嵌入式 设备而设计。它的接口其实和 Open GL很类似。
OpenGL_ES有几个主要版本,但对游戏开发来说,需要关注的只有两个: OpenGL_ES_1.x_和 OpenGL_ES_2.x。
两者的特性和主要区别如下:
OpenGL_ES_1.x 为固定渲染管线(Fixed_Function)而设计。子版本包括:1.0,1.1。1.0从OpenGL_1.3裁减而来;1.1从OpenGL_1.5裁减而来。1.1向下兼容1.0。经研究,1.1因为更先进,而且相比1.0增加的特性也都很有用,所以基本上不用考虑1.0了。1.1和1.0的变化不算很大,应该芯片的价格也不会高出很多?1.1的技术规范参见:es_full_spec.1.1.12.pdf 或者 es_cm_spec_1.1.12.pdf。
OpenGL_ES_2.x 为可编程渲染管线(Programmable)而设计。目前只有2.0这一 个子版本,从OpenGL_2.0裁减而来。和1.x的区别是可以支持vertex和pixel shader,因此能够实现更多的特效。另外2.0就不再支持1.x里面的固定管线功能 了,也就是说2.x并不向下兼容1.x。技术规范参见:es_full_spec_2.0.22.pdf 或者:es_cm_spec_2.0.22.pdf。
OpenGL ES相对OpenGL删减了一切低效能的操作方式,有高性能的决不留低效能 的,即只求效能不求兼容性。比如
- 没有double型数据类型,但加入了高性能的定点小数数据类型;
- 没有glBegin/glEnd/glVertex,只能用glDrawArrays/glDraw......;
- 没有实时将非压缩图片数据转成压缩贴图的功能,程序必须直接提供压缩好 的贴图;
OpenGL ES 与 OpenGL 的区别3
数据类型:
- i GLint 整数型
- f GLfixed 定点小数
- x GLclampx 限定型定点小数
删除的功能:
- glBegin/glEnd
- glArrayElement
- 显示列表
- 求值器
- 索引色模式
- 自定义裁剪平面
- glRect
- 图像处理(这个一般显卡也没有,FireGL/Quadro显卡有)
- 反馈缓冲
- 选择缓冲
- 累积缓冲
- 边界标志
- glPolygonMode
- GL_QUADS,GL_QUAD_STRIP,GL_POLYGON
- glPushAttrib,glPopAttrib,glPushClientAttrib,glPopClientAttrib
- TEXTURE_1D、TEXTURE_3D、TEXTURE_RECT、TEXTURE_CUBE_MAP
- GL_COMBINE
- 自动纹理坐标生成
- 纹理边界
- GL_CLAMP、GL_CLAMP_TO_BORDER
- 消失纹理代表
- 纹理LOD限定
- 纹理偏好限定
- 纹理自动压缩、解压缩
- glDrawPixels,glPixelTransfer,glPixelZoom
- glReadBuffer,glDrawBuffer,glCopyPixels
其它注意事项:
- glDrawArrays等函数中数据必须紧密排列,即间隔为0
- 各种数据的堆栈深度较低
OpenGL based Graphics : A state machine4
It's a state machine - Setup the stage, lighting, actors... Then draw it.
Sample OpenGL ES 2.0 program as following:
// Setup Handle = get_platform_specific_window_handle(); eglGetDisplay (handle); eglInitialize (); eglBindAPI (EGL_OPENGL_ES_API); eglChooseConfig (); eglCreateWindowSurface (); eglCreateContex (); eglMakeCurrent (); //Actors float afVertices [] = {...}; glEnableVertexAttribArray (0); glVertexAttribPointer (VERTEX_ARRAY, GL_FLOAT, GL_FALSE, afVertices); glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); //Show eglSwapBuffers (eglDisplay, eglSurface);
OpenGL ES 2.0, OpenGL ES 1.1 and Full Function4
- ES2.0 offers Programmable pipeline vs Fixed function in ES1.1
- Ex, Lighting, Fog functions in ES1.1 not present in ES2.0, so need to write code to generate these effects.
- More flexibility, little more work, but lot of available code
- Android uses ES1.1
- ES2.0 NOT backward compatible with ES1.1
- See Companion paper for definitive comparison of available functions in ES1.1 and ES2.0.
- See "Difference Specification" documents in Khronos OpenGL website, for summary of changes compared to OpenGL "full" function specification
OpenGL ES 2.x
简介
OpenGL ES 2.0 is very different thank ES 1.1. You don't have a fixed-function pipeline anymore, so your faimilar "push matrix, translate, rotate", etc are all gone.
Instead you have the concept of shaders: vertex and frament. They're little programs that get executed for each vertex and each pixel. That's where all the transformation and other effects happen. Your code will prepare the vertex data, tell OpenGL how it's structured, and hand it over to the shaders.
怎样上手
- 看书
- OpenGL ES 2.0 programming guide
- A brief shader tutorial
- 写几个 shader 程序练练手,推荐一个在线的 shader toy:
如何 port 应用 from OpenGL ES 1.1 to OpenGL ES 2.05
You can translate easily:
- textures management
- framebuffer objects
- blending
More difficult (Need shaders):
- fixed pipeline transformations (rotation, scale ...)
- fog
- lighting
To port your code, i recommand you:
- Learn GLSL 1.2: you can read WebGL tutorials try to write some shaders in shader toy.
- List all material you have (or rendering technics);List all vertices informations as vertices coordinates, normal,textures coord, color informations you need for each material.With theses informations, you will know which GLSL Programs (vertex + fragment shaders) you must write.
- Write your shader compil functions and log each informations; Implement a minimal program OpenGL ES 2.X with a quad (two triangles); Implement and test your GLSL programs one by one.
- Optimize