summaryrefslogtreecommitdiffstats
path: root/opengl/libagl
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2009-07-25 19:52:22 -0700
committerJean-Baptiste Queru <jbq@google.com>2009-07-25 21:15:25 -0700
commit9261bae1d2a769cb7453d2cadb6040be38ec86e5 (patch)
treeb9edeeb20bf20eb9f76902a9671dbe10e871717b /opengl/libagl
parent4cce5bd5ccc7c8468d0f8cc359525f82a45dedec (diff)
parent4d3b5c1e36f2a3746a1c87f8af97d4fe97e8f49e (diff)
downloadframeworks_native-9261bae1d2a769cb7453d2cadb6040be38ec86e5.zip
frameworks_native-9261bae1d2a769cb7453d2cadb6040be38ec86e5.tar.gz
frameworks_native-9261bae1d2a769cb7453d2cadb6040be38ec86e5.tar.bz2
Merge korg/donut into korg/master
Diffstat (limited to 'opengl/libagl')
-rw-r--r--opengl/libagl/Android.mk2
-rw-r--r--opengl/libagl/array.cpp4
-rw-r--r--opengl/libagl/egl.cpp68
-rw-r--r--opengl/libagl/light.cpp35
-rw-r--r--opengl/libagl/matrix.cpp83
-rw-r--r--opengl/libagl/texture.cpp9
6 files changed, 97 insertions, 104 deletions
diff --git a/opengl/libagl/Android.mk b/opengl/libagl/Android.mk
index 99efe4c..3ce0414 100644
--- a/opengl/libagl/Android.mk
+++ b/opengl/libagl/Android.mk
@@ -33,6 +33,8 @@ ifneq ($(TARGET_SIMULATOR),true)
endif
LOCAL_SHARED_LIBRARIES := libcutils libutils libpixelflinger
+LOCAL_CFLAGS += -fvisibility=hidden
+
LOCAL_LDLIBS := -lpthread -ldl
LOCAL_MODULE:= libagl
diff --git a/opengl/libagl/array.cpp b/opengl/libagl/array.cpp
index 8fa7566..3e9c6a5 100644
--- a/opengl/libagl/array.cpp
+++ b/opengl/libagl/array.cpp
@@ -951,6 +951,8 @@ void compileElement__generic(ogles_context_t* c,
v->index = first;
first &= vertex_cache_t::INDEX_MASK;
const GLubyte* vp = c->arrays.vertex.element(first);
+ v->obj.z = 0;
+ v->obj.w = 0x10000;
c->arrays.vertex.fetch(c, v->obj.v, vp);
c->arrays.mvp_transform(&c->transforms.mvp, &v->clip, &v->obj);
c->arrays.perspective(c, v);
@@ -966,6 +968,8 @@ void compileElements__generic(ogles_context_t* c,
do {
v->flags = 0;
v->index = first++;
+ v->obj.z = 0;
+ v->obj.w = 0x10000;
c->arrays.vertex.fetch(c, v->obj.v, vp);
c->arrays.mvp_transform(mvp, &v->clip, &v->obj);
c->arrays.perspective(c, v);
diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp
index 3b4c041..c44478d 100644
--- a/opengl/libagl/egl.cpp
+++ b/opengl/libagl/egl.cpp
@@ -1,17 +1,17 @@
-/*
+/*
**
** Copyright 2007 The Android Open Source Project
**
-** Licensed under the Apache License Version 2.0(the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License Version 2.0(the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
**
-** http://www.apache.org/licenses/LICENSE-2.0
+** http://www.apache.org/licenses/LICENSE-2.0
**
-** Unless required by applicable law or agreed to in writing software
-** distributed under the License is distributed on an "AS IS" BASIS
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing software
+** distributed under the License is distributed on an "AS IS" BASIS
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
@@ -478,22 +478,38 @@ struct extention_map_t {
};
static const extention_map_t gExtentionMap[] = {
- { "glDrawTexsOES", (void(*)())&glDrawTexsOES },
- { "glDrawTexiOES", (void(*)())&glDrawTexiOES },
- { "glDrawTexfOES", (void(*)())&glDrawTexfOES },
- { "glDrawTexxOES", (void(*)())&glDrawTexxOES },
- { "glDrawTexsvOES", (void(*)())&glDrawTexsvOES },
- { "glDrawTexivOES", (void(*)())&glDrawTexivOES },
- { "glDrawTexfvOES", (void(*)())&glDrawTexfvOES },
- { "glDrawTexxvOES", (void(*)())&glDrawTexxvOES },
- { "glQueryMatrixxOES", (void(*)())&glQueryMatrixxOES },
- { "glClipPlanef", (void(*)())&glClipPlanef },
- { "glClipPlanex", (void(*)())&glClipPlanex },
- { "glBindBuffer", (void(*)())&glBindBuffer },
- { "glBufferData", (void(*)())&glBufferData },
- { "glBufferSubData", (void(*)())&glBufferSubData },
- { "glDeleteBuffers", (void(*)())&glDeleteBuffers },
- { "glGenBuffers", (void(*)())&glGenBuffers },
+ { "glDrawTexsOES",
+ (__eglMustCastToProperFunctionPointerType)&glDrawTexsOES },
+ { "glDrawTexiOES",
+ (__eglMustCastToProperFunctionPointerType)&glDrawTexiOES },
+ { "glDrawTexfOES",
+ (__eglMustCastToProperFunctionPointerType)&glDrawTexfOES },
+ { "glDrawTexxOES",
+ (__eglMustCastToProperFunctionPointerType)&glDrawTexxOES },
+ { "glDrawTexsvOES",
+ (__eglMustCastToProperFunctionPointerType)&glDrawTexsvOES },
+ { "glDrawTexivOES",
+ (__eglMustCastToProperFunctionPointerType)&glDrawTexivOES },
+ { "glDrawTexfvOES",
+ (__eglMustCastToProperFunctionPointerType)&glDrawTexfvOES },
+ { "glDrawTexxvOES",
+ (__eglMustCastToProperFunctionPointerType)&glDrawTexxvOES },
+ { "glQueryMatrixxOES",
+ (__eglMustCastToProperFunctionPointerType)&glQueryMatrixxOES },
+ { "glClipPlanef",
+ (__eglMustCastToProperFunctionPointerType)&glClipPlanef },
+ { "glClipPlanex",
+ (__eglMustCastToProperFunctionPointerType)&glClipPlanex },
+ { "glBindBuffer",
+ (__eglMustCastToProperFunctionPointerType)&glBindBuffer },
+ { "glBufferData",
+ (__eglMustCastToProperFunctionPointerType)&glBufferData },
+ { "glBufferSubData",
+ (__eglMustCastToProperFunctionPointerType)&glBufferSubData },
+ { "glDeleteBuffers",
+ (__eglMustCastToProperFunctionPointerType)&glDeleteBuffers },
+ { "glGenBuffers",
+ (__eglMustCastToProperFunctionPointerType)&glGenBuffers },
};
/*
@@ -1299,6 +1315,8 @@ EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
}
}
+ // TODO: call connect / disconnect on the surface
+
ogles_context_t* gl = (ogles_context_t*)ctx;
if (makeCurrent(gl) == 0) {
if (ctx) {
diff --git a/opengl/libagl/light.cpp b/opengl/libagl/light.cpp
index 25c41d0..8ae32cc 100644
--- a/opengl/libagl/light.cpp
+++ b/opengl/libagl/light.cpp
@@ -38,13 +38,14 @@ static void lightVertex(ogles_context_t* c, vertex_t* v);
static void lightVertexMaterial(ogles_context_t* c, vertex_t* v);
static inline void vscale3(GLfixed* d, const GLfixed* m, GLfixed s);
-static inline void vsub3w(GLfixed* d, const GLfixed* a, const GLfixed* b);
static __attribute__((noinline))
void vnorm3(GLfixed* d, const GLfixed* a);
static inline void vsa3(GLfixed* d,
const GLfixed* m, GLfixed s, const GLfixed* a);
+static inline void vss3(GLfixed* d,
+ const GLfixed* m, GLfixed s, const GLfixed* a);
static inline void vmla3(GLfixed* d,
const GLfixed* m0, const GLfixed* m1, const GLfixed* a);
static inline void vmul3(GLfixed* d,
@@ -151,18 +152,10 @@ void vsa3(GLfixed* d, const GLfixed* m, GLfixed s, const GLfixed* a) {
}
static inline
-void vsub3w(GLfixed* d, const GLfixed* a, const GLfixed* b) {
- const GLfixed wa = a[3];
- const GLfixed wb = b[3];
- if (ggl_likely(wa == wb)) {
- d[0] = a[0] - b[0];
- d[1] = a[1] - b[1];
- d[2] = a[2] - b[2];
- } else {
- d[0] = gglMulSubx(a[0], wb, gglMulx(b[0], wa));
- d[1] = gglMulSubx(a[1], wb, gglMulx(b[1], wa));
- d[2] = gglMulSubx(a[2], wb, gglMulx(b[2], wa));
- }
+void vss3(GLfixed* d, const GLfixed* m, GLfixed s, const GLfixed* a) {
+ d[0] = gglMulSubx(m[0], s, a[0]);
+ d[1] = gglMulSubx(m[1], s, a[1]);
+ d[2] = gglMulSubx(m[2], s, a[2]);
}
static inline
@@ -227,7 +220,7 @@ static inline void validate_light_mvi(ogles_context_t* c)
const int i = 31 - gglClz(en);
en &= ~(1<<i);
light_t& l = c->lighting.lights[i];
- c->transforms.mvui.point3(&c->transforms.mvui,
+ c->transforms.mvui.point4(&c->transforms.mvui,
&l.objPosition, &l.position);
vnorm3(l.normalizedObjPosition.v, l.objPosition.v);
}
@@ -318,6 +311,11 @@ void lightVertexMaterial(ogles_context_t* c, vertex_t* v)
vmul3(l.implicitAmbient.v, material.ambient.v, l.ambient.v);
vmul3(l.implicitDiffuse.v, material.diffuse.v, l.diffuse.v);
vmul3(l.implicitSpecular.v, material.specular.v, l.specular.v);
+ // this is just a flag to tell if we have a specular component
+ l.implicitSpecular.v[3] =
+ l.implicitSpecular.r |
+ l.implicitSpecular.g |
+ l.implicitSpecular.b;
}
// emission and ambient for the whole scene
vmla3( c->lighting.implicitSceneEmissionAndAmbient.v,
@@ -343,7 +341,11 @@ void lightVertex(ogles_context_t* c, vertex_t* v)
vec4_t n;
c->arrays.normal.fetch(c, n.v,
c->arrays.normal.element(v->index & vertex_cache_t::INDEX_MASK));
- if (c->transforms.rescaleNormals == GL_NORMALIZE)
+
+ // TODO: right now we handle GL_RESCALE_NORMALS as if ti were
+ // GL_NORMALIZE. We could optimize this by scaling mvui
+ // appropriately instead.
+ if (c->transforms.rescaleNormals)
vnorm3(n.v, n.v);
const material_t& material = c->lighting.front;
@@ -360,7 +362,8 @@ void lightVertex(ogles_context_t* c, vertex_t* v)
// compute vertex-to-light vector
if (ggl_unlikely(l.position.w)) {
- vsub3w(d.v, l.objPosition.v, v->obj.v);
+ // lightPos/1.0 - vertex/vertex.w == lightPos*vertex.w - vertex
+ vss3(d.v, l.objPosition.v, v->obj.w, v->obj.v);
sqDist = dot3(d.v, d.v);
vscale3(d.v, d.v, gglSqrtRecipx(sqDist));
} else {
diff --git a/opengl/libagl/matrix.cpp b/opengl/libagl/matrix.cpp
index f175cda..0b68dc0 100644
--- a/opengl/libagl/matrix.cpp
+++ b/opengl/libagl/matrix.cpp
@@ -55,7 +55,7 @@ static void normal__nop(transform_t const*, vec4_t* c, vec4_t const* o);
static void point2__generic(transform_t const*, vec4_t* c, vec4_t const* o);
static void point3__generic(transform_t const*, vec4_t* c, vec4_t const* o);
static void point4__generic(transform_t const*, vec4_t* c, vec4_t const* o);
-static void normal__generic(transform_t const*, vec4_t* c, vec4_t const* o);
+static void point4__mvui(transform_t const*, vec4_t* c, vec4_t const* o);
// ----------------------------------------------------------------------------
#if 0
@@ -209,7 +209,8 @@ void mvui_transform_t::picker()
{
flags = 0;
ops = OP_ALL;
- point3 = normal__generic;
+ point3 = point4__mvui;
+ point4 = point4__mvui;
}
void transform_t::dump(const char* what)
@@ -596,66 +597,19 @@ void transform_state_t::update_mvit()
void transform_state_t::update_mvui()
{
+ GLfloat r[16];
const GLfloat* const mv = modelview.top().elements();
-
- /*
- When transforming normals, we can use the upper 3x3 matrix, see:
- http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node26.html
- */
- // Also note that:
- // l(obj) = tr(M).l(eye) for infinite light
- // l(obj) = inv(M).l(eye) for local light
-
- const uint32_t ops = modelview.top_ops() & ~OP_TRANSLATE;
- if (ggl_likely((!(ops & ~OP_ROTATE)) ||
- (rescaleNormals && modelview.isRigidBody()))) {
- // if the modelview matrix is a rigid body transformation
- // (translation, rotation, uniform scaling), then we can bypass
- // the inverse by transposing the matrix.
- GLfloat rescale = 1.0f;
- if (rescaleNormals == GL_RESCALE_NORMAL) {
- if (!(ops & ~OP_UNIFORM_SCALE)) {
- rescale = reciprocalf(mv[I(0,0)]);
- } else {
- rescale = rsqrtf(
- sqrf(mv[I(2,0)]) + sqrf(mv[I(2,1)]) + sqrf(mv[I(2,2)]));
- }
- }
- GLfixed* const x = mvui.matrix.m;
- for (int i=0 ; i<3 ; i++) {
- x[I(i,0)] = gglFloatToFixed(mv[I(0,i)] * rescale);
- x[I(i,1)] = gglFloatToFixed(mv[I(1,i)] * rescale);
- x[I(i,2)] = gglFloatToFixed(mv[I(2,i)] * rescale);
- }
- mvui.picker();
- return;
- }
-
- GLfloat r[3][3];
- r[0][0] = det22(mv[I(1,1)], mv[I(2,1)], mv[I(1,2)], mv[I(2,2)]);
- r[0][1] =ndet22(mv[I(0,1)], mv[I(2,1)], mv[I(0,2)], mv[I(2,2)]);
- r[0][2] = det22(mv[I(0,1)], mv[I(1,1)], mv[I(0,2)], mv[I(1,2)]);
- r[1][0] =ndet22(mv[I(1,0)], mv[I(2,0)], mv[I(1,2)], mv[I(2,2)]);
- r[1][1] = det22(mv[I(0,0)], mv[I(2,0)], mv[I(0,2)], mv[I(2,2)]);
- r[1][2] =ndet22(mv[I(0,0)], mv[I(1,0)], mv[I(0,2)], mv[I(1,2)]);
- r[2][0] = det22(mv[I(1,0)], mv[I(2,0)], mv[I(1,1)], mv[I(2,1)]);
- r[2][1] =ndet22(mv[I(0,0)], mv[I(2,0)], mv[I(0,1)], mv[I(2,1)]);
- r[2][2] = det22(mv[I(0,0)], mv[I(1,0)], mv[I(0,1)], mv[I(1,1)]);
-
- GLfloat rdet;
- if (rescaleNormals == GL_RESCALE_NORMAL) {
- rdet = rsqrtf(sqrf(r[0][2]) + sqrf(r[1][2]) + sqrf(r[2][2]));
- } else {
- rdet = reciprocalf(
- r[0][0]*mv[I(0,0)] + r[0][1]*mv[I(1,0)] + r[0][2]*mv[I(2,0)]);
- }
+ // TODO: we need a faster invert, especially for when the modelview
+ // is a rigid-body matrix
+ invert(r, mv);
GLfixed* const x = mvui.matrix.m;
- for (int i=0 ; i<3 ; i++) {
- x[I(i,0)] = gglFloatToFixed(r[i][0] * rdet);
- x[I(i,1)] = gglFloatToFixed(r[i][1] * rdet);
- x[I(i,2)] = gglFloatToFixed(r[i][2] * rdet);
+ for (int i=0 ; i<4 ; i++) {
+ x[I(i,0)] = gglFloatToFixed(r[I(i,0)]);
+ x[I(i,1)] = gglFloatToFixed(r[I(i,1)]);
+ x[I(i,2)] = gglFloatToFixed(r[I(i,2)]);
+ x[I(i,4)] = gglFloatToFixed(r[I(i,3)]);
}
mvui.picker();
}
@@ -783,14 +737,19 @@ void point4__generic(transform_t const* mx, vec4_t* lhs, vec4_t const* rhs) {
lhs->w = mla4(rx, m[ 3], ry, m[ 7], rz, m[11], rw, m[15]);
}
-void normal__generic(transform_t const* mx, vec4_t* lhs, vec4_t const* rhs) {
+void point4__mvui(transform_t const* mx, vec4_t* lhs, vec4_t const* rhs) {
+ // this used for transforming light positions back to object space.
+ // Lights have 3 components positions, so w is always 1.
+ // however, it is used as a switch for directional lights, so we need
+ // to preserve it.
const GLfixed* const m = mx->matrix.m;
const GLfixed rx = rhs->x;
const GLfixed ry = rhs->y;
const GLfixed rz = rhs->z;
- lhs->x = mla3(rx, m[ 0], ry, m[ 4], rz, m[ 8]);
- lhs->y = mla3(rx, m[ 1], ry, m[ 5], rz, m[ 9]);
- lhs->z = mla3(rx, m[ 2], ry, m[ 6], rz, m[10]);
+ lhs->x = mla3a(rx, m[ 0], ry, m[ 4], rz, m[ 8], m[12]);
+ lhs->y = mla3a(rx, m[ 1], ry, m[ 5], rz, m[ 9], m[13]);
+ lhs->z = mla3a(rx, m[ 2], ry, m[ 6], rz, m[10], m[14]);
+ lhs->w = rhs->w;
}
diff --git a/opengl/libagl/texture.cpp b/opengl/libagl/texture.cpp
index b6f534b..14a910c 100644
--- a/opengl/libagl/texture.cpp
+++ b/opengl/libagl/texture.cpp
@@ -900,7 +900,7 @@ void glTexParameteriv(
memcpy(textureObject->crop_rect, params, 4*sizeof(GLint));
break;
default:
- ogles_error(c, GL_INVALID_ENUM);
+ texParameterx(target, pname, GLfixed(params[0]), c);
return;
}
}
@@ -919,6 +919,13 @@ void glTexParameterx(
texParameterx(target, pname, param, c);
}
+void glTexParameteri(
+ GLenum target, GLenum pname, GLint param)
+{
+ ogles_context_t* c = ogles_context_t::get();
+ texParameterx(target, pname, GLfixed(param), c);
+}
+
// ----------------------------------------------------------------------------
#if 0
#pragma mark -