1864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian/* 2864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * Copyright (C) 2006 The Android Open Source Project 3864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * 4864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * you may not use this file except in compliance with the License. 6864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * You may obtain a copy of the License at 7864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * 8864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * 10864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * Unless required by applicable law or agreed to in writing, software 11864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * See the License for the specific language governing permissions and 14864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian * limitations under the License. 15864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian */ 16864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 17864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#ifndef ANDROID_OPENGLES_CONTEXT_H 18864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#define ANDROID_OPENGLES_CONTEXT_H 19864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 20864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <stdint.h> 21864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <stddef.h> 22864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <sys/types.h> 23864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <pthread.h> 246071da7ef84c60645572654504813d492b8b21d5Elliott Hughes#ifdef __ANDROID__ 25864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <bionic_tls.h> 26864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#endif 27864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 28864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <private/pixelflinger/ggl_context.h> 29864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <hardware/gralloc.h> 30864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 31864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <GLES/gl.h> 32864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#include <GLES/glext.h> 33864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 34864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopiannamespace android { 35864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 36864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 37864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianconst unsigned int OGLES_NUM_COMPRESSED_TEXTURE_FORMATS = 10 38864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#ifdef GL_OES_compressed_ETC1_RGB8_texture 39864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian + 1 40864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#endif 41864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian ; 42864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 43864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianclass EGLTextureObject; 44864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianclass EGLSurfaceManager; 45864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianclass EGLBufferObjectManager; 46864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 47864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopiannamespace gl { 48864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 49864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct ogles_context_t; 50864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct matrixx_t; 51864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct transform_t; 52864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct buffer_t; 53864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 54864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianogles_context_t* getGlContext(); 55864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 56864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopiantemplate<typename T> 57864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstatic inline void swap(T& a, T& b) { 58864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian T t(a); a = b; b = t; 59864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian} 60864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopiantemplate<typename T> 61864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianinline T max(T a, T b) { 62864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return a<b ? b : a; 63864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian} 64864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopiantemplate<typename T> 65864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianinline T max(T a, T b, T c) { 66864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return max(a, max(b, c)); 67864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian} 68864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopiantemplate<typename T> 69864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianinline T min(T a, T b) { 70864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return a<b ? a : b; 71864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian} 72864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopiantemplate<typename T> 73864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianinline T min(T a, T b, T c) { 74864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return min(a, min(b, c)); 75864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian} 76864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopiantemplate<typename T> 77864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianinline T min(T a, T b, T c, T d) { 78864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return min(min(a,b), min(c,d)); 79864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian} 80864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 81864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 82864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// vertices 83864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 84864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 85864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct vec3_t { 86864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian union { 87864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { GLfixed x, y, z; }; 88864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { GLfixed r, g, b; }; 89864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { GLfixed S, T, R; }; 90864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed v[3]; 91864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 92864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 93864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 94864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct vec4_t { 95864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian union { 96864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { GLfixed x, y, z, w; }; 97864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { GLfixed r, g, b, a; }; 98864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { GLfixed S, T, R, Q; }; 99864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed v[4]; 100864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 101864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 102864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 103864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct vertex_t { 104864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian enum { 105864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // these constant matter for our clipping 106864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian CLIP_L = 0x0001, // clipping flags 107864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian CLIP_R = 0x0002, 108864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian CLIP_B = 0x0004, 109864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian CLIP_T = 0x0008, 110864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian CLIP_N = 0x0010, 111864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian CLIP_F = 0x0020, 112864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 113864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian EYE = 0x0040, 114864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian RESERVED = 0x0080, 115864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 116864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian USER_CLIP_0 = 0x0100, // user clipping flags 117864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian USER_CLIP_1 = 0x0200, 118864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian USER_CLIP_2 = 0x0400, 119864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian USER_CLIP_3 = 0x0800, 120864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian USER_CLIP_4 = 0x1000, 121864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian USER_CLIP_5 = 0x2000, 122864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 123864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian LIT = 0x4000, // lighting has been applied 124864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian TT = 0x8000, // texture coords transformed 125864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 126864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian FRUSTUM_CLIP_ALL= 0x003F, 127864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian USER_CLIP_ALL = 0x3F00, 128864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian CLIP_ALL = 0x3F3F, 129864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 130864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 131864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // the fields below are arranged to minimize d-cache usage 132864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // we group together, by cache-line, the fields most likely to be used 133864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 134864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian union { 135864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t obj; 136864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t eye; 137864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 138864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t clip; 139864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 140864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t flags; 141864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian size_t index; // cache tag, and vertex index 142864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed fog; 143864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t locked; 144864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t mru; 145864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t reserved[2]; 146864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t window; 147864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 148864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t color; 149864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t texture[GGL_TEXTURE_UNIT_COUNT]; 150444839b842798497cfa326204285a4f2ca2362afColin Cross#ifdef __LP64__ 151444839b842798497cfa326204285a4f2ca2362afColin Cross uint32_t reserved1[2]; 152444839b842798497cfa326204285a4f2ca2362afColin Cross#else 153864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t reserved1[4]; 154444839b842798497cfa326204285a4f2ca2362afColin Cross#endif 155864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 156864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline void clear() { 157864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian flags = index = locked = mru = 0; 158864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } 159864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 160864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 161864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct point_size_t { 162864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLcoord size; 163864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean smooth; 164864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 165864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 166864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct line_width_t { 167864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLcoord width; 168864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean smooth; 169864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 170864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 171864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct polygon_offset_t { 172864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed factor; 173864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed units; 174864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean enable; 175864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 176864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 177864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 178864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// arrays 179864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 180864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 181864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct array_t { 182864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian typedef void (*fetcher_t)(ogles_context_t*, GLfixed*, const GLvoid*); 183864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian fetcher_t fetch; 184864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLvoid const* physical_pointer; 185864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint size; 186864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLsizei stride; 187864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLvoid const* pointer; 188864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian buffer_t const* bo; 189864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint16_t type; 190864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean enable; 191864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean pad; 192864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLsizei bounds; 193864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void init(GLint, GLenum, GLsizei, const GLvoid *, const buffer_t*, GLsizei); 194864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline void resolve(); 195864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline const GLubyte* element(GLint i) const { 196864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return (const GLubyte*)physical_pointer + i * stride; 197864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } 198864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 199864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 200864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct array_machine_t { 201864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian array_t vertex; 202864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian array_t normal; 203864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian array_t color; 204864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian array_t texture[GGL_TEXTURE_UNIT_COUNT]; 205864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t activeTexture; 206864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t tmu; 207864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint16_t cull; 208864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t flags; 209864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum indicesType; 210864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian buffer_t const* array_buffer; 211864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian buffer_t const* element_array_buffer; 212864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 213864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*compileElements)(ogles_context_t*, vertex_t*, GLint, GLsizei); 214864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*compileElement)(ogles_context_t*, vertex_t*, GLint); 215864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 216864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*mvp_transform)(transform_t const*, vec4_t*, vec4_t const*); 217864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*mv_transform)(transform_t const*, vec4_t*, vec4_t const*); 218864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*tex_transform[2])(transform_t const*, vec4_t*, vec4_t const*); 219864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*perspective)(ogles_context_t*c, vertex_t* v); 220864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*clipVertex)(ogles_context_t* c, vertex_t* nv, 221864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLfixed t, const vertex_t* s, const vertex_t* p); 222864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*clipEye)(ogles_context_t* c, vertex_t* nv, 223864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLfixed t, const vertex_t* s, const vertex_t* p); 224864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 225864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 226864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct vertex_cache_t { 227864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian enum { 228864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // must be at least 4 229864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // 3 vertice for triangles 230864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // or 2 + 2 for indexed triangles w/ cache contention 231864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian VERTEX_BUFFER_SIZE = 8, 232864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // must be a power of two and at least 3 233864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian VERTEX_CACHE_SIZE = 64, // 8 KB 234864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 235864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian INDEX_BITS = 16, 236864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian INDEX_MASK = ((1LU<<INDEX_BITS)-1), 237864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian INDEX_SEQ = 1LU<<INDEX_BITS, 238864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 239864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t* vBuffer; 240864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t* vCache; 241864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t sequence; 242864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void* base; 243864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t total; 244864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t misses; 245864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian int64_t startTime; 246864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void init(); 247864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void uninit(); 248864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void clear(); 249864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void dump_stats(GLenum mode); 250864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 251864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 252864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 253864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// fog 254864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 255864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 256864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct fog_t { 257864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed density; 258864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed start; 259864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed end; 260864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed invEndMinusStart; 261864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum mode; 262864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed (*fog)(ogles_context_t* c, GLfixed z); 263864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 264864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 265864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 266864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// user clip planes 267864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 268864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 269864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianconst unsigned int OGLES_MAX_CLIP_PLANES = 6; 270864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 271864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct clip_plane_t { 272864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t equation; 273864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 274864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 275864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct user_clip_planes_t { 276864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian clip_plane_t plane[OGLES_MAX_CLIP_PLANES]; 277864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t enable; 278864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 279864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 280864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 281864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// lighting 282864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 283864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 284864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianconst unsigned int OGLES_MAX_LIGHTS = 8; 285864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 286864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct light_t { 287864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t ambient; 288864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t diffuse; 289864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t specular; 290864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t implicitAmbient; 291864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t implicitDiffuse; 292864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t implicitSpecular; 293864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t position; // position in eye space 294864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t objPosition; 295864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t normalizedObjPosition; 296864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t spotDir; 297864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t normalizedSpotDir; 298864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed spotExp; 299864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed spotCutoff; 300864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed spotCutoffCosine; 301864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed attenuation[3]; 302864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed rConstAttenuation; 303864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean enable; 304864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 305864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 306864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct material_t { 307864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t ambient; 308864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t diffuse; 309864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t specular; 310864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t emission; 311864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed shininess; 312864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 313864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 314864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct light_model_t { 315864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t ambient; 316864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean twoSide; 317864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 318864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 319864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct color_material_t { 320864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum face; 321864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum mode; 322864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean enable; 323864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 324864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 325864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct lighting_t { 326864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian light_t lights[OGLES_MAX_LIGHTS]; 327864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian material_t front; 328864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian light_model_t lightModel; 329864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian color_material_t colorMaterial; 330864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t implicitSceneEmissionAndAmbient; 331864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t objViewer; 332864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t enabledLights; 333864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean enable; 334864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum shadeModel; 335864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian typedef void (*light_fct_t)(ogles_context_t*, vertex_t*); 336864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*lightVertex)(ogles_context_t* c, vertex_t* v); 337864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*lightTriangle)(ogles_context_t* c, 338864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t* v0, vertex_t* v1, vertex_t* v2); 339864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 340864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 341864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct culling_t { 342864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum cullFace; 343864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum frontFace; 344864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLboolean enable; 345864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 346864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 347864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 348864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// textures 349864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 350864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 351864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct texture_unit_t { 352864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLuint name; 353864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian EGLTextureObject* texture; 354864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t dirty; 355864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 356864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 357864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct texture_state_t 358864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian{ 359864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian texture_unit_t tmu[GGL_TEXTURE_UNIT_COUNT]; 360864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian int active; // active tmu 361864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian EGLTextureObject* defaultTexture; 362864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLContext* ggl; 363864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t packAlignment; 364864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t unpackAlignment; 365864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 366864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 367864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 368864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// transformation and matrices 369864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 370864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 371864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct matrixf_t; 372864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 373864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct matrixx_t { 374864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfixed m[16]; 375864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void load(const matrixf_t& rhs); 376864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 377864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 378864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct matrix_stack_t; 379864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 380864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 381864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct matrixf_t { 382864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void loadIdentity(); 383864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void load(const matrixf_t& rhs); 384864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 385864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline GLfloat* editElements() { return m; } 386864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline GLfloat const* elements() const { return m; } 387864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 388864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void set(const GLfixed* rhs); 389864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void set(const GLfloat* rhs); 390864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 391864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian static void multiply(matrixf_t& r, 392864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian const matrixf_t& lhs, const matrixf_t& rhs); 393864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 394864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void dump(const char* what); 395864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 396864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianprivate: 397864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian friend struct matrix_stack_t; 398864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfloat m[16]; 399864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void load(const GLfixed* rhs); 400864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void load(const GLfloat* rhs); 401864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void multiply(const matrixf_t& rhs); 402864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void translate(GLfloat x, GLfloat y, GLfloat z); 403864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void scale(GLfloat x, GLfloat y, GLfloat z); 404864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z); 405864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 406864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 407864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianenum { 408864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian OP_IDENTITY = 0x00, 409864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian OP_TRANSLATE = 0x01, 410864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian OP_UNIFORM_SCALE = 0x02, 411864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian OP_SCALE = 0x05, 412864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian OP_ROTATE = 0x08, 413864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian OP_SKEW = 0x10, 414864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian OP_ALL = 0x1F 415864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 416864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 417864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct transform_t { 418864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian enum { 419864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian FLAGS_2D_PROJECTION = 0x1 420864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 421864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian matrixx_t matrix; 422864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t flags; 423864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t ops; 424864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 425864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian union { 426864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { 427864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*point2)(transform_t const* t, vec4_t*, vec4_t const*); 428864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*point3)(transform_t const* t, vec4_t*, vec4_t const*); 429864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*point4)(transform_t const* t, vec4_t*, vec4_t const*); 430864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 431864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*pointv[3])(transform_t const* t, vec4_t*, vec4_t const*); 432864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 433864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 434864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void loadIdentity(); 435864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void picker(); 436864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void dump(const char* what); 437864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 438864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 439864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct mvui_transform_t : public transform_t 440864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian{ 441864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void picker(); 442864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 443864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 444864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct matrix_stack_t { 445864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian enum { 446864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian DO_PICKER = 0x1, 447864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian DO_FLOAT_TO_FIXED = 0x2 448864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 449864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian transform_t transform; 450864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t maxDepth; 451864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t depth; 452864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t dirty; 453864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t reserved; 454864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian matrixf_t *stack; 455864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t *ops; 456864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void init(int depth); 457864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void uninit(); 458864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void loadIdentity(); 459864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void load(const GLfixed* rhs); 460864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void load(const GLfloat* rhs); 461864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void multiply(const matrixf_t& rhs); 462864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void translate(GLfloat x, GLfloat y, GLfloat z); 463864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void scale(GLfloat x, GLfloat y, GLfloat z); 464864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z); 465864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint push(); 466864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint pop(); 467864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void validate(); 468864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian matrixf_t& top() { return stack[depth]; } 469864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian const matrixf_t& top() const { return stack[depth]; } 470864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t top_ops() const { return ops[depth]; } 471864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline bool isRigidBody() const { 472864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return !(ops[depth] & ~(OP_TRANSLATE|OP_UNIFORM_SCALE|OP_ROTATE)); 473864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } 474864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 475864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 476864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct vp_transform_t { 477864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian transform_t transform; 478864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian matrixf_t matrix; 479864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfloat zNear; 480864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLfloat zFar; 481864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void loadIdentity(); 482864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 483864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 484864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct transform_state_t { 485864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian enum { 486864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian MODELVIEW = 0x01, 487864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian PROJECTION = 0x02, 488864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian VIEWPORT = 0x04, 489864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian TEXTURE = 0x08, 490864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian MVUI = 0x10, 491864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian MVIT = 0x20, 492864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian MVP = 0x40, 493864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian }; 494864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian matrix_stack_t *current; 495864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian matrix_stack_t modelview; 496864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian matrix_stack_t projection; 497864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian matrix_stack_t texture[GGL_TEXTURE_UNIT_COUNT]; 498864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 499864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // modelview * projection 500864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian transform_t mvp __attribute__((aligned(32))); 501864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // viewport transformation 502864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vp_transform_t vpt __attribute__((aligned(32))); 503864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // same for 4-D vertices 504864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian transform_t mvp4; 505864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // full modelview inverse transpose 506864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian transform_t mvit4; 507864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // upper 3x3 of mv-inverse-transpose (for normals) 508864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian mvui_transform_t mvui; 509864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 510864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum matrixMode; 511864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum rescaleNormals; 512864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t dirty; 513864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void invalidate(); 514864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void update_mvp(); 515864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void update_mvit(); 516864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void update_mvui(); 517864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 518864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 519864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct viewport_t { 520864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint x; 521864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint y; 522864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLsizei w; 523864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLsizei h; 524864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { 525864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint x; 526864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint y; 527864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } surfaceport; 528864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian struct { 529864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint x; 530864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLint y; 531864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLsizei w; 532864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLsizei h; 533864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } scissor; 534864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 535864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 536864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 537864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// Lerping 538864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 539864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 540864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct compute_iterators_t 541864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian{ 542864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void initTriangle( 543864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t const* v0, 544864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t const* v1, 545864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t const* v2); 546864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 547864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void initLine( 548864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t const* v0, 549864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t const* v1); 550864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 551864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline void initLerp(vertex_t const* v0, uint32_t enables); 552864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 553864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian int iteratorsScale(int32_t it[3], 554864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian int32_t c0, int32_t c1, int32_t c2) const; 555864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 556864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void iterators1616(GGLfixed it[3], 557864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLfixed c0, GGLfixed c1, GGLfixed c2) const; 558864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 559864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void iterators0032(int32_t it[3], 560864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian int32_t c0, int32_t c1, int32_t c2) const; 561864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 562864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void iterators0032(int64_t it[3], 563864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian int32_t c0, int32_t c1, int32_t c2) const; 564864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 565864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLcoord area() const { return m_area; } 566864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 567864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianprivate: 568864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // don't change order of members here -- used by iterators.S 569864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLcoord m_dx01, m_dy10, m_dx20, m_dy02; 570864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLcoord m_x0, m_y0; 571864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GGLcoord m_area; 572864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t m_scale; 573864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t m_area_scale; 574864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint8_t m_reserved[2]; 575864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 576864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 577864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 578864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 579864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// state 580864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian// ---------------------------------------------------------------------------- 581864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 5826071da7ef84c60645572654504813d492b8b21d5Elliott Hughes#ifdef __ANDROID__ 583864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian // We have a dedicated TLS slot in bionic 584864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline void setGlThreadSpecific(ogles_context_t *value) { 585444839b842798497cfa326204285a4f2ca2362afColin Cross __get_tls()[TLS_SLOT_OPENGL] = value; 586864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } 587864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline ogles_context_t* getGlThreadSpecific() { 588444839b842798497cfa326204285a4f2ca2362afColin Cross return static_cast<ogles_context_t*>(__get_tls()[TLS_SLOT_OPENGL]); 589864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } 590864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#else 591864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian extern pthread_key_t gGLKey; 592864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline void setGlThreadSpecific(ogles_context_t *value) { 593864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian pthread_setspecific(gGLKey, value); 594864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } 595864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian inline ogles_context_t* getGlThreadSpecific() { 596864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return static_cast<ogles_context_t*>(pthread_getspecific(gGLKey)); 597864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } 598864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#endif 599864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 600864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 601864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct prims_t { 602864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian typedef ogles_context_t* GL; 603864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*renderPoint)(GL, vertex_t*); 604864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*renderLine)(GL, vertex_t*, vertex_t*); 605864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian void (*renderTriangle)(GL, vertex_t*, vertex_t*, vertex_t*); 606864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 607864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 608864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopianstruct ogles_context_t { 609864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian context_t rasterizer; 610864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian array_machine_t arrays __attribute__((aligned(32))); 611864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian texture_state_t textures; 612864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian transform_state_t transforms; 613864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_cache_t vc; 614864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian prims_t prims; 615864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian culling_t cull; 616864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian lighting_t lighting; 617864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian user_clip_planes_t clipPlanes; 618864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian compute_iterators_t lerp; __attribute__((aligned(32))); 619864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vertex_t current; 620864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec4_t currentColorClamped; 621864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian vec3_t currentNormal; 622864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian viewport_t viewport; 623864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian point_size_t point; 624864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian line_width_t line; 625864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian polygon_offset_t polygonOffset; 626864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian fog_t fog; 627864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t perspective : 1; 628864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian uint32_t transformTextures : 1; 629864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian EGLSurfaceManager* surfaceManager; 630864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian EGLBufferObjectManager* bufferObjectManager; 631864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 632864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian GLenum error; 633864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 634864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian static inline ogles_context_t* get() { 635864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian return getGlThreadSpecific(); 636864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian } 637864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 638864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; 639864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 640864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; // namespace gl 641864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian}; // namespace android 642edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 643edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectusing namespace android::gl; 644864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 645864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian#endif // ANDROID_OPENGLES_CONTEXT_H 646864d2afbb3b8ffa17b408660624b384b518ef752Mathias Agopian 647