利用者:AlexK/Gsoc2012/Design

提供: wiki
< 利用者:AlexK‎ | Gsoc2012
2018年6月29日 (金) 05:49時点におけるYamyam (トーク | 投稿記録)による版 (1版 をインポートしました)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

OpenGL and ES 2.0 integration

Intro

First, the OpenGL ES 2.0 is very different from ES 1.1 and doesn't support fixed pipeline. Therefore we cannot just enable OpenGL ES 2.0 without ruining the code with #ifdef. On the bright side, it supports a lot of new features that are used in BGE. For example, we can reuse GLSL with some simplifications and allow python plugins access to shaders. Also, according to Moguri, shadows are using FBOs available only in 2.0. The bigger problem is that 2.0 is not compatible with 1.1 which seriously prevent porting to 2.0 in future.

Matrices

OpenGL ES 2.0 uses vertex shaders and don't have own shaders stack. I will implement shader stack as Jason and Brecht. It would be similar to usual OpenGL stack, but instead will use BLI_math (which would be modified to speed up and support direct operations). glLoadMatrix will used for fixed pipeline to update the matrix. For ES GLSL, glUniformMatrix4fv. GLU code for setting camera prespective, will be also ported from gle implementation. That way we will cover half of incompatibility.

Technical Note

To allow easily switching

  • all matrix implementation will be moved to gpu_*
  • It will be separated with #ifdef, allowing freely compile
  • We will use pointer functions like in glew in order to load different implementation during start time

Material

We have GLSL for BGE materials in Blender already. Code generation will be simplify for ES 2.0 profiles. For basic materials and simple (solid color + texture) we will have our own shaders. This will be used mainly for UI and viewport when time will come.

Before drawing, Blender will specify what it will need:

gpu_need_draw(BSH_COLOR_FLAT | BSH_TEXT1)

Setting that we would need flat color and texture shader. We pick one out of list. For example, we don't have (BSH_COLOR_FLAT | BSH_TEXT1) shader, but we have (BSH_COLOR_FLAT | BSH_TEXT1 | BSH_TEXT2), we would use it. Another method, is to have compile it one the fly. But this wouldn't be for common usage as we would have a shader for each tiny element, which is not good for storing and sorting.

Jason is working

gpuColorEach_fixed(){glColorPointer ();}

For ES it will be like

gpuColorEach_es()
{
    glVertexAttrib(curent_shader->colorlocation ...);
    glEnableVertexAttribArray(curent_shader->colorlocation);
    curent_shader->doneattribures |= SH_COLOR;
}

When we ready do draw, we need to check if all attributes are set as we might gotten more complex shader than we needed to. All unset values are set to their defaults: color to black, texture to transparent.

Lights

Lights are more complex with premaid. We can have sets of premaid shaders with 0, 1, 2, 4, 8, 16 number of lights. We can set intensity for unused light to 0. In this case we would have 6 sets with ~7 premaid shaders which is a lot of shaders. We can compile only these shaders which we need.

As before, the same with light. We declare number of lights before hand and we choose appropriate shader set and set color before we draw.

Textures

With textures, it is much simpler. The maximum number of textures which we will need is one-two. You shouldn't use more then that on mobile platform. If you need to, you can always use dynamic blender's GLSL.

Blender Code

With some restriction, we can easily replace all functionality in blender with this encapsulation as it will be very similar in order. A little tedious, but it should allow to run on OpenGL ES 2.0.