2009-07-20 14:31:06 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 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
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rsContext.h"
|
|
|
|
#include "rsScriptC.h"
|
|
|
|
#include "rsMatrix.h"
|
2009-08-03 21:12:51 -07:00
|
|
|
#include "rsNoise.h"
|
2009-07-20 14:31:06 -07:00
|
|
|
|
|
|
|
#include "acc/acc.h"
|
2009-08-09 11:39:02 -07:00
|
|
|
#include "utils/Timers.h"
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-09-30 17:36:20 -07:00
|
|
|
#define GL_GLEXT_PROTOTYPES
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
#include <GLES/gl.h>
|
|
|
|
#include <GLES/glext.h>
|
2009-11-25 13:22:07 -08:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-07-30 18:45:01 -07:00
|
|
|
#include <time.h>
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
using namespace android;
|
|
|
|
using namespace android::renderscript;
|
|
|
|
|
|
|
|
#define GET_TLS() Context::ScriptTLSStruct * tls = \
|
|
|
|
(Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
|
|
|
|
Context * rsc = tls->mContext; \
|
|
|
|
ScriptC * sc = (ScriptC *) tls->mScript
|
|
|
|
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_acospi(float v) {
|
|
|
|
return acosf(v)/ M_PI;
|
|
|
|
}
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_asinpi(float v) {
|
|
|
|
return asinf(v) / M_PI;
|
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_atanpi(float v) {
|
|
|
|
return atanf(v) / M_PI;
|
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_atan2pi(float y, float x) {
|
|
|
|
return atan2f(y, x) / M_PI;
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_cospi(float v) {
|
|
|
|
return cosf(v * M_PI);
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_exp10(float v) {
|
|
|
|
return pow(10.f, v);
|
|
|
|
|
2009-08-04 17:19:48 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_fract(float v, int *iptr) {
|
|
|
|
int i = (int)floor(v);
|
|
|
|
iptr[0] = i;
|
|
|
|
return fmin(v - i, 0x1.fffffep-1f);
|
2009-08-04 17:19:48 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_log2(float v) {
|
|
|
|
return log10(v) / log10(2.f);
|
2009-08-06 22:52:13 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_pown(float v, int p) {
|
|
|
|
return powf(v, (float)p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_powr(float v, float p) {
|
|
|
|
return powf(v, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
float SC_rootn(float v, int r) {
|
|
|
|
return pow(v, 1.f / r);
|
|
|
|
}
|
|
|
|
|
|
|
|
float SC_rsqrt(float v) {
|
|
|
|
return 1.f / sqrtf(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
float SC_sincos(float v, float *cosptr) {
|
|
|
|
*cosptr = cosf(v);
|
|
|
|
return sinf(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_sinpi(float v) {
|
|
|
|
return sinf(v * M_PI);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_tanpi(float v) {
|
|
|
|
return tanf(v * M_PI);
|
|
|
|
}
|
|
|
|
|
|
|
|
//{ "logb", (void *)& },
|
|
|
|
//{ "mad", (void *)& },
|
|
|
|
//{ "nan", (void *)& },
|
|
|
|
//{ "tgamma", (void *)& },
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Integer
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t SC_abs_i32(int32_t v) {return abs(v);}
|
|
|
|
static uint16_t SC_abs_i16(int16_t v) {return (uint16_t)abs(v);}
|
|
|
|
static uint8_t SC_abs_i8(int8_t v) {return (uint8_t)abs(v);}
|
|
|
|
|
|
|
|
static uint32_t SC_clz_u32(uint32_t v) {return __builtin_clz(v);}
|
|
|
|
static uint16_t SC_clz_u16(uint16_t v) {return (uint16_t)__builtin_clz(v);}
|
|
|
|
static uint8_t SC_clz_u8(uint8_t v) {return (uint8_t)__builtin_clz(v);}
|
|
|
|
static int32_t SC_clz_i32(int32_t v) {return (int32_t)__builtin_clz((uint32_t)v);}
|
|
|
|
static int16_t SC_clz_i16(int16_t v) {return (int16_t)__builtin_clz(v);}
|
|
|
|
static int8_t SC_clz_i8(int8_t v) {return (int8_t)__builtin_clz(v);}
|
|
|
|
|
|
|
|
static uint32_t SC_max_u32(uint32_t v, uint32_t v2) {return rsMax(v, v2);}
|
|
|
|
static uint16_t SC_max_u16(uint16_t v, uint16_t v2) {return rsMax(v, v2);}
|
|
|
|
static uint8_t SC_max_u8(uint8_t v, uint8_t v2) {return rsMax(v, v2);}
|
|
|
|
static int32_t SC_max_i32(int32_t v, int32_t v2) {return rsMax(v, v2);}
|
|
|
|
static int16_t SC_max_i16(int16_t v, int16_t v2) {return rsMax(v, v2);}
|
|
|
|
static int8_t SC_max_i8(int8_t v, int8_t v2) {return rsMax(v, v2);}
|
|
|
|
|
|
|
|
static uint32_t SC_min_u32(uint32_t v, uint32_t v2) {return rsMin(v, v2);}
|
|
|
|
static uint16_t SC_min_u16(uint16_t v, uint16_t v2) {return rsMin(v, v2);}
|
|
|
|
static uint8_t SC_min_u8(uint8_t v, uint8_t v2) {return rsMin(v, v2);}
|
|
|
|
static int32_t SC_min_i32(int32_t v, int32_t v2) {return rsMin(v, v2);}
|
|
|
|
static int16_t SC_min_i16(int16_t v, int16_t v2) {return rsMin(v, v2);}
|
|
|
|
static int8_t SC_min_i8(int8_t v, int8_t v2) {return rsMin(v, v2);}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Float util
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static float SC_clamp_f32(float amount, float low, float high)
|
2009-08-06 22:52:13 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
return amount < low ? low : (amount > high ? high : amount);
|
2009-08-06 22:52:13 -07:00
|
|
|
}
|
2009-08-06 12:40:41 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_degrees(float radians)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
return radians * (180.f / M_PI);
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_max_f32(float v, float v2)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
return rsMax(v, v2);
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_min_f32(float v, float v2)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
return rsMin(v, v2);
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_mix_f32(float start, float stop, float amount)
|
|
|
|
{
|
|
|
|
//LOGE("lerpf %f %f %f", start, stop, amount);
|
|
|
|
return start + (stop - start) * amount;
|
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_radians(float degrees)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
return degrees * (M_PI / 180.f);
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_step_f32(float edge, float v)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
if (v < edge) return 0.f;
|
|
|
|
return 1.f;
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_sign_f32(float value)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
if (value > 0) return 1.f;
|
|
|
|
if (value < 0) return -1.f;
|
|
|
|
return value;
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Non-Updated code below
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
|
|
|
} vec3_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
|
|
|
float w;
|
|
|
|
} vec4_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
} vec2_t;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// IO routines
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void SC_updateSimpleMesh(RsSimpleMesh mesh)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2010-05-11 14:03:58 -07:00
|
|
|
SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
|
|
|
|
sm->uploadAll(rsc);
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2009-09-04 14:42:41 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Vec3 routines
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void SC_vec3Norm(vec3_t *v)
|
|
|
|
{
|
|
|
|
float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
|
|
|
|
len = 1 / len;
|
|
|
|
v->x *= len;
|
|
|
|
v->y *= len;
|
|
|
|
v->z *= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_vec3Length(const vec3_t *v)
|
|
|
|
{
|
|
|
|
return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
|
|
|
{
|
|
|
|
dest->x = lhs->x + rhs->x;
|
|
|
|
dest->y = lhs->y + rhs->y;
|
|
|
|
dest->z = lhs->z + rhs->z;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
|
|
|
{
|
|
|
|
dest->x = lhs->x - rhs->x;
|
|
|
|
dest->y = lhs->y - rhs->y;
|
|
|
|
dest->z = lhs->z - rhs->z;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
|
|
|
{
|
|
|
|
float x = lhs->y * rhs->z - lhs->z * rhs->y;
|
|
|
|
float y = lhs->z * rhs->x - lhs->x * rhs->z;
|
|
|
|
float z = lhs->x * rhs->y - lhs->y * rhs->x;
|
|
|
|
dest->x = x;
|
|
|
|
dest->y = y;
|
|
|
|
dest->z = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
|
|
|
|
{
|
|
|
|
return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_vec3Scale(vec3_t *lhs, float scale)
|
|
|
|
{
|
|
|
|
lhs->x *= scale;
|
|
|
|
lhs->y *= scale;
|
|
|
|
lhs->z *= scale;
|
|
|
|
}
|
|
|
|
|
2009-10-09 16:05:25 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Vec4 routines
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void SC_vec4Norm(vec4_t *v)
|
|
|
|
{
|
|
|
|
float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
|
|
|
|
len = 1 / len;
|
|
|
|
v->x *= len;
|
|
|
|
v->y *= len;
|
|
|
|
v->z *= len;
|
|
|
|
v->w *= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_vec4Length(const vec4_t *v)
|
|
|
|
{
|
|
|
|
return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
|
|
|
|
{
|
|
|
|
dest->x = lhs->x + rhs->x;
|
|
|
|
dest->y = lhs->y + rhs->y;
|
|
|
|
dest->z = lhs->z + rhs->z;
|
|
|
|
dest->w = lhs->w + rhs->w;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
|
|
|
|
{
|
|
|
|
dest->x = lhs->x - rhs->x;
|
|
|
|
dest->y = lhs->y - rhs->y;
|
|
|
|
dest->z = lhs->z - rhs->z;
|
|
|
|
dest->w = lhs->w - rhs->w;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs)
|
|
|
|
{
|
|
|
|
return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_vec4Scale(vec4_t *lhs, float scale)
|
|
|
|
{
|
|
|
|
lhs->x *= scale;
|
|
|
|
lhs->y *= scale;
|
|
|
|
lhs->z *= scale;
|
|
|
|
lhs->w *= scale;
|
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Math routines
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-08-18 11:39:17 -07:00
|
|
|
static float SC_sinf_fast(float x)
|
|
|
|
{
|
|
|
|
const float A = 1.0f / (2.0f * M_PI);
|
|
|
|
const float B = -16.0f;
|
|
|
|
const float C = 8.0f;
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2009-08-18 11:39:17 -07:00
|
|
|
// scale angle for easy argument reduction
|
|
|
|
x *= A;
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2009-08-18 11:39:17 -07:00
|
|
|
if (fabsf(x) >= 0.5f) {
|
|
|
|
// argument reduction
|
|
|
|
x = x - ceilf(x + 0.5f) + 1.0f;
|
|
|
|
}
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2009-08-18 11:39:17 -07:00
|
|
|
const float y = B * x * fabsf(x) + C * x;
|
|
|
|
return 0.2215f * (y * fabsf(y) - y) + y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_cosf_fast(float x)
|
|
|
|
{
|
|
|
|
x += float(M_PI / 2);
|
|
|
|
|
|
|
|
const float A = 1.0f / (2.0f * M_PI);
|
|
|
|
const float B = -16.0f;
|
|
|
|
const float C = 8.0f;
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2009-08-18 11:39:17 -07:00
|
|
|
// scale angle for easy argument reduction
|
|
|
|
x *= A;
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2009-08-18 11:39:17 -07:00
|
|
|
if (fabsf(x) >= 0.5f) {
|
|
|
|
// argument reduction
|
|
|
|
x = x - ceilf(x + 0.5f) + 1.0f;
|
|
|
|
}
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2009-08-18 11:39:17 -07:00
|
|
|
const float y = B * x * fabsf(x) + C * x;
|
|
|
|
return 0.2215f * (y * fabsf(y) - y) + y;
|
|
|
|
}
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
static float SC_randf(float max)
|
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
//LOGE("max %f", max);
|
2009-07-20 14:31:06 -07:00
|
|
|
float r = (float)rand();
|
|
|
|
return r / RAND_MAX * max;
|
|
|
|
}
|
|
|
|
|
2009-07-31 11:20:59 -07:00
|
|
|
static float SC_randf2(float min, float max)
|
|
|
|
{
|
|
|
|
float r = (float)rand();
|
|
|
|
return r / RAND_MAX * (max - min) + min;
|
|
|
|
}
|
|
|
|
|
2009-10-09 16:05:25 -07:00
|
|
|
static int SC_sign(int value)
|
|
|
|
{
|
|
|
|
return (value > 0) - (value < 0);
|
|
|
|
}
|
|
|
|
|
2009-08-09 17:04:54 -07:00
|
|
|
static int SC_clamp(int amount, int low, int high)
|
|
|
|
{
|
|
|
|
return amount < low ? low : (amount > high ? high : amount);
|
|
|
|
}
|
|
|
|
|
2009-09-18 14:24:24 -07:00
|
|
|
static float SC_roundf(float v)
|
|
|
|
{
|
|
|
|
return floorf(v + 0.4999999999);
|
|
|
|
}
|
|
|
|
|
2009-07-31 11:20:59 -07:00
|
|
|
static float SC_distf2(float x1, float y1, float x2, float y2)
|
|
|
|
{
|
|
|
|
float x = x2 - x1;
|
|
|
|
float y = y2 - y1;
|
2009-08-09 17:01:55 -07:00
|
|
|
return sqrtf(x * x + y * y);
|
2009-07-31 11:20:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
|
|
|
|
{
|
|
|
|
float x = x2 - x1;
|
|
|
|
float y = y2 - y1;
|
|
|
|
float z = z2 - z1;
|
2009-08-09 17:01:55 -07:00
|
|
|
return sqrtf(x * x + y * y + z * z);
|
2009-07-31 11:20:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_magf2(float a, float b)
|
|
|
|
{
|
|
|
|
return sqrtf(a * a + b * b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_magf3(float a, float b, float c)
|
|
|
|
{
|
|
|
|
return sqrtf(a * a + b * b + c * c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_normf(float start, float stop, float value)
|
|
|
|
{
|
|
|
|
return (value - start) / (stop - start);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
|
|
|
|
{
|
|
|
|
return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
|
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static float SC_frac(float v)
|
|
|
|
{
|
|
|
|
int i = (int)floor(v);
|
|
|
|
return fmin(v - i, 0x1.fffffep-1f);
|
|
|
|
}
|
|
|
|
|
2009-07-30 18:45:01 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Time routines
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-08-09 11:39:02 -07:00
|
|
|
static int32_t SC_second()
|
2009-07-30 18:45:01 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
|
|
|
|
time_t rawtime;
|
|
|
|
time(&rawtime);
|
|
|
|
|
2009-11-11 15:36:06 -08:00
|
|
|
struct tm *timeinfo;
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
return timeinfo->tm_sec;
|
2009-07-30 18:45:01 -07:00
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-08-09 11:39:02 -07:00
|
|
|
static int32_t SC_minute()
|
2009-07-30 18:45:01 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-07-30 18:45:01 -07:00
|
|
|
time_t rawtime;
|
|
|
|
time(&rawtime);
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-11-11 15:36:06 -08:00
|
|
|
struct tm *timeinfo;
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
return timeinfo->tm_min;
|
2009-08-09 17:01:55 -07:00
|
|
|
}
|
2009-07-30 18:45:01 -07:00
|
|
|
|
2009-08-09 11:39:02 -07:00
|
|
|
static int32_t SC_hour()
|
2009-07-30 18:45:01 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-07-30 18:45:01 -07:00
|
|
|
time_t rawtime;
|
|
|
|
time(&rawtime);
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-11-11 15:36:06 -08:00
|
|
|
struct tm *timeinfo;
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
return timeinfo->tm_hour;
|
2009-07-31 11:20:59 -07:00
|
|
|
}
|
|
|
|
|
2009-08-09 11:39:02 -07:00
|
|
|
static int32_t SC_day()
|
2009-07-31 11:20:59 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-07-31 11:20:59 -07:00
|
|
|
time_t rawtime;
|
|
|
|
time(&rawtime);
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-11-11 15:36:06 -08:00
|
|
|
struct tm *timeinfo;
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
return timeinfo->tm_mday;
|
2009-08-09 17:01:55 -07:00
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-08-09 11:39:02 -07:00
|
|
|
static int32_t SC_month()
|
2009-07-31 11:20:59 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-07-31 11:20:59 -07:00
|
|
|
time_t rawtime;
|
|
|
|
time(&rawtime);
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-11-11 15:36:06 -08:00
|
|
|
struct tm *timeinfo;
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
return timeinfo->tm_mon;
|
2009-08-09 17:01:55 -07:00
|
|
|
}
|
2009-07-31 11:20:59 -07:00
|
|
|
|
2009-08-09 11:39:02 -07:00
|
|
|
static int32_t SC_year()
|
2009-07-31 11:20:59 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-07-31 11:20:59 -07:00
|
|
|
time_t rawtime;
|
|
|
|
time(&rawtime);
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-11-11 15:36:06 -08:00
|
|
|
struct tm *timeinfo;
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
return timeinfo->tm_year;
|
2009-07-31 11:20:59 -07:00
|
|
|
}
|
|
|
|
|
2009-08-09 11:39:02 -07:00
|
|
|
static int32_t SC_uptimeMillis()
|
|
|
|
{
|
|
|
|
return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t SC_startTimeMillis()
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
return sc->mEnviroment.mStartTimeMillis;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t SC_elapsedTimeMillis()
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
|
|
|
|
- sc->mEnviroment.mStartTimeMillis;
|
|
|
|
}
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Matrix routines
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
static void SC_matrixLoadIdentity(rsc_Matrix *mat)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->loadIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->load(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->load(reinterpret_cast<const Matrix *>(newmat));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->loadRotate(rot, x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->loadScale(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->loadTranslate(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
|
|
|
|
reinterpret_cast<const Matrix *>(rhs));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->multiply(reinterpret_cast<const Matrix *>(rhs));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->rotate(rot, x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->scale(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
|
|
|
|
{
|
|
|
|
Matrix *m = reinterpret_cast<Matrix *>(mat);
|
|
|
|
m->translate(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static rsvF_2 SC_vec2Rand(float maxLen)
|
2009-08-17 13:56:09 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
float2 t;
|
|
|
|
float angle = SC_randf(M_PI * 2);
|
2009-08-17 13:56:09 -07:00
|
|
|
float len = SC_randf(maxLen);
|
2010-05-11 14:03:58 -07:00
|
|
|
t.f[0] = len * sinf(angle);
|
|
|
|
t.f[1] = len * cosf(angle);
|
|
|
|
return t.v;
|
2009-08-17 13:56:09 -07:00
|
|
|
}
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Context
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
2009-12-17 16:55:08 -08:00
|
|
|
rsi_ProgramBindTexture(rsc,
|
|
|
|
static_cast<ProgramFragment *>(vpf),
|
|
|
|
slot,
|
|
|
|
static_cast<Allocation *>(va));
|
2009-07-20 14:31:06 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
2009-12-17 16:55:08 -08:00
|
|
|
rsi_ProgramBindSampler(rsc,
|
|
|
|
static_cast<ProgramFragment *>(vpf),
|
|
|
|
slot,
|
|
|
|
static_cast<Sampler *>(vs));
|
2009-07-20 14:31:06 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-05-13 18:30:11 -07:00
|
|
|
static void SC_bindProgramStore(RsProgramStore pfs)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2010-05-13 18:30:11 -07:00
|
|
|
rsi_ContextBindProgramStore(rsc, pfs);
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_bindProgramFragment(RsProgramFragment pf)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
rsi_ContextBindProgramFragment(rsc, pf);
|
|
|
|
}
|
|
|
|
|
2009-07-21 12:20:54 -07:00
|
|
|
static void SC_bindProgramVertex(RsProgramVertex pv)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
rsi_ContextBindProgramVertex(rsc, pv);
|
2010-05-12 18:26:52 -07:00
|
|
|
}
|
2009-07-21 12:20:54 -07:00
|
|
|
|
2010-05-12 18:26:52 -07:00
|
|
|
static void SC_bindProgramRaster(RsProgramRaster pv)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
rsi_ContextBindProgramRaster(rsc, pv);
|
2009-07-21 12:20:54 -07:00
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-07-28 12:02:16 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Drawing
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-08-07 15:40:32 -07:00
|
|
|
static void SC_drawLine(float x1, float y1, float z1,
|
|
|
|
float x2, float y2, float z2)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
2010-03-03 13:03:18 -08:00
|
|
|
if (!rsc->setupCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-08-07 15:40:32 -07:00
|
|
|
|
|
|
|
float vtx[] = { x1, y1, z1, x2, y2, z2 };
|
2009-11-25 13:22:07 -08:00
|
|
|
VertexArray va;
|
2010-01-25 12:31:24 -08:00
|
|
|
va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
|
2009-11-25 13:22:07 -08:00
|
|
|
if (rsc->checkVersion2_0()) {
|
2009-12-23 14:35:29 -08:00
|
|
|
va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
|
2009-11-25 13:22:07 -08:00
|
|
|
} else {
|
2009-12-23 14:35:29 -08:00
|
|
|
va.setupGL(rsc, &rsc->mStateVertexArray);
|
2009-11-25 13:22:07 -08:00
|
|
|
}
|
2009-08-07 15:40:32 -07:00
|
|
|
|
|
|
|
glDrawArrays(GL_LINES, 0, 2);
|
|
|
|
}
|
|
|
|
|
2009-09-28 18:12:56 -07:00
|
|
|
static void SC_drawPoint(float x, float y, float z)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
2010-03-03 13:03:18 -08:00
|
|
|
if (!rsc->setupCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-09-28 18:12:56 -07:00
|
|
|
|
|
|
|
float vtx[] = { x, y, z };
|
|
|
|
|
2009-11-25 13:22:07 -08:00
|
|
|
VertexArray va;
|
2010-01-25 12:31:24 -08:00
|
|
|
va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
|
2009-11-25 13:22:07 -08:00
|
|
|
if (rsc->checkVersion2_0()) {
|
2009-12-23 14:35:29 -08:00
|
|
|
va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
|
2009-11-25 13:22:07 -08:00
|
|
|
} else {
|
2009-12-23 14:35:29 -08:00
|
|
|
va.setupGL(rsc, &rsc->mStateVertexArray);
|
2009-11-25 13:22:07 -08:00
|
|
|
}
|
2009-09-28 18:12:56 -07:00
|
|
|
|
|
|
|
glDrawArrays(GL_POINTS, 0, 1);
|
|
|
|
}
|
|
|
|
|
2009-08-08 18:30:19 -07:00
|
|
|
static void SC_drawQuadTexCoords(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)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2010-03-03 13:03:18 -08:00
|
|
|
if (!rsc->setupCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-08-10 14:55:26 -07:00
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
//LOGE("Quad");
|
|
|
|
//LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
|
|
|
|
//LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
|
|
|
|
//LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
|
|
|
|
//LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
|
2009-08-10 14:55:26 -07:00
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
|
2009-08-08 18:30:19 -07:00
|
|
|
const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-11-25 13:22:07 -08:00
|
|
|
VertexArray va;
|
2010-01-25 12:31:24 -08:00
|
|
|
va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
|
|
|
|
va.addLegacy(GL_FLOAT, 2, 8, RS_KIND_TEXTURE, false, (uint32_t)tex);
|
2009-11-25 13:22:07 -08:00
|
|
|
if (rsc->checkVersion2_0()) {
|
2009-12-23 14:35:29 -08:00
|
|
|
va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
|
2009-11-25 13:22:07 -08:00
|
|
|
} else {
|
2009-12-23 14:35:29 -08:00
|
|
|
va.setupGL(rsc, &rsc->mStateVertexArray);
|
2009-11-25 13:22:07 -08:00
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
|
|
}
|
|
|
|
|
2009-08-08 18:30:19 -07:00
|
|
|
static void SC_drawQuad(float x1, float y1, float z1,
|
|
|
|
float x2, float y2, float z2,
|
|
|
|
float x3, float y3, float z3,
|
|
|
|
float x4, float y4, float z4)
|
|
|
|
{
|
|
|
|
SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
|
|
|
|
x2, y2, z2, 1, 1,
|
|
|
|
x3, y3, z3, 1, 0,
|
|
|
|
x4, y4, z4, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-09-30 17:36:20 -07:00
|
|
|
static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
2009-11-25 13:22:07 -08:00
|
|
|
ObjectBaseRef<const ProgramVertex> tmp(rsc->getVertex());
|
|
|
|
rsc->setVertex(rsc->getDefaultProgramVertex());
|
|
|
|
//rsc->setupCheck();
|
2009-09-30 17:36:20 -07:00
|
|
|
|
2009-11-25 13:22:07 -08:00
|
|
|
//GLint crop[4] = {0, h, w, -h};
|
|
|
|
|
|
|
|
float sh = rsc->getHeight();
|
|
|
|
|
|
|
|
SC_drawQuad(x, sh - y, z,
|
|
|
|
x+w, sh - y, z,
|
|
|
|
x+w, sh - (y+h), z,
|
|
|
|
x, sh - (y+h), z);
|
|
|
|
rsc->setVertex((ProgramVertex *)tmp.get());
|
2009-09-30 17:36:20 -07:00
|
|
|
}
|
|
|
|
|
2010-01-14 15:59:35 -05:00
|
|
|
static void SC_drawSpriteScreenspaceCropped(float x, float y, float z, float w, float h,
|
|
|
|
float cx0, float cy0, float cx1, float cy1)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
2010-03-03 13:03:18 -08:00
|
|
|
if (!rsc->setupCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-01-14 15:59:35 -05:00
|
|
|
|
|
|
|
GLint crop[4] = {cx0, cy0, cx1, cy1};
|
|
|
|
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
|
|
|
|
glDrawTexfOES(x, y, z, w, h);
|
|
|
|
}
|
|
|
|
|
2009-09-30 17:36:20 -07:00
|
|
|
static void SC_drawSprite(float x, float y, float z, float w, float h)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
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
|
2009-11-25 13:22:07 -08:00
|
|
|
SC_drawSpriteScreenspace(vout[0], vout[1], z, h, w);
|
|
|
|
//rsc->setupCheck();
|
2009-09-30 17:36:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-28 17:20:11 -07:00
|
|
|
static void SC_drawRect(float x1, float y1,
|
|
|
|
float x2, float y2, float z)
|
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
//LOGE("SC_drawRect %f,%f %f,%f %f", x1, y1, x2, y2, z);
|
2009-07-28 17:20:11 -07:00
|
|
|
SC_drawQuad(x1, y2, z,
|
|
|
|
x2, y2, z,
|
|
|
|
x2, y1, z,
|
|
|
|
x1, y1, z);
|
|
|
|
}
|
|
|
|
|
2009-08-09 17:01:55 -07:00
|
|
|
static void SC_drawSimpleMesh(RsSimpleMesh vsm)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
|
2010-03-03 13:03:18 -08:00
|
|
|
if (!rsc->setupCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-11-25 13:22:07 -08:00
|
|
|
sm->render(rsc);
|
2009-08-09 17:01:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
|
2010-03-03 13:03:18 -08:00
|
|
|
if (!rsc->setupCheck()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-11-25 13:22:07 -08:00
|
|
|
sm->renderRange(rsc, start, len);
|
2009-08-09 17:01:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static uint32_t SC_allocGetDimX(RsAllocation va)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
2009-11-25 13:22:07 -08:00
|
|
|
GET_TLS();
|
2010-05-11 14:03:58 -07:00
|
|
|
const Allocation *a = static_cast<const Allocation *>(va);
|
|
|
|
//LOGE("SC_allocGetDimX a=%p", a);
|
|
|
|
//LOGE(" type=%p", a->getType());
|
|
|
|
return a->getType()->getDimX();
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static uint32_t SC_allocGetDimY(RsAllocation va)
|
2009-08-06 22:52:13 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
GET_TLS();
|
|
|
|
const Allocation *a = static_cast<const Allocation *>(va);
|
|
|
|
return a->getType()->getDimY();
|
2009-08-06 22:52:13 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static uint32_t SC_allocGetDimZ(RsAllocation va)
|
2009-08-06 22:52:13 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
GET_TLS();
|
|
|
|
const Allocation *a = static_cast<const Allocation *>(va);
|
|
|
|
return a->getType()->getDimZ();
|
2009-08-06 22:52:13 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static uint32_t SC_allocGetDimLOD(RsAllocation va)
|
2009-08-06 22:52:13 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
GET_TLS();
|
|
|
|
const Allocation *a = static_cast<const Allocation *>(va);
|
|
|
|
return a->getType()->getDimLOD();
|
2009-08-06 22:52:13 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static uint32_t SC_allocGetDimFaces(RsAllocation va)
|
2009-08-06 22:52:13 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
GET_TLS();
|
|
|
|
const Allocation *a = static_cast<const Allocation *>(va);
|
|
|
|
return a->getType()->getDimFaces();
|
2009-08-06 22:52:13 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
|
|
|
|
static void SC_color(float r, float g, float b, float a)
|
2009-08-06 22:52:13 -07:00
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
GET_TLS();
|
|
|
|
rsc->mStateVertex.color[0] = r;
|
|
|
|
rsc->mStateVertex.color[1] = g;
|
|
|
|
rsc->mStateVertex.color[2] = b;
|
|
|
|
rsc->mStateVertex.color[3] = a;
|
|
|
|
if (!rsc->checkVersion2_0()) {
|
|
|
|
glColor4f(r, g, b, a);
|
|
|
|
}
|
2009-08-06 22:52:13 -07:00
|
|
|
}
|
|
|
|
|
2009-09-04 17:55:41 -07:00
|
|
|
static void SC_pointAttenuation(float a, float b, float c)
|
|
|
|
{
|
|
|
|
GLfloat params[] = { a, b, c };
|
|
|
|
glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, params);
|
|
|
|
}
|
|
|
|
|
2009-08-20 17:08:33 -07:00
|
|
|
static void SC_hsbToRgb(float h, float s, float b, float* rgb)
|
2009-07-31 15:33:59 -07:00
|
|
|
{
|
|
|
|
float red = 0.0f;
|
|
|
|
float green = 0.0f;
|
|
|
|
float blue = 0.0f;
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-07-31 15:33:59 -07:00
|
|
|
float x = h;
|
|
|
|
float y = s;
|
|
|
|
float z = b;
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-07-31 15:33:59 -07:00
|
|
|
float hf = (x - (int) x) * 6.0f;
|
|
|
|
int ihf = (int) hf;
|
|
|
|
float f = hf - ihf;
|
|
|
|
float pv = z * (1.0f - y);
|
|
|
|
float qv = z * (1.0f - y * f);
|
|
|
|
float tv = z * (1.0f - y * (1.0f - f));
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-07-31 15:33:59 -07:00
|
|
|
switch (ihf) {
|
|
|
|
case 0: // Red is the dominant color
|
|
|
|
red = z;
|
|
|
|
green = tv;
|
|
|
|
blue = pv;
|
|
|
|
break;
|
|
|
|
case 1: // Green is the dominant color
|
|
|
|
red = qv;
|
|
|
|
green = z;
|
|
|
|
blue = pv;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
red = pv;
|
|
|
|
green = z;
|
|
|
|
blue = tv;
|
|
|
|
break;
|
|
|
|
case 3: // Blue is the dominant color
|
|
|
|
red = pv;
|
|
|
|
green = qv;
|
|
|
|
blue = z;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
red = tv;
|
|
|
|
green = pv;
|
|
|
|
blue = z;
|
|
|
|
break;
|
|
|
|
case 5: // Red is the dominant color
|
|
|
|
red = z;
|
|
|
|
green = pv;
|
|
|
|
blue = qv;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-09 17:01:55 -07:00
|
|
|
|
2009-08-20 17:08:33 -07:00
|
|
|
rgb[0] = red;
|
|
|
|
rgb[1] = green;
|
|
|
|
rgb[2] = blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SC_hsbToAbgr(float h, float s, float b, float a)
|
|
|
|
{
|
2010-05-11 14:03:58 -07:00
|
|
|
//LOGE("hsb a %f, %f, %f %f", h, s, b, a);
|
2009-08-20 17:08:33 -07:00
|
|
|
float rgb[3];
|
|
|
|
SC_hsbToRgb(h, s, b, rgb);
|
2010-05-11 14:03:58 -07:00
|
|
|
//LOGE("rgb %f, %f, %f ", rgb[0], rgb[1], rgb[2]);
|
2009-08-20 17:08:33 -07:00
|
|
|
return int(a * 255.0f) << 24 |
|
|
|
|
int(rgb[2] * 255.0f) << 16 |
|
|
|
|
int(rgb[1] * 255.0f) << 8 |
|
|
|
|
int(rgb[0] * 255.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_hsb(float h, float s, float b, float a)
|
|
|
|
{
|
2009-11-25 13:22:07 -08:00
|
|
|
GET_TLS();
|
2009-08-20 17:08:33 -07:00
|
|
|
float rgb[3];
|
|
|
|
SC_hsbToRgb(h, s, b, rgb);
|
2009-11-25 13:22:07 -08:00
|
|
|
if (rsc->checkVersion2_0()) {
|
|
|
|
glVertexAttrib4f(1, rgb[0], rgb[1], rgb[2], a);
|
|
|
|
} else {
|
|
|
|
glColor4f(rgb[0], rgb[1], rgb[2], a);
|
|
|
|
}
|
2009-07-31 15:33:59 -07:00
|
|
|
}
|
|
|
|
|
2009-07-28 12:02:16 -07:00
|
|
|
static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
|
2009-07-20 14:31:06 -07:00
|
|
|
{
|
|
|
|
GET_TLS();
|
2010-02-23 17:44:28 -08:00
|
|
|
rsi_AllocationUploadToTexture(rsc, va, false, baseMipLevel);
|
2009-07-20 14:31:06 -07:00
|
|
|
}
|
|
|
|
|
2009-08-09 17:01:55 -07:00
|
|
|
static void SC_uploadToBufferObject(RsAllocation va)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
rsi_AllocationUploadToBufferObject(rsc, va);
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:12:28 -08:00
|
|
|
static void SC_syncToGL(RsAllocation va)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
Allocation *a = static_cast<Allocation *>(va);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
static void SC_ClearColor(float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
//LOGE("c %f %f %f %f", r, g, b, a);
|
|
|
|
GET_TLS();
|
|
|
|
sc->mEnviroment.mClearColor[0] = r;
|
|
|
|
sc->mEnviroment.mClearColor[1] = g;
|
|
|
|
sc->mEnviroment.mClearColor[2] = b;
|
|
|
|
sc->mEnviroment.mClearColor[3] = a;
|
|
|
|
}
|
|
|
|
|
2009-07-28 12:02:16 -07:00
|
|
|
static void SC_debugF(const char *s, float f)
|
|
|
|
{
|
|
|
|
LOGE("%s %f", s, f);
|
|
|
|
}
|
|
|
|
|
2009-08-20 17:08:33 -07:00
|
|
|
static void SC_debugHexF(const char *s, float f)
|
|
|
|
{
|
|
|
|
LOGE("%s 0x%x", s, *((int *) (&f)));
|
|
|
|
}
|
|
|
|
|
2009-07-28 12:02:16 -07:00
|
|
|
static void SC_debugI32(const char *s, int32_t i)
|
|
|
|
{
|
|
|
|
LOGE("%s %i", s, i);
|
|
|
|
}
|
|
|
|
|
2009-08-20 17:08:33 -07:00
|
|
|
static void SC_debugHexI32(const char *s, int32_t i)
|
|
|
|
{
|
|
|
|
LOGE("%s 0x%x", s, i);
|
|
|
|
}
|
|
|
|
|
2009-08-10 14:55:26 -07:00
|
|
|
static uint32_t SC_getWidth()
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
return rsc->getWidth();
|
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-08-10 14:55:26 -07:00
|
|
|
static uint32_t SC_getHeight()
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
return rsc->getHeight();
|
|
|
|
}
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static uchar4 SC_convertColorTo8888_f3(float r, float g, float b) {
|
|
|
|
uchar4 t;
|
|
|
|
t.f[0] = (uint8_t)(r * 255.f);
|
|
|
|
t.f[1] = (uint8_t)(g * 255.f);
|
|
|
|
t.f[2] = (uint8_t)(b * 255.f);
|
|
|
|
t.f[3] = 0xff;
|
|
|
|
return t;
|
2009-08-17 13:56:09 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static uchar4 SC_convertColorTo8888_f4(float r, float g, float b, float a) {
|
|
|
|
uchar4 t;
|
|
|
|
t.f[0] = (uint8_t)(r * 255.f);
|
|
|
|
t.f[1] = (uint8_t)(g * 255.f);
|
|
|
|
t.f[2] = (uint8_t)(b * 255.f);
|
|
|
|
t.f[3] = (uint8_t)(a * 255.f);
|
|
|
|
return t;
|
2009-08-17 13:56:09 -07:00
|
|
|
}
|
|
|
|
|
2009-10-06 13:58:47 -07:00
|
|
|
static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
2010-05-11 14:03:58 -07:00
|
|
|
//LOGE("SC_toClient %i %i %i", cmdID, len, waitForSpace);
|
2009-10-06 13:58:47 -07:00
|
|
|
return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0);
|
|
|
|
}
|
|
|
|
|
2009-10-07 18:14:01 -07:00
|
|
|
static void SC_scriptCall(int scriptID)
|
|
|
|
{
|
|
|
|
GET_TLS();
|
|
|
|
rsc->runScript((Script *)scriptID, 0);
|
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
static void SC_debugP(int i, void *p)
|
|
|
|
{
|
|
|
|
LOGE("debug P %i %p, %i", i, p, (int)p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_debugPi(int i, int p)
|
|
|
|
{
|
|
|
|
LOGE("debug Pi %i 0x%08x, %i", i, p, (int)p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_debugPf(int i, float p)
|
|
|
|
{
|
|
|
|
LOGE("debug Pf %i %f, 0x%08x", i, p, reinterpret_cast<uint32_t *>(&p)[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SC_divsi3(int a, int b)
|
|
|
|
{
|
|
|
|
return a / b;
|
|
|
|
}
|
2009-10-07 18:14:01 -07:00
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Class implementation
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
// llvm name mangling ref
|
|
|
|
// <builtin-type> ::= v # void
|
|
|
|
// ::= b # bool
|
|
|
|
// ::= c # char
|
|
|
|
// ::= a # signed char
|
|
|
|
// ::= h # unsigned char
|
|
|
|
// ::= s # short
|
|
|
|
// ::= t # unsigned short
|
|
|
|
// ::= i # int
|
|
|
|
// ::= j # unsigned int
|
|
|
|
// ::= l # long
|
|
|
|
// ::= m # unsigned long
|
|
|
|
// ::= x # long long, __int64
|
|
|
|
// ::= y # unsigned long long, __int64
|
|
|
|
// ::= f # float
|
|
|
|
// ::= d # double
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "__divsi3", (void *)&SC_divsi3 },
|
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
// IO
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "updateSimpleMesh", (void *)&SC_updateSimpleMesh },
|
|
|
|
|
|
|
|
// OpenCL math
|
|
|
|
{ "_Z4acosf", (void *)&acosf },
|
|
|
|
{ "_Z5acoshf", (void *)&acoshf },
|
|
|
|
{ "_Z6acospif", (void *)&SC_acospi },
|
|
|
|
{ "_Z4asinf", (void *)&asinf },
|
|
|
|
{ "_Z5asinhf", (void *)&asinhf },
|
|
|
|
{ "_Z6asinpif", (void *)&SC_asinpi },
|
|
|
|
{ "_Z4atanf", (void *)&atanf },
|
|
|
|
{ "_Z5atan2f", (void *)&atan2f },
|
|
|
|
{ "_Z6atanpif", (void *)&SC_atanpi },
|
|
|
|
{ "_Z7atan2pif", (void *)&SC_atan2pi },
|
|
|
|
{ "_Z4cbrtf", (void *)&cbrtf },
|
|
|
|
{ "_Z4ceilf", (void *)&ceilf },
|
|
|
|
{ "_Z8copysignff", (void *)©signf },
|
|
|
|
{ "_Z3cosf", (void *)&cosf },
|
|
|
|
{ "_Z4coshf", (void *)&coshf },
|
|
|
|
{ "_Z5cospif", (void *)&SC_cospi },
|
|
|
|
{ "_Z4erfcf", (void *)&erfcf },
|
|
|
|
{ "_Z3erff", (void *)&erff },
|
|
|
|
{ "_Z3expf", (void *)&expf },
|
|
|
|
{ "_Z4exp2f", (void *)&exp2f },
|
|
|
|
{ "_Z5exp10f", (void *)&SC_exp10 },
|
|
|
|
{ "_Z5expm1f", (void *)&expm1f },
|
|
|
|
{ "_Z4fabsf", (void *)&fabsf },
|
|
|
|
{ "_Z4fdimff", (void *)&fdimf },
|
|
|
|
{ "_Z5floorf", (void *)&floorf },
|
|
|
|
{ "_Z3fmafff", (void *)&fmaf },
|
|
|
|
{ "_Z4fmaxff", (void *)&fmaxf },
|
|
|
|
{ "_Z4fminff", (void *)&fminf }, // float fmin(float, float)
|
|
|
|
{ "_Z4fmodff", (void *)&fmodf },
|
|
|
|
{ "_Z5fractfPf", (void *)&SC_fract },
|
|
|
|
{ "_Z5frexpfPi", (void *)&frexpf },
|
|
|
|
{ "_Z5hypotff", (void *)&hypotf },
|
|
|
|
{ "_Z5ilogbf", (void *)&ilogbf },
|
|
|
|
{ "_Z5ldexpfi", (void *)&ldexpf },
|
|
|
|
{ "_Z6lgammaf", (void *)&lgammaf },
|
|
|
|
{ "_Z3logf", (void *)&logf },
|
|
|
|
{ "_Z4log2f", (void *)&SC_log2 },
|
|
|
|
{ "_Z5log10f", (void *)&log10f },
|
|
|
|
{ "_Z5log1pf", (void *)&log1pf },
|
|
|
|
//{ "logb", (void *)& },
|
|
|
|
//{ "mad", (void *)& },
|
|
|
|
{ "modf", (void *)&modff },
|
|
|
|
//{ "nan", (void *)& },
|
|
|
|
{ "_Z9nextafterff", (void *)&nextafterf },
|
|
|
|
{ "_Z3powff", (void *)&powf },
|
|
|
|
{ "_Z4pownfi", (void *)&SC_pown },
|
|
|
|
{ "_Z4powrff", (void *)&SC_powr },
|
|
|
|
{ "_Z9remainderff", (void *)&remainderf },
|
|
|
|
{ "remquo", (void *)&remquof },
|
|
|
|
{ "_Z4rintf", (void *)&rintf },
|
|
|
|
{ "_Z5rootnfi", (void *)&SC_rootn },
|
|
|
|
{ "_Z5roundf", (void *)&roundf },
|
|
|
|
{ "_Z5rsqrtf", (void *)&SC_rsqrt },
|
|
|
|
{ "_Z3sinf", (void *)&sinf },
|
|
|
|
{ "sincos", (void *)&SC_sincos },
|
|
|
|
{ "_Z4sinhf", (void *)&sinhf },
|
|
|
|
{ "_Z5sinpif", (void *)&SC_sinpi },
|
|
|
|
{ "_Z4sqrtf", (void *)&sqrtf },
|
|
|
|
{ "_Z3tanf", (void *)&tanf },
|
|
|
|
{ "_Z4tanhf", (void *)&tanhf },
|
|
|
|
{ "_Z5tanpif", (void *)&SC_tanpi },
|
|
|
|
//{ "tgamma", (void *)& },
|
|
|
|
{ "_Z5truncf", (void *)&truncf },
|
|
|
|
|
|
|
|
// OpenCL Int
|
|
|
|
{ "_Z3absi", (void *)&SC_abs_i32 },
|
|
|
|
{ "_Z3abss", (void *)&SC_abs_i16 },
|
|
|
|
{ "_Z3absc", (void *)&SC_abs_i8 },
|
|
|
|
{ "_Z3clzj", (void *)&SC_clz_u32 },
|
|
|
|
{ "_Z3clzt", (void *)&SC_clz_u16 },
|
|
|
|
{ "_Z3clzh", (void *)&SC_clz_u8 },
|
|
|
|
{ "_Z3clzi", (void *)&SC_clz_i32 },
|
|
|
|
{ "_Z3clzs", (void *)&SC_clz_i16 },
|
|
|
|
{ "_Z3clzc", (void *)&SC_clz_i8 },
|
|
|
|
{ "_Z3maxjj", (void *)&SC_max_u32 },
|
|
|
|
{ "_Z3maxtt", (void *)&SC_max_u16 },
|
|
|
|
{ "_Z3maxhh", (void *)&SC_max_u8 },
|
|
|
|
{ "_Z3maxii", (void *)&SC_max_i32 },
|
|
|
|
{ "_Z3maxss", (void *)&SC_max_i16 },
|
|
|
|
{ "_Z3maxcc", (void *)&SC_max_i8 },
|
|
|
|
{ "_Z3minjj", (void *)&SC_min_u32 },
|
|
|
|
{ "_Z3mintt", (void *)&SC_min_u16 },
|
|
|
|
{ "_Z3minhh", (void *)&SC_min_u8 },
|
|
|
|
{ "_Z3minii", (void *)&SC_min_i32 },
|
|
|
|
{ "_Z3minss", (void *)&SC_min_i16 },
|
|
|
|
{ "_Z3mincc", (void *)&SC_min_i8 },
|
|
|
|
|
|
|
|
// OpenCL 6.11.4
|
|
|
|
{ "_Z5clampfff", (void *)&SC_clamp_f32 },
|
|
|
|
{ "_Z7degreesf", (void *)&SC_degrees },
|
|
|
|
{ "_Z3maxff", (void *)&SC_max_f32 },
|
|
|
|
{ "_Z3minff", (void *)&SC_min_f32 },
|
|
|
|
{ "_Z3mixfff", (void *)&SC_mix_f32 },
|
|
|
|
{ "_Z7radiansf", (void *)&SC_radians },
|
|
|
|
{ "_Z4stepff", (void *)&SC_step_f32 },
|
|
|
|
//{ "smoothstep", (void *)& },
|
|
|
|
{ "_Z4signf", (void *)&SC_sign_f32 },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ "modf", (void *)&fmod },
|
|
|
|
{ "_Z4fracf", (void *)&SC_frac },
|
|
|
|
//{ "sinf_fast", (void *)&SC_sinf_fast },
|
|
|
|
//{ "cosf_fast", (void *)&SC_cosf_fast },
|
|
|
|
{ "randf", (void *)&SC_randf },
|
|
|
|
{ "randf2", (void *)&SC_randf2 },
|
|
|
|
{ "sign", (void *)&SC_sign },
|
|
|
|
{ "clamp", (void *)&SC_clamp },
|
|
|
|
{ "distf2", (void *)&SC_distf2 },
|
|
|
|
{ "distf3", (void *)&SC_distf3 },
|
|
|
|
{ "magf2", (void *)&SC_magf2 },
|
|
|
|
{ "magf3", (void *)&SC_magf3 },
|
|
|
|
{ "normf", (void *)&SC_normf },
|
|
|
|
{ "mapf", (void *)&SC_mapf },
|
|
|
|
{ "noisef", (void *)&SC_noisef },
|
|
|
|
{ "noisef2", (void *)&SC_noisef2 },
|
|
|
|
{ "noisef3", (void *)&SC_noisef3 },
|
|
|
|
{ "turbulencef2", (void *)&SC_turbulencef2 },
|
|
|
|
{ "turbulencef3", (void *)&SC_turbulencef3 },
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-07-30 18:45:01 -07:00
|
|
|
// time
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "second", (void *)&SC_second },
|
|
|
|
{ "minute", (void *)&SC_minute },
|
|
|
|
{ "hour", (void *)&SC_hour },
|
|
|
|
{ "day", (void *)&SC_day },
|
|
|
|
{ "month", (void *)&SC_month },
|
|
|
|
{ "year", (void *)&SC_year },
|
|
|
|
{ "uptimeMillis", (void*)&SC_uptimeMillis }, // TODO: use long instead
|
|
|
|
{ "startTimeMillis", (void*)&SC_startTimeMillis }, // TODO: use long instead
|
|
|
|
{ "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis }, // TODO: use long instead
|
2009-07-30 18:45:01 -07:00
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
// matrix
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity },
|
|
|
|
{ "matrixLoadFloat", (void *)&SC_matrixLoadFloat },
|
|
|
|
{ "matrixLoadMat", (void *)&SC_matrixLoadMat },
|
|
|
|
{ "matrixLoadRotate", (void *)&SC_matrixLoadRotate },
|
|
|
|
{ "matrixLoadScale", (void *)&SC_matrixLoadScale },
|
|
|
|
{ "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate },
|
|
|
|
{ "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply },
|
|
|
|
{ "matrixMultiply", (void *)&SC_matrixMultiply },
|
|
|
|
{ "matrixRotate", (void *)&SC_matrixRotate },
|
|
|
|
{ "matrixScale", (void *)&SC_matrixScale },
|
|
|
|
{ "matrixTranslate", (void *)&SC_matrixTranslate },
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-08-17 13:56:09 -07:00
|
|
|
// vector
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "vec2Rand", (void *)&SC_vec2Rand },
|
2009-08-17 13:56:09 -07:00
|
|
|
|
2009-09-04 14:42:41 -07:00
|
|
|
// vec3
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "vec3Norm", (void *)&SC_vec3Norm },
|
|
|
|
{ "vec3Length", (void *)&SC_vec3Length },
|
|
|
|
{ "vec3Add", (void *)&SC_vec3Add },
|
|
|
|
{ "vec3Sub", (void *)&SC_vec3Sub },
|
|
|
|
{ "vec3Cross", (void *)&SC_vec3Cross },
|
|
|
|
{ "vec3Dot", (void *)&SC_vec3Dot },
|
|
|
|
{ "vec3Scale", (void *)&SC_vec3Scale },
|
2009-09-04 14:42:41 -07:00
|
|
|
|
2009-10-09 16:05:25 -07:00
|
|
|
// vec4
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "vec4Norm", (void *)&SC_vec4Norm },
|
|
|
|
{ "vec4Length", (void *)&SC_vec4Length },
|
|
|
|
{ "vec4Add", (void *)&SC_vec4Add },
|
|
|
|
{ "vec4Sub", (void *)&SC_vec4Sub },
|
|
|
|
{ "vec4Dot", (void *)&SC_vec4Dot },
|
|
|
|
{ "vec4Scale", (void *)&SC_vec4Scale },
|
2009-10-09 16:05:25 -07:00
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
// context
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "bindProgramFragment", (void *)&SC_bindProgramFragment },
|
2010-05-13 18:30:11 -07:00
|
|
|
{ "bindProgramStore", (void *)&SC_bindProgramStore },
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "bindProgramVertex", (void *)&SC_bindProgramVertex },
|
2010-05-12 18:26:52 -07:00
|
|
|
{ "bindProgramRaster", (void *)&SC_bindProgramRaster },
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "bindSampler", (void *)&SC_bindSampler },
|
|
|
|
{ "bindTexture", (void *)&SC_bindTexture },
|
2009-07-20 14:31:06 -07:00
|
|
|
|
2009-07-28 12:02:16 -07:00
|
|
|
// vp
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix },
|
|
|
|
{ "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix },
|
2009-07-28 12:02:16 -07:00
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
// allocation
|
|
|
|
{ "allocGetDimX", (void *)&SC_allocGetDimX },
|
|
|
|
{ "allocGetDimY", (void *)&SC_allocGetDimY },
|
|
|
|
{ "allocGetDimZ", (void *)&SC_allocGetDimZ },
|
|
|
|
{ "allocGetDimLOD", (void *)&SC_allocGetDimLOD },
|
|
|
|
{ "allocGetDimFaces", (void *)&SC_allocGetDimFaces },
|
2009-07-28 12:02:16 -07:00
|
|
|
|
2009-07-20 14:31:06 -07:00
|
|
|
// drawing
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "drawRect", (void *)&SC_drawRect },
|
|
|
|
{ "drawQuad", (void *)&SC_drawQuad },
|
|
|
|
{ "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords },
|
|
|
|
{ "drawSprite", (void *)&SC_drawSprite },
|
|
|
|
{ "drawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace },
|
|
|
|
{ "drawSpriteScreenspaceCropped", (void *)&SC_drawSpriteScreenspaceCropped },
|
|
|
|
{ "drawLine", (void *)&SC_drawLine },
|
|
|
|
{ "drawPoint", (void *)&SC_drawPoint },
|
|
|
|
{ "drawSimpleMesh", (void *)&SC_drawSimpleMesh },
|
|
|
|
{ "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange },
|
2009-07-20 14:31:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
// misc
|
2010-05-11 14:03:58 -07:00
|
|
|
{ "pfClearColor", (void *)&SC_ClearColor },
|
|
|
|
{ "color", (void *)&SC_color },
|
|
|
|
{ "hsb", (void *)&SC_hsb },
|
|
|
|
{ "hsbToRgb", (void *)&SC_hsbToRgb },
|
|
|
|
{ "hsbToAbgr", (void *)&SC_hsbToAbgr },
|
|
|
|
{ "pointAttenuation", (void *)&SC_pointAttenuation },
|
|
|
|
|
|
|
|
{ "uploadToTexture", (void *)&SC_uploadToTexture },
|
|
|
|
{ "uploadToBufferObject", (void *)&SC_uploadToBufferObject },
|
|
|
|
|
|
|
|
{ "syncToGL", (void *)&SC_syncToGL },
|
|
|
|
|
|
|
|
{ "getWidth", (void *)&SC_getWidth },
|
|
|
|
{ "getHeight", (void *)&SC_getHeight },
|
|
|
|
|
|
|
|
{ "sendToClient", (void *)&SC_toClient },
|
|
|
|
|
|
|
|
{ "_Z18convertColorTo8888fff", (void *)&SC_convertColorTo8888_f3 },
|
|
|
|
{ "_Z18convertColorTo8888ffff", (void *)&SC_convertColorTo8888_f4 },
|
|
|
|
|
|
|
|
{ "debugF", (void *)&SC_debugF },
|
|
|
|
{ "debugI32", (void *)&SC_debugI32 },
|
|
|
|
{ "debugHexF", (void *)&SC_debugHexF },
|
|
|
|
{ "debugHexI32", (void *)&SC_debugHexI32 },
|
|
|
|
{ "debugP", (void *)&SC_debugP },
|
|
|
|
{ "debugPf", (void *)&SC_debugPf },
|
|
|
|
{ "debugPi", (void *)&SC_debugPi },
|
|
|
|
|
|
|
|
{ "scriptCall", (void *)&SC_scriptCall },
|
|
|
|
|
|
|
|
{ NULL, NULL }
|
2009-07-20 14:31:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
|
|
|
|
{
|
|
|
|
ScriptCState::SymbolTable_t *syms = gSyms;
|
|
|
|
|
|
|
|
while (syms->mPtr) {
|
|
|
|
if (!strcmp(syms->mName, sym)) {
|
|
|
|
return syms;
|
|
|
|
}
|
|
|
|
syms++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|