diff options
Diffstat (limited to 'libs/rs/rsScriptC_Lib.cpp')
-rw-r--r-- | libs/rs/rsScriptC_Lib.cpp | 161 |
1 files changed, 131 insertions, 30 deletions
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp index 129b19f..ca05114 100644 --- a/libs/rs/rsScriptC_Lib.cpp +++ b/libs/rs/rsScriptC_Lib.cpp @@ -24,6 +24,9 @@ #include <GLES/gl.h> #include <GLES/glext.h> +#include <time.h> +#include <cutils/tztime.h> + using namespace android; using namespace android::renderscript; @@ -133,8 +136,63 @@ static float SC_randf(float max) } +////////////////////////////////////////////////////////////////////////////// +// Time routines +////////////////////////////////////////////////////////////////////////////// +static uint32_t SC_second() +{ + GET_TLS(); + time_t rawtime; + time(&rawtime); + + if (sc->mEnviroment.mTimeZone) { + struct tm timeinfo; + localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); + return timeinfo.tm_sec; + } else { + struct tm *timeinfo; + timeinfo = localtime(&rawtime); + return timeinfo->tm_sec; + } +} + +static uint32_t SC_minute() +{ + GET_TLS(); + + time_t rawtime; + time(&rawtime); + + if (sc->mEnviroment.mTimeZone) { + struct tm timeinfo; + localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); + return timeinfo.tm_min; + } else { + struct tm *timeinfo; + timeinfo = localtime(&rawtime); + return timeinfo->tm_min; + } +} + +static uint32_t SC_hour() +{ + GET_TLS(); + + time_t rawtime; + time(&rawtime); + + if (sc->mEnviroment.mTimeZone) { + struct tm timeinfo; + localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); + return timeinfo.tm_hour; + } else { + struct tm *timeinfo; + timeinfo = localtime(&rawtime); + return timeinfo->tm_hour; + } +} ////////////////////////////////////////////////////////////////////////////// // Matrix routines @@ -257,6 +315,24 @@ static void SC_bindProgramVertex(RsProgramVertex pv) } ////////////////////////////////////////////////////////////////////////////// +// VP +////////////////////////////////////////////////////////////////////////////// + +static void SC_vpLoadModelMatrix(const rsc_Matrix *m) +{ + GET_TLS(); + rsc->getVertex()->setModelviewMatrix(m); +} + +static void SC_vpLoadTextureMatrix(const rsc_Matrix *m) +{ + GET_TLS(); + rsc->getVertex()->setTextureMatrix(m); +} + + + +////////////////////////////////////////////////////////////////////////////// // Drawing ////////////////////////////////////////////////////////////////////////////// @@ -339,24 +415,25 @@ static void SC_drawQuad(float x1, float y1, float z1, glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// - -extern "C" const void * loadVp(uint32_t bank, uint32_t offset) +static void SC_drawRect(float x1, float y1, + float x2, float y2, float z) { - GET_TLS(); - return &static_cast<const uint8_t *>(sc->mSlots[bank]->getPtr())[offset]; + SC_drawQuad(x1, y2, z, + x2, y2, z, + x2, y1, z, + x1, y1, z); } - +////////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////////// static void SC_color(float r, float g, float b, float a) { glColor4f(r, g, b, a); } - +/* extern "C" void materialDiffuse(float r, float g, float b, float a) { float v[] = {r, g, b, a}; @@ -369,35 +446,18 @@ extern "C" void materialSpecular(float r, float g, float b, float a) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v); } -extern "C" void lightPosition(float x, float y, float z, float w) -{ - float v[] = {x, y, z, w}; - glLightfv(GL_LIGHT0, GL_POSITION, v); -} - extern "C" void materialShininess(float s) { glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s); } +*/ -extern "C" void uploadToTexture(RsAllocation va, uint32_t baseMipLevel) +static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel) { GET_TLS(); rsi_AllocationUploadToTexture(rsc, va, baseMipLevel); } -extern "C" void enable(uint32_t p) -{ - glEnable(p); -} - -extern "C" void disable(uint32_t p) -{ - glDisable(p); -} - - - static void SC_ClearColor(float r, float g, float b, float a) { //LOGE("c %f %f %f %f", r, g, b, a); @@ -408,6 +468,16 @@ static void SC_ClearColor(float r, float g, float b, float a) sc->mEnviroment.mClearColor[3] = a; } +static void SC_debugF(const char *s, float f) +{ + LOGE("%s %f", s, f); +} + +static void SC_debugI32(const char *s, int32_t i) +{ + LOGE("%s %i", s, i); +} + ////////////////////////////////////////////////////////////////////////////// @@ -440,10 +510,22 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { "float", "(float)" }, { "cosf", (void *)&cosf, "float", "(float)" }, - { "fabs", (void *)&fabs, + { "fabsf", (void *)&fabsf, "float", "(float)" }, { "randf", (void *)&SC_randf, "float", "(float)" }, + { "floorf", (void *)&floorf, + "float", "(float)" }, + { "ceilf", (void *)&ceilf, + "float", "(float)" }, + + // time + { "second", (void *)&SC_second, + "int", "()" }, + { "minute", (void *)&SC_minute, + "int", "()" }, + { "hour", (void *)&SC_hour, + "int", "()" }, // matrix { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity, @@ -481,7 +563,17 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { { "bindTexture", (void *)&SC_bindTexture, "void", "(int, int, int)" }, + // vp + { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix, + "void", "(void *)" }, + { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix, + "void", "(void *)" }, + + + // drawing + { "drawRect", (void *)&SC_drawRect, + "void", "(float x1, float y1, float x2, float y2, float z)" }, { "drawQuad", (void *)&SC_drawQuad, "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)" }, { "drawTriangleArray", (void *)&SC_drawTriangleArray, @@ -495,10 +587,19 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { // misc { "pfClearColor", (void *)&SC_ClearColor, "void", "(float, float, float, float)" }, - { "color", (void *)&SC_color, "void", "(float, float, float, float)" }, + { "uploadToTexture", (void *)&SC_uploadToTexture, + "void", "(int, int)" }, + + + { "debugF", (void *)&SC_debugF, + "void", "(void *, float)" }, + { "debugI32", (void *)&SC_debugI32, + "void", "(void *, int)" }, + + { NULL, NULL, NULL, NULL } }; |