diff options
author | Jason Sams <rjsams@android.com> | 2009-09-30 17:36:20 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2009-09-30 17:40:06 -0700 |
commit | e9ad9a719dc66437ddf021d13e6ca736a23b5413 (patch) | |
tree | eaf8a1b1da324af59924a0d49eb6db36cae5b27c | |
parent | 5eb7c9d3e880032972c0d03dd34d9432fa7c719d (diff) | |
download | frameworks_base-e9ad9a719dc66437ddf021d13e6ca736a23b5413.zip frameworks_base-e9ad9a719dc66437ddf021d13e6ca736a23b5413.tar.gz frameworks_base-e9ad9a719dc66437ddf021d13e6ca736a23b5413.tar.bz2 |
Implement screen aligned bitmap drawing support.
-rw-r--r-- | libs/rs/rsMatrix.cpp | 9 | ||||
-rw-r--r-- | libs/rs/rsMatrix.h | 6 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.cpp | 9 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.h | 3 | ||||
-rw-r--r-- | libs/rs/rsScriptC_Lib.cpp | 48 |
5 files changed, 70 insertions, 5 deletions
diff --git a/libs/rs/rsMatrix.cpp b/libs/rs/rsMatrix.cpp index 5f68197..2f21405 100644 --- a/libs/rs/rsMatrix.cpp +++ b/libs/rs/rsMatrix.cpp @@ -85,7 +85,7 @@ void Matrix::loadRotate(float rot, float x, float y, float z) const float zx = z * x; const float xs = x * s; const float ys = y * s; - const float zs = z * s; + const float zs = z * s; m[ 0] = x*x*nc + c; m[ 4] = xy*nc - zs; m[ 8] = zx*nc + ys; @@ -156,4 +156,9 @@ void Matrix::loadFrustum(float l, float r, float b, float t, float n, float f) { m[15]= 0; } - +void Matrix::vectorMultiply(float *out, const float *in) const { + out[0] = (m[0] * in[0]) + (m[4] * in[1]) + (m[8] * in[2]) + m[12]; + out[1] = (m[1] * in[0]) + (m[5] * in[1]) + (m[9] * in[2]) + m[13]; + out[2] = (m[2] * in[0]) + (m[6] * in[1]) + (m[10] * in[2]) + m[14]; + out[3] = (m[3] * in[0]) + (m[7] * in[1]) + (m[11] * in[2]) + m[15]; +} diff --git a/libs/rs/rsMatrix.h b/libs/rs/rsMatrix.h index 7dc4165..11ce42e 100644 --- a/libs/rs/rsMatrix.h +++ b/libs/rs/rsMatrix.h @@ -23,7 +23,7 @@ namespace android { namespace renderscript { -struct Matrix +struct Matrix { float m[16]; @@ -47,6 +47,8 @@ struct Matrix void loadOrtho(float l, float r, float b, float t, float n, float f); void loadFrustum(float l, float r, float b, float t, float n, float f); + void vectorMultiply(float *v4out, const float *v3in) const; + void multiply(const Matrix *rhs) { Matrix tmp; tmp.loadMultiply(this, rhs); @@ -71,7 +73,7 @@ struct Matrix }; - + } diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index 9bfa602..eea8b3b 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -121,7 +121,14 @@ void ProgramVertex::setTextureMatrix(const rsc_Matrix *m) const mDirty = true; } - +void ProgramVertex::transformToScreen(const Context *rsc, float *v4out, const float *v3in) const +{ + float *f = static_cast<float *>(mConstants->getPtr()); + Matrix mvp; + mvp.loadMultiply((Matrix *)&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET], + (Matrix *)&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]); + mvp.vectorMultiply(v4out, v3in); +} ProgramVertexState::ProgramVertexState() { diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h index e198f23..493668c 100644 --- a/libs/rs/rsProgramVertex.h +++ b/libs/rs/rsProgramVertex.h @@ -43,6 +43,9 @@ public: void setModelviewMatrix(const rsc_Matrix *) const; void setTextureMatrix(const rsc_Matrix *) const; + void transformToScreen(const Context *, float *v4out, const float *v3in) const; + + protected: uint32_t mLightCount; ObjectBaseRef<const Light> mLights[MAX_LIGHTS]; diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp index 8919465..17d14f5 100644 --- a/libs/rs/rsScriptC_Lib.cpp +++ b/libs/rs/rsScriptC_Lib.cpp @@ -22,6 +22,8 @@ #include "acc/acc.h" #include "utils/Timers.h" +#define GL_GLEXT_PROTOTYPES + #include <GLES/gl.h> #include <GLES/glext.h> @@ -744,6 +746,48 @@ static void SC_drawQuad(float x1, float y1, float z1, x4, y4, z4, 0, 0); } +static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h) +{ + GET_TLS(); + rsc->setupCheck(); + + GLint crop[4] = {0, h, w, -h}; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); + glDrawTexfOES(x, y, z, w, h); +} + +static void SC_drawSprite(float x, float y, float z, float w, float h) +{ + GET_TLS(); + rsc->setupCheck(); + + float vin[3] = {x, y, z}; + float vout[4]; + + //LOGE("ds in %f %f %f", x, y, z); + rsc->getVertex()->transformToScreen(rsc, vout, vin); + //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]); + vout[0] /= vout[3]; + vout[1] /= vout[3]; + vout[2] /= vout[3]; + + vout[0] *= rsc->getWidth() / 2; + vout[1] *= rsc->getHeight() / 2; + vout[0] += rsc->getWidth() / 2; + vout[1] += rsc->getHeight() / 2; + + vout[0] -= w/2; + vout[1] -= h/2; + + //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]); + + // U, V, W, H + GLint crop[4] = {0, h, w, -h}; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); + glDrawTexiOES(vout[0], vout[1], 0/*vout[2]*/, w, h); +} + + static void SC_drawRect(float x1, float y1, float x2, float y2, float z) { @@ -1172,6 +1216,10 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { "void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" }, { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords, "void", "(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4)" }, + { "drawSprite", (void *)&SC_drawSprite, + "void", "(float x, float y, float z, float w, float h)" }, + { "drawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace, + "void", "(float x, float y, float z, float w, float h)" }, { "drawLine", (void *)&SC_drawLine, "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" }, { "drawPoint", (void *)&SC_drawPoint, |