summaryrefslogtreecommitdiffstats
path: root/libs/rs
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs')
-rw-r--r--libs/rs/Android.mk22
-rw-r--r--libs/rs/RenderScript.h3
-rw-r--r--libs/rs/rsAdapter.cpp4
-rw-r--r--libs/rs/rsAllocation.cpp49
-rw-r--r--libs/rs/rsAnimation.cpp5
-rw-r--r--libs/rs/rsComponent.cpp9
-rw-r--r--libs/rs/rsContext.h50
-rw-r--r--libs/rs/rsContextHostStub.h159
-rw-r--r--libs/rs/rsDevice.cpp4
-rw-r--r--libs/rs/rsElement.cpp8
-rw-r--r--libs/rs/rsFileA3D.cpp23
-rw-r--r--libs/rs/rsFont.cpp4
-rw-r--r--libs/rs/rsMesh.cpp185
-rw-r--r--libs/rs/rsMesh.h16
-rw-r--r--libs/rs/rsObjectBase.cpp6
-rw-r--r--libs/rs/rsProgram.cpp8
-rw-r--r--libs/rs/rsProgramFragment.cpp8
-rw-r--r--libs/rs/rsProgramRaster.cpp8
-rw-r--r--libs/rs/rsProgramStore.cpp8
-rw-r--r--libs/rs/rsProgramVertex.cpp8
-rw-r--r--libs/rs/rsSampler.cpp10
-rw-r--r--libs/rs/rsScriptC.cpp7
-rw-r--r--libs/rs/rsShaderCache.cpp7
-rw-r--r--libs/rs/rsStream.cpp5
-rw-r--r--libs/rs/rsType.cpp8
-rw-r--r--libs/rs/rsUtils.h2
-rw-r--r--libs/rs/rsVertexArray.cpp5
-rw-r--r--libs/rs/scriptc/rs_core.rsh250
-rw-r--r--libs/rs/scriptc/rs_types.rsh2
29 files changed, 484 insertions, 399 deletions
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 3835852..25c8beb 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -130,6 +130,28 @@ LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
+# Now build a host version for serialization
+include $(CLEAR_VARS)
+LOCAL_CFLAGS += -DANDROID_RS_SERIALIZE
+
+LOCAL_SRC_FILES:= \
+ rsAllocation.cpp \
+ rsComponent.cpp \
+ rsElement.cpp \
+ rsFileA3D.cpp \
+ rsObjectBase.cpp \
+ rsMesh.cpp \
+ rsStream.cpp \
+ rsType.cpp
+
+LOCAL_STATIC_LIBRARIES := libcutils libutils
+
+LOCAL_LDLIBS := -lpthread
+LOCAL_MODULE:= libRSserialize
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_STATIC_LIBRARY)
+
# include the java examples
include $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk,\
java \
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index f160ef1..bb5e4aa 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -365,6 +365,9 @@ RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
RsAllocationMipmapControl mips,
const void *data, uint32_t usages);
+#ifdef ANDROID_RS_SERIALIZE
+#define NO_RS_FUNCS
+#endif
#ifndef NO_RS_FUNCS
#include "rsgApiFuncDecl.h"
diff --git a/libs/rs/rsAdapter.cpp b/libs/rs/rsAdapter.cpp
index 8d363fd..6e8ca70 100644
--- a/libs/rs/rsAdapter.cpp
+++ b/libs/rs/rsAdapter.cpp
@@ -15,11 +15,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#else
-#include "rsContextHostStub.h"
-#endif
using namespace android;
using namespace android::renderscript;
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index c598f03..54dcbcb 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -13,20 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
-#include "rsContext.h"
+#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES/glext.h>
-#else
-#include "rsContextHostStub.h"
-
-#include <OpenGL/gl.h>
-#include <OpenGl/glext.h>
-#endif
-
-#include "utils/StopWatch.h"
+#endif //ANDROID_RS_SERIALIZE
static void rsaAllocationGenerateScriptMips(RsContext con, RsAllocation va);
@@ -83,7 +76,7 @@ Allocation::~Allocation() {
mPtr = NULL;
}
freeScriptMemory();
-
+#ifndef ANDROID_RS_SERIALIZE
if (mBufferID) {
// Causes a SW crash....
//LOGV(" mBufferID %i", mBufferID);
@@ -94,6 +87,7 @@ Allocation::~Allocation() {
glDeleteTextures(1, &mTextureID);
mTextureID = 0;
}
+#endif //ANDROID_RS_SERIALIZE
}
void Allocation::setCpuWritable(bool) {
@@ -118,6 +112,7 @@ void Allocation::deferedUploadToTexture(const Context *rsc) {
}
uint32_t Allocation::getGLTarget() const {
+#ifndef ANDROID_RS_SERIALIZE
if (getIsTexture()) {
if (mType->getDimFaces()) {
return GL_TEXTURE_CUBE_MAP;
@@ -128,6 +123,7 @@ uint32_t Allocation::getGLTarget() const {
if (getIsBufferObject()) {
return GL_ARRAY_BUFFER;
}
+#endif //ANDROID_RS_SERIALIZE
return 0;
}
@@ -158,7 +154,7 @@ void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) {
}
void Allocation::uploadToTexture(const Context *rsc) {
-
+#ifndef ANDROID_RS_SERIALIZE
mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE;
GLenum type = mType->getElement()->getComponent().getGLType();
GLenum format = mType->getElement()->getComponent().getGLFormat();
@@ -195,8 +191,10 @@ void Allocation::uploadToTexture(const Context *rsc) {
}
rsc->checkError("Allocation::uploadToTexture");
+#endif //ANDROID_RS_SERIALIZE
}
+#ifndef ANDROID_RS_SERIALIZE
const static GLenum gFaceOrder[] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
@@ -205,10 +203,12 @@ const static GLenum gFaceOrder[] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
+#endif //ANDROID_RS_SERIALIZE
void Allocation::update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
uint32_t lod, RsAllocationCubemapFace face,
uint32_t w, uint32_t h) {
+#ifndef ANDROID_RS_SERIALIZE
GLenum type = mType->getElement()->getComponent().getGLType();
GLenum format = mType->getElement()->getComponent().getGLFormat();
GLenum target = (GLenum)getGLTarget();
@@ -220,9 +220,11 @@ void Allocation::update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
t = gFaceOrder[face];
}
glTexSubImage2D(t, lod, xoff, yoff, w, h, format, type, ptr);
+#endif //ANDROID_RS_SERIALIZE
}
void Allocation::upload2DTexture(bool isFirstUpload) {
+#ifndef ANDROID_RS_SERIALIZE
GLenum type = mType->getElement()->getComponent().getGLType();
GLenum format = mType->getElement()->getComponent().getGLFormat();
@@ -258,10 +260,9 @@ void Allocation::upload2DTexture(bool isFirstUpload) {
}
if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) {
-#ifndef ANDROID_RS_BUILD_FOR_HOST
glGenerateMipmap(target);
-#endif //ANDROID_RS_BUILD_FOR_HOST
}
+#endif //ANDROID_RS_SERIALIZE
}
void Allocation::deferedUploadToBufferObject(const Context *rsc) {
@@ -270,6 +271,7 @@ void Allocation::deferedUploadToBufferObject(const Context *rsc) {
}
void Allocation::uploadToBufferObject(const Context *rsc) {
+#ifndef ANDROID_RS_SERIALIZE
rsAssert(!mType->getDimY());
rsAssert(!mType->getDimZ());
@@ -288,6 +290,7 @@ void Allocation::uploadToBufferObject(const Context *rsc) {
glBufferData(target, mType->getSizeBytes(), getPtr(), GL_DYNAMIC_DRAW);
glBindBuffer(target, 0);
rsc->checkError("Allocation::uploadToBufferObject");
+#endif //ANDROID_RS_SERIALIZE
}
void Allocation::uploadCheck(Context *rsc) {
@@ -386,7 +389,7 @@ void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
ptr += mType->getElement()->getFieldOffsetBytes(cIdx);
if (sizeBytes != e->getSizeBytes()) {
- LOGE("Error Allocation::subElementData data size %i does not match field size %i.", sizeBytes, e->getSizeBytes());
+ LOGE("Error Allocation::subElementData data size %i does not match field size %zu.", sizeBytes, e->getSizeBytes());
rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
return;
}
@@ -429,7 +432,7 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
ptr += mType->getElement()->getFieldOffsetBytes(cIdx);
if (sizeBytes != e->getSizeBytes()) {
- LOGE("Error Allocation::subElementData data size %i does not match field size %i.", sizeBytes, e->getSizeBytes());
+ LOGE("Error Allocation::subElementData data size %i does not match field size %zu.", sizeBytes, e->getSizeBytes());
rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
return;
}
@@ -445,10 +448,13 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
}
void Allocation::addProgramToDirty(const Program *p) {
+#ifndef ANDROID_RS_SERIALIZE
mToDirtyList.push(p);
+#endif //ANDROID_RS_SERIALIZE
}
void Allocation::removeProgramToDirty(const Program *p) {
+#ifndef ANDROID_RS_SERIALIZE
for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
if (mToDirtyList[ct] == p) {
mToDirtyList.removeAt(ct);
@@ -456,6 +462,7 @@ void Allocation::removeProgramToDirty(const Program *p) {
}
}
rsAssert(0);
+#endif //ANDROID_RS_SERIALIZE
}
void Allocation::dumpLOGV(const char *prefix) const {
@@ -530,9 +537,11 @@ Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) {
}
void Allocation::sendDirty() const {
+#ifndef ANDROID_RS_SERIALIZE
for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
mToDirtyList[ct]->forceDirty();
}
+#endif //ANDROID_RS_SERIALIZE
}
void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const {
@@ -591,7 +600,7 @@ void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) {
/////////////////
//
-
+#ifndef ANDROID_RS_SERIALIZE
namespace android {
namespace renderscript {
@@ -674,8 +683,6 @@ static void mip(const Adapter2D &out, const Adapter2D &in) {
}
}
-#ifndef ANDROID_RS_BUILD_FOR_HOST
-
void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) {
Allocation *a = static_cast<Allocation *>(va);
a->syncAll(rsc, src);
@@ -739,8 +746,6 @@ void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32
a->resize2D(rsc, dimX, dimY);
}
-#endif //ANDROID_RS_BUILD_FOR_HOST
-
}
}
@@ -840,3 +845,5 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
texAlloc->deferedUploadToTexture(rsc);
return texAlloc;
}
+
+#endif //ANDROID_RS_SERIALIZE
diff --git a/libs/rs/rsAnimation.cpp b/libs/rs/rsAnimation.cpp
index 6abda3c..48b4f02 100644
--- a/libs/rs/rsAnimation.cpp
+++ b/libs/rs/rsAnimation.cpp
@@ -14,12 +14,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#else
-#include "rsContextHostStub.h"
-#endif //ANDROID_RS_BUILD_FOR_HOST
-
#include "rsAnimation.h"
diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp
index 81ade5d..4c4987a 100644
--- a/libs/rs/rsComponent.cpp
+++ b/libs/rs/rsComponent.cpp
@@ -16,10 +16,8 @@
#include "rsComponent.h"
-#ifndef ANDROID_RS_BUILD_FOR_HOST
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
-#else
-#include <OpenGL/gl.h>
#endif
using namespace android;
@@ -183,6 +181,7 @@ bool Component::isReference() const {
}
uint32_t Component::getGLType() const {
+#ifndef ANDROID_RS_SERIALIZE
switch (mType) {
case RS_TYPE_UNSIGNED_5_6_5: return GL_UNSIGNED_SHORT_5_6_5;
case RS_TYPE_UNSIGNED_5_5_5_1: return GL_UNSIGNED_SHORT_5_5_5_1;
@@ -196,11 +195,12 @@ uint32_t Component::getGLType() const {
case RS_TYPE_SIGNED_16: return GL_SHORT;
default: break;
}
-
+#endif //ANDROID_RS_SERIALIZE
return 0;
}
uint32_t Component::getGLFormat() const {
+#ifndef ANDROID_RS_SERIALIZE
switch (mKind) {
case RS_KIND_PIXEL_L: return GL_LUMINANCE;
case RS_KIND_PIXEL_A: return GL_ALPHA;
@@ -209,6 +209,7 @@ uint32_t Component::getGLFormat() const {
case RS_KIND_PIXEL_RGBA: return GL_RGBA;
default: break;
}
+#endif //ANDROID_RS_SERIALIZE
return 0;
}
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 9f94f26..c5e32a6 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -18,16 +18,16 @@
#define ANDROID_RS_CONTEXT_H
#include "rsUtils.h"
-#include "rsMutex.h"
-
-#include "rsThreadIO.h"
#include "rsType.h"
-#include "rsMatrix.h"
#include "rsAllocation.h"
#include "rsMesh.h"
+
+#ifndef ANDROID_RS_SERIALIZE
+#include "rsMutex.h"
+#include "rsThreadIO.h"
+#include "rsMatrix.h"
#include "rsDevice.h"
#include "rsScriptC.h"
-#include "rsAllocation.h"
#include "rsAdapter.h"
#include "rsSampler.h"
#include "rsFont.h"
@@ -42,6 +42,7 @@
#include "rsLocklessFifo.h"
#include <ui/egl/android_natives.h>
+#endif // ANDROID_RS_SERIALIZE
// ---------------------------------------------------------------------------
namespace android {
@@ -66,6 +67,8 @@ namespace renderscript {
#define CHECK_OBJ_OR_NULL(o)
#endif
+#ifndef ANDROID_RS_SERIALIZE
+
class Context {
public:
static Context * createContext(Device *, const RsSurfaceConfig *sc);
@@ -321,6 +324,39 @@ private:
uint32_t mAverageFPS;
};
-}
-}
+#else
+
+class Context {
+public:
+ Context() {
+ mObjHead = NULL;
+ }
+ ~Context() {
+ ObjectBase::zeroAllUserRef(this);
+ }
+
+ ElementState mStateElement;
+ TypeState mStateType;
+
+ struct {
+ bool mLogTimes;
+ bool mLogScripts;
+ bool mLogObjects;
+ bool mLogShaders;
+ bool mLogShadersAttr;
+ bool mLogShadersUniforms;
+ bool mLogVisual;
+ } props;
+
+ void setError(RsError e, const char *msg = NULL) { }
+
+ mutable const ObjectBase * mObjHead;
+
+protected:
+
+};
+#endif //ANDROID_RS_SERIALIZE
+
+} // renderscript
+} // android
#endif
diff --git a/libs/rs/rsContextHostStub.h b/libs/rs/rsContextHostStub.h
deleted file mode 100644
index 8cfb38b..0000000
--- a/libs/rs/rsContextHostStub.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef ANDROID_RS_CONTEXT_HOST_STUB_H
-#define ANDROID_RS_CONTEXT_HOST_STUB_H
-
-#include "rsUtils.h"
-//#include "rsMutex.h"
-
-//#include "rsThreadIO.h"
-#include "rsType.h"
-#include "rsMatrix.h"
-#include "rsAllocation.h"
-#include "rsMesh.h"
-//#include "rsDevice.h"
-#include "rsScriptC.h"
-#include "rsAllocation.h"
-#include "rsAdapter.h"
-#include "rsSampler.h"
-#include "rsProgramFragment.h"
-#include "rsProgramStore.h"
-#include "rsProgramRaster.h"
-#include "rsProgramVertex.h"
-#include "rsShaderCache.h"
-#include "rsVertexArray.h"
-
-//#include "rsgApiStructs.h"
-//#include "rsLocklessFifo.h"
-
-//#include <ui/egl/android_natives.h>
-
-// ---------------------------------------------------------------------------
-namespace android {
-namespace renderscript {
-
-class Device;
-
-class Context {
-public:
- Context(Device *, bool isGraphics, bool useDepth) {
- mObjHead = NULL;
- }
- ~Context() {
- }
-
-
- //StructuredAllocationContext mStateAllocation;
- ElementState mStateElement;
- TypeState mStateType;
- SamplerState mStateSampler;
- //ProgramFragmentState mStateFragment;
- ProgramStoreState mStateFragmentStore;
- //ProgramRasterState mStateRaster;
- //ProgramVertexState mStateVertex;
- VertexArrayState mStateVertexArray;
-
- //ScriptCState mScriptC;
- ShaderCache mShaderCache;
-
- RsSurfaceConfig mUserSurfaceConfig;
-
- //bool setupCheck();
-
- ProgramFragment * getDefaultProgramFragment() const {
- return NULL;
- }
- ProgramVertex * getDefaultProgramVertex() const {
- return NULL;
- }
- ProgramStore * getDefaultProgramStore() const {
- return NULL;
- }
- ProgramRaster * getDefaultProgramRaster() const {
- return NULL;
- }
-
- uint32_t getWidth() const {return 0;}
- uint32_t getHeight() const {return 0;}
-
- // Timers
- enum Timers {
- RS_TIMER_IDLE,
- RS_TIMER_INTERNAL,
- RS_TIMER_SCRIPT,
- RS_TIMER_CLEAR_SWAP,
- _RS_TIMER_TOTAL
- };
-
- bool checkVersion1_1() const {return false; }
- bool checkVersion2_0() const {return false; }
-
- struct {
- bool mLogTimes;
- bool mLogScripts;
- bool mLogObjects;
- bool mLogShaders;
- bool mLogShadersAttr;
- bool mLogShadersUniforms;
- bool mLogVisual;
- } props;
-
- void dumpDebug() const { }
- void checkError(const char *) const { };
- void setError(RsError e, const char *msg = NULL) { }
-
- mutable const ObjectBase * mObjHead;
-
- bool ext_OES_texture_npot() const {return mGL.OES_texture_npot;}
- bool ext_GL_NV_texture_npot_2D_mipmap() const {return mGL.GL_NV_texture_npot_2D_mipmap;}
- float ext_texture_max_aniso() const {return mGL.EXT_texture_max_aniso; }
- uint32_t getMaxFragmentTextures() const {return mGL.mMaxFragmentTextureImageUnits;}
- uint32_t getMaxFragmentUniformVectors() const {return mGL.mMaxFragmentUniformVectors;}
- uint32_t getMaxVertexUniformVectors() const {return mGL.mMaxVertexUniformVectors;}
- uint32_t getMaxVertexAttributes() const {return mGL.mMaxVertexAttribs;}
-
-protected:
-
- struct {
- const uint8_t * mVendor;
- const uint8_t * mRenderer;
- const uint8_t * mVersion;
- const uint8_t * mExtensions;
-
- uint32_t mMajorVersion;
- uint32_t mMinorVersion;
-
- int32_t mMaxVaryingVectors;
- int32_t mMaxTextureImageUnits;
-
- int32_t mMaxFragmentTextureImageUnits;
- int32_t mMaxFragmentUniformVectors;
-
- int32_t mMaxVertexAttribs;
- int32_t mMaxVertexUniformVectors;
- int32_t mMaxVertexTextureUnits;
-
- bool OES_texture_npot;
- bool GL_NV_texture_npot_2D_mipmap;
- float EXT_texture_max_aniso;
- } mGL;
-
-};
-
-}
-}
-#endif
diff --git a/libs/rs/rsDevice.cpp b/libs/rs/rsDevice.cpp
index dd96445..d7d03f6 100644
--- a/libs/rs/rsDevice.cpp
+++ b/libs/rs/rsDevice.cpp
@@ -15,11 +15,7 @@
*/
#include "rsDevice.h"
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#else
-#include "rsContextHostStub.h"
-#endif
using namespace android;
using namespace android::renderscript;
diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp
index 6ae8bb8..477cb61 100644
--- a/libs/rs/rsElement.cpp
+++ b/libs/rs/rsElement.cpp
@@ -15,13 +15,7 @@
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#include <GLES/gl.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#endif
using namespace android;
using namespace android::renderscript;
@@ -65,7 +59,7 @@ size_t Element::getSizeBits() const {
void Element::dumpLOGV(const char *prefix) const {
ObjectBase::dumpLOGV(prefix);
- LOGV("%s Element: fieldCount: %i, size bytes: %i", prefix, mFieldCount, getSizeBytes());
+ LOGV("%s Element: fieldCount: %zu, size bytes: %zu", prefix, mFieldCount, getSizeBytes());
for (uint32_t ct = 0; ct < mFieldCount; ct++) {
LOGV("%s Element field index: %u ------------------", prefix, ct);
LOGV("%s name: %s, offsetBits: %u, arraySize: %u",
diff --git a/libs/rs/rsFileA3D.cpp b/libs/rs/rsFileA3D.cpp
index d34ddd6..cd02c24 100644
--- a/libs/rs/rsFileA3D.cpp
+++ b/libs/rs/rsFileA3D.cpp
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#else
-#include "rsContextHostStub.h"
-#endif
-
#include "rsFileA3D.h"
#include "rsMesh.h"
@@ -249,31 +244,31 @@ ObjectBase *FileA3D::initializeFromEntry(size_t index) {
entry->mRsObj = Allocation::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_PROGRAM_VERTEX:
- entry->mRsObj = ProgramVertex::createFromStream(mRSC, mReadStream);
+ //entry->mRsObj = ProgramVertex::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_PROGRAM_RASTER:
- entry->mRsObj = ProgramRaster::createFromStream(mRSC, mReadStream);
+ //entry->mRsObj = ProgramRaster::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_PROGRAM_FRAGMENT:
- entry->mRsObj = ProgramFragment::createFromStream(mRSC, mReadStream);
+ //entry->mRsObj = ProgramFragment::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_PROGRAM_STORE:
- entry->mRsObj = ProgramStore::createFromStream(mRSC, mReadStream);
+ //entry->mRsObj = ProgramStore::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_SAMPLER:
- entry->mRsObj = Sampler::createFromStream(mRSC, mReadStream);
+ //entry->mRsObj = Sampler::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_ANIMATION:
- entry->mRsObj = Animation::createFromStream(mRSC, mReadStream);
+ //entry->mRsObj = Animation::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_ADAPTER_1D:
- entry->mRsObj = Adapter1D::createFromStream(mRSC, mReadStream);
+ //entry->mRsObj = Adapter1D::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_ADAPTER_2D:
- entry->mRsObj = Adapter2D::createFromStream(mRSC, mReadStream);
+ //entry->mRsObj = Adapter2D::createFromStream(mRSC, mReadStream);
break;
case RS_A3D_CLASS_ID_SCRIPT_C:
- return NULL;
+ break;
}
if (entry->mRsObj) {
entry->mRsObj->incUserRef();
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index 7fdfbe0..8a5ab99 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -15,11 +15,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#else
-#include "rsContextHostStub.h"
-#endif
#include "rsFont.h"
#include "rsProgramFragment.h"
diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp
index baf4c53..76fe62d 100644
--- a/libs/rs/rsMesh.cpp
+++ b/libs/rs/rsMesh.cpp
@@ -14,17 +14,11 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES/glext.h>
-#else
-#include "rsContextHostStub.h"
-
-#include <OpenGL/gl.h>
-#include <OpenGl/glext.h>
#endif
using namespace android;
@@ -35,10 +29,13 @@ Mesh::Mesh(Context *rsc) : ObjectBase(rsc) {
mPrimitivesCount = 0;
mVertexBuffers = NULL;
mVertexBufferCount = 0;
+
+#ifndef ANDROID_RS_SERIALIZE
mAttribs = NULL;
mAttribAllocationIndex = NULL;
mAttribCount = 0;
+#endif
}
Mesh::~Mesh() {
@@ -53,12 +50,97 @@ Mesh::~Mesh() {
delete[] mPrimitives;
}
+#ifndef ANDROID_RS_SERIALIZE
if (mAttribs) {
delete[] mAttribs;
delete[] mAttribAllocationIndex;
}
+#endif
+}
+
+void Mesh::serialize(OStream *stream) const {
+ // Need to identify ourselves
+ stream->addU32((uint32_t)getClassId());
+
+ String8 name(getName());
+ stream->addString(&name);
+
+ // Store number of vertex streams
+ stream->addU32(mVertexBufferCount);
+ for (uint32_t vCount = 0; vCount < mVertexBufferCount; vCount ++) {
+ mVertexBuffers[vCount]->serialize(stream);
+ }
+
+ stream->addU32(mPrimitivesCount);
+ // Store the primitives
+ for (uint32_t pCount = 0; pCount < mPrimitivesCount; pCount ++) {
+ Primitive_t * prim = mPrimitives[pCount];
+
+ stream->addU8((uint8_t)prim->mPrimitive);
+
+ if (prim->mIndexBuffer.get()) {
+ stream->addU32(1);
+ prim->mIndexBuffer->serialize(stream);
+ } else {
+ stream->addU32(0);
+ }
+ }
}
+Mesh *Mesh::createFromStream(Context *rsc, IStream *stream) {
+ // First make sure we are reading the correct object
+ RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
+ if (classID != RS_A3D_CLASS_ID_MESH) {
+ LOGE("mesh loading skipped due to invalid class id");
+ return NULL;
+ }
+
+ Mesh * mesh = new Mesh(rsc);
+
+ String8 name;
+ stream->loadString(&name);
+ mesh->setName(name.string(), name.size());
+
+ mesh->mVertexBufferCount = stream->loadU32();
+ if (mesh->mVertexBufferCount) {
+ mesh->mVertexBuffers = new ObjectBaseRef<Allocation>[mesh->mVertexBufferCount];
+
+ for (uint32_t vCount = 0; vCount < mesh->mVertexBufferCount; vCount ++) {
+ Allocation *vertexAlloc = Allocation::createFromStream(rsc, stream);
+ mesh->mVertexBuffers[vCount].set(vertexAlloc);
+ }
+ }
+
+ mesh->mPrimitivesCount = stream->loadU32();
+ if (mesh->mPrimitivesCount) {
+ mesh->mPrimitives = new Primitive_t *[mesh->mPrimitivesCount];
+
+ // load all primitives
+ for (uint32_t pCount = 0; pCount < mesh->mPrimitivesCount; pCount ++) {
+ Primitive_t * prim = new Primitive_t;
+ mesh->mPrimitives[pCount] = prim;
+
+ prim->mPrimitive = (RsPrimitive)stream->loadU8();
+
+ // Check to see if the index buffer was stored
+ uint32_t isIndexPresent = stream->loadU32();
+ if (isIndexPresent) {
+ Allocation *indexAlloc = Allocation::createFromStream(rsc, stream);
+ prim->mIndexBuffer.set(indexAlloc);
+ }
+ }
+ }
+
+#ifndef ANDROID_RS_SERIALIZE
+ mesh->updateGLPrimitives();
+ mesh->initVertexAttribs();
+ mesh->uploadAll(rsc);
+#endif
+ return mesh;
+}
+
+#ifndef ANDROID_RS_SERIALIZE
+
bool Mesh::isValidGLComponent(const Element *elem, uint32_t fieldIdx) {
// Do not create attribs for padding
if (elem->getFieldName(fieldIdx)[0] == '#') {
@@ -224,86 +306,6 @@ void Mesh::updateGLPrimitives() {
}
}
-void Mesh::serialize(OStream *stream) const {
- // Need to identify ourselves
- stream->addU32((uint32_t)getClassId());
-
- String8 name(getName());
- stream->addString(&name);
-
- // Store number of vertex streams
- stream->addU32(mVertexBufferCount);
- for (uint32_t vCount = 0; vCount < mVertexBufferCount; vCount ++) {
- mVertexBuffers[vCount]->serialize(stream);
- }
-
- stream->addU32(mPrimitivesCount);
- // Store the primitives
- for (uint32_t pCount = 0; pCount < mPrimitivesCount; pCount ++) {
- Primitive_t * prim = mPrimitives[pCount];
-
- stream->addU8((uint8_t)prim->mPrimitive);
-
- if (prim->mIndexBuffer.get()) {
- stream->addU32(1);
- prim->mIndexBuffer->serialize(stream);
- } else {
- stream->addU32(0);
- }
- }
-}
-
-Mesh *Mesh::createFromStream(Context *rsc, IStream *stream) {
- // First make sure we are reading the correct object
- RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
- if (classID != RS_A3D_CLASS_ID_MESH) {
- LOGE("mesh loading skipped due to invalid class id");
- return NULL;
- }
-
- Mesh * mesh = new Mesh(rsc);
-
- String8 name;
- stream->loadString(&name);
- mesh->setName(name.string(), name.size());
-
- mesh->mVertexBufferCount = stream->loadU32();
- if (mesh->mVertexBufferCount) {
- mesh->mVertexBuffers = new ObjectBaseRef<Allocation>[mesh->mVertexBufferCount];
-
- for (uint32_t vCount = 0; vCount < mesh->mVertexBufferCount; vCount ++) {
- Allocation *vertexAlloc = Allocation::createFromStream(rsc, stream);
- mesh->mVertexBuffers[vCount].set(vertexAlloc);
- }
- }
-
- mesh->mPrimitivesCount = stream->loadU32();
- if (mesh->mPrimitivesCount) {
- mesh->mPrimitives = new Primitive_t *[mesh->mPrimitivesCount];
-
- // load all primitives
- for (uint32_t pCount = 0; pCount < mesh->mPrimitivesCount; pCount ++) {
- Primitive_t * prim = new Primitive_t;
- mesh->mPrimitives[pCount] = prim;
-
- prim->mPrimitive = (RsPrimitive)stream->loadU8();
-
- // Check to see if the index buffer was stored
- uint32_t isIndexPresent = stream->loadU32();
- if (isIndexPresent) {
- Allocation *indexAlloc = Allocation::createFromStream(rsc, stream);
- prim->mIndexBuffer.set(indexAlloc);
- }
- }
- }
-
- mesh->updateGLPrimitives();
- mesh->initVertexAttribs();
- mesh->uploadAll(rsc);
-
- return mesh;
-}
-
void Mesh::computeBBox() {
float *posPtr = NULL;
uint32_t vectorSize = 0;
@@ -347,13 +349,6 @@ void Mesh::computeBBox() {
}
}
-
-MeshContext::MeshContext() {
-}
-
-MeshContext::~MeshContext() {
-}
-
namespace android {
namespace renderscript {
@@ -428,3 +423,5 @@ void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *pri
}
}
}
+
+#endif
diff --git a/libs/rs/rsMesh.h b/libs/rs/rsMesh.h
index 410b70b..3e080e2 100644
--- a/libs/rs/rsMesh.h
+++ b/libs/rs/rsMesh.h
@@ -50,15 +50,18 @@ public:
Primitive_t ** mPrimitives;
uint32_t mPrimitivesCount;
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
+ static Mesh *createFromStream(Context *rsc, IStream *stream);
+
+#ifndef ANDROID_RS_SERIALIZE
void render(Context *) const;
void renderPrimitive(Context *, uint32_t primIndex) const;
void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
void uploadAll(Context *);
void updateGLPrimitives();
- virtual void serialize(OStream *stream) const;
- virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
- static Mesh *createFromStream(Context *rsc, IStream *stream);
+
// Bounding volumes
float mBBoxMin[3];
@@ -76,12 +79,15 @@ protected:
// buffer, it lets us properly map it
uint32_t *mAttribAllocationIndex;
uint32_t mAttribCount;
+#endif
};
class MeshContext {
public:
- MeshContext();
- ~MeshContext();
+ MeshContext() {
+ }
+ ~MeshContext() {
+ }
};
}
diff --git a/libs/rs/rsObjectBase.cpp b/libs/rs/rsObjectBase.cpp
index aec2f67..f428f94 100644
--- a/libs/rs/rsObjectBase.cpp
+++ b/libs/rs/rsObjectBase.cpp
@@ -15,13 +15,7 @@
*/
#include "rsObjectBase.h"
-
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#else
-#include "rsContextHostStub.h"
-#endif
-
using namespace android;
using namespace android::renderscript;
diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp
index 39b85e3..4ef05bf 100644
--- a/libs/rs/rsProgram.cpp
+++ b/libs/rs/rsProgram.cpp
@@ -14,15 +14,11 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#include <OpenGL/glext.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
+#endif //ANDROID_RS_SERIALIZE
#include "rsProgram.h"
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index 22cd5d3..ff314b7 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -14,17 +14,13 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#include <OpenGL/glext.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
+#endif //ANDROID_RS_SERIALIZE
#include "rsProgramFragment.h"
diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp
index f2b5b9a..ace1572 100644
--- a/libs/rs/rsProgramRaster.cpp
+++ b/libs/rs/rsProgramRaster.cpp
@@ -14,15 +14,11 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES/glext.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#include <OpenGl/glext.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
+#endif //ANDROID_RS_SERIALIZE
#include "rsProgramRaster.h"
diff --git a/libs/rs/rsProgramStore.cpp b/libs/rs/rsProgramStore.cpp
index 72ac574..09b759d 100644
--- a/libs/rs/rsProgramStore.cpp
+++ b/libs/rs/rsProgramStore.cpp
@@ -14,15 +14,11 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES/glext.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#include <OpenGl/glext.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
+#endif //ANDROID_RS_SERIALIZE
#include "rsProgramStore.h"
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index ad2beaf..403c2a6 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -14,17 +14,13 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#include <OpenGL/glext.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
+#endif //ANDROID_RS_SERIALIZE
#include "rsProgramVertex.h"
diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp
index c80aecc..db2383a 100644
--- a/libs/rs/rsSampler.cpp
+++ b/libs/rs/rsSampler.cpp
@@ -14,15 +14,11 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
+#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES/glext.h>
-#include "rsContext.h"
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#include <OpenGL/glext.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
+#endif //ANDROID_RS_SERIALIZE
#include "rsSampler.h"
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index fc673a2..445a4e4 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -485,12 +485,7 @@ bool ScriptCState::runCompiler(Context *rsc,
}
#if 1
- if (bccLinkBC(s->mBccScript,
- resName,
- NULL /*rs_runtime_lib_bc*/,
- 1 /*rs_runtime_lib_bc_size*/
- /*"1" means skip buffer here, and let libbcc decide*/,
- 0) != 0) {
+ if (bccLinkFile(s->mBccScript, "/system/lib/libclcore.bc", 0) != 0) {
LOGE("bcc: FAILS to link bitcode");
return false;
}
diff --git a/libs/rs/rsShaderCache.cpp b/libs/rs/rsShaderCache.cpp
index b958021..e8d89c2 100644
--- a/libs/rs/rsShaderCache.cpp
+++ b/libs/rs/rsShaderCache.cpp
@@ -14,14 +14,11 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES2/gl2.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
+#endif //ANDROID_RS_SERIALIZE
using namespace android;
using namespace android::renderscript;
diff --git a/libs/rs/rsStream.cpp b/libs/rs/rsStream.cpp
index 49ed567..b9df0cc 100644
--- a/libs/rs/rsStream.cpp
+++ b/libs/rs/rsStream.cpp
@@ -15,12 +15,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#else
-#include "rsContextHostStub.h"
-#endif
-
#include "rsStream.h"
using namespace android;
diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp
index d7b5f12..cd2be94 100644
--- a/libs/rs/rsType.cpp
+++ b/libs/rs/rsType.cpp
@@ -14,13 +14,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#include <GLES/gl.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#endif
using namespace android;
using namespace android::renderscript;
@@ -146,7 +140,7 @@ uint32_t Type::getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face, uint
void Type::dumpLOGV(const char *prefix) const {
char buf[1024];
ObjectBase::dumpLOGV(prefix);
- LOGV("%s Type: x=%i y=%i z=%i mip=%i face=%i", prefix, mDimX, mDimY, mDimZ, mDimLOD, mFaces);
+ LOGV("%s Type: x=%zu y=%zu z=%zu mip=%i face=%i", prefix, mDimX, mDimY, mDimZ, mDimLOD, mFaces);
snprintf(buf, sizeof(buf), "%s element: ", prefix);
mElement->dumpLOGV(buf);
}
diff --git a/libs/rs/rsUtils.h b/libs/rs/rsUtils.h
index 0699b57..3b60af5 100644
--- a/libs/rs/rsUtils.h
+++ b/libs/rs/rsUtils.h
@@ -32,7 +32,7 @@
#include <time.h>
#include <cutils/atomic.h>
-#ifndef ANDROID_RS_BUILD_FOR_HOST
+#ifndef ANDROID_RS_SERIALIZE
#include <EGL/egl.h>
#endif
diff --git a/libs/rs/rsVertexArray.cpp b/libs/rs/rsVertexArray.cpp
index d9393fe..354ee89 100644
--- a/libs/rs/rsVertexArray.cpp
+++ b/libs/rs/rsVertexArray.cpp
@@ -14,13 +14,10 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#ifndef ANDROID_RS_SERIALIZE
#include <GLES/gl.h>
#include <GLES2/gl2.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
#endif
using namespace android;
diff --git a/libs/rs/scriptc/rs_core.rsh b/libs/rs/scriptc/rs_core.rsh
index 464e1d9..4768bbe 100644
--- a/libs/rs/scriptc/rs_core.rsh
+++ b/libs/rs/scriptc/rs_core.rsh
@@ -295,6 +295,256 @@ extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m);
extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m);
/////////////////////////////////////////////////////
+// quaternion ops
+/////////////////////////////////////////////////////
+
+static void __attribute__((overloadable))
+rsQuaternionSet(rs_quaternion *q, float w, float x, float y, float z) {
+ q->w = w;
+ q->x = x;
+ q->y = y;
+ q->z = z;
+}
+
+static void __attribute__((overloadable))
+rsQuaternionSet(rs_quaternion *q, const rs_quaternion *rhs) {
+ q->w = rhs->w;
+ q->x = rhs->x;
+ q->y = rhs->y;
+ q->z = rhs->z;
+}
+
+static void __attribute__((overloadable))
+rsQuaternionMultiply(rs_quaternion *q, float s) {
+ q->w *= s;
+ q->x *= s;
+ q->y *= s;
+ q->z *= s;
+}
+
+static void __attribute__((overloadable))
+rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) {
+ q->w = -q->x*rhs->x - q->y*rhs->y - q->z*rhs->z + q->w*rhs->w;
+ q->x = q->x*rhs->w + q->y*rhs->z - q->z*rhs->y + q->w*rhs->x;
+ q->y = -q->x*rhs->z + q->y*rhs->w + q->z*rhs->x + q->w*rhs->y;
+ q->z = q->x*rhs->y - q->y*rhs->x + q->z*rhs->w + q->w*rhs->z;
+}
+
+static void
+rsQuaternionAdd(rs_quaternion *q, const rs_quaternion *rhs) {
+ q->w *= rhs->w;
+ q->x *= rhs->x;
+ q->y *= rhs->y;
+ q->z *= rhs->z;
+}
+
+static void
+rsQuaternionLoadRotateUnit(rs_quaternion *q, float rot, float x, float y, float z) {
+ rot *= (float)(M_PI / 180.0f) * 0.5f;
+ float c = cos(rot);
+ float s = sin(rot);
+
+ q->w = c;
+ q->x = x * s;
+ q->y = y * s;
+ q->z = z * s;
+}
+
+static void
+rsQuaternionLoadRotate(rs_quaternion *q, float rot, float x, float y, float z) {
+ const float len = x*x + y*y + z*z;
+ if (len != 1) {
+ const float recipLen = 1.f / sqrt(len);
+ x *= recipLen;
+ y *= recipLen;
+ z *= recipLen;
+ }
+ rsQuaternionLoadRotateUnit(q, rot, x, y, z);
+}
+
+static void
+rsQuaternionConjugate(rs_quaternion *q) {
+ q->x = -q->x;
+ q->y = -q->y;
+ q->z = -q->z;
+}
+
+static float
+rsQuaternionDot(const rs_quaternion *q0, const rs_quaternion *q1) {
+ return q0->w*q1->w + q0->x*q1->x + q0->y*q1->y + q0->z*q1->z;
+}
+
+static void
+rsQuaternionNormalize(rs_quaternion *q) {
+ const float len = rsQuaternionDot(q, q);
+ if (len != 1) {
+ const float recipLen = 1.f / sqrt(len);
+ rsQuaternionMultiply(q, recipLen);
+ }
+}
+
+static void
+rsQuaternionSlerp(rs_quaternion *q, const rs_quaternion *q0, const rs_quaternion *q1, float t) {
+ if (t <= 0.0f) {
+ rsQuaternionSet(q, q0);
+ return;
+ }
+ if (t >= 1.0f) {
+ rsQuaternionSet(q, q1);
+ return;
+ }
+
+ rs_quaternion tempq0, tempq1;
+ rsQuaternionSet(&tempq0, q0);
+ rsQuaternionSet(&tempq1, q1);
+
+ float angle = rsQuaternionDot(q0, q1);
+ if (angle < 0) {
+ rsQuaternionMultiply(&tempq0, -1.0f);
+ angle *= -1.0f;
+ }
+
+ float scale, invScale;
+ if (angle + 1.0f > 0.05f) {
+ if (1.0f - angle >= 0.05f) {
+ float theta = acos(angle);
+ float invSinTheta = 1.0f / sin(theta);
+ scale = sin(theta * (1.0f - t)) * invSinTheta;
+ invScale = sin(theta * t) * invSinTheta;
+ } else {
+ scale = 1.0f - t;
+ invScale = t;
+ }
+ } else {
+ rsQuaternionSet(&tempq1, tempq0.z, -tempq0.y, tempq0.x, -tempq0.w);
+ scale = sin(M_PI * (0.5f - t));
+ invScale = sin(M_PI * t);
+ }
+
+ rsQuaternionSet(q, tempq0.w*scale + tempq1.w*invScale, tempq0.x*scale + tempq1.x*invScale,
+ tempq0.y*scale + tempq1.y*invScale, tempq0.z*scale + tempq1.z*invScale);
+}
+
+static void rsQuaternionGetMatrixUnit(rs_matrix4x4 *m, const rs_quaternion *q) {
+ float x2 = 2.0f * q->x * q->x;
+ float y2 = 2.0f * q->y * q->y;
+ float z2 = 2.0f * q->z * q->z;
+ float xy = 2.0f * q->x * q->y;
+ float wz = 2.0f * q->w * q->z;
+ float xz = 2.0f * q->x * q->z;
+ float wy = 2.0f * q->w * q->y;
+ float wx = 2.0f * q->w * q->x;
+ float yz = 2.0f * q->y * q->z;
+
+ m->m[0] = 1.0f - y2 - z2;
+ m->m[1] = xy - wz;
+ m->m[2] = xz + wy;
+ m->m[3] = 0.0f;
+
+ m->m[4] = xy + wz;
+ m->m[5] = 1.0f - x2 - z2;
+ m->m[6] = yz - wx;
+ m->m[7] = 0.0f;
+
+ m->m[8] = xz - wy;
+ m->m[9] = yz - wx;
+ m->m[10] = 1.0f - x2 - y2;
+ m->m[11] = 0.0f;
+
+ m->m[12] = 0.0f;
+ m->m[13] = 0.0f;
+ m->m[14] = 0.0f;
+ m->m[15] = 1.0f;
+}
+
+/////////////////////////////////////////////////////
+// utility funcs
+/////////////////////////////////////////////////////
+__inline__ static void __attribute__((overloadable, always_inline))
+rsExtractFrustumPlanes(const rs_matrix4x4 *modelViewProj,
+ float4 *left, float4 *right,
+ float4 *top, float4 *bottom,
+ float4 *near, float4 *far) {
+ // x y z w = a b c d in the plane equation
+ left->x = modelViewProj->m[3] + modelViewProj->m[0];
+ left->y = modelViewProj->m[7] + modelViewProj->m[4];
+ left->z = modelViewProj->m[11] + modelViewProj->m[8];
+ left->w = modelViewProj->m[15] + modelViewProj->m[12];
+
+ right->x = modelViewProj->m[3] - modelViewProj->m[0];
+ right->y = modelViewProj->m[7] - modelViewProj->m[4];
+ right->z = modelViewProj->m[11] - modelViewProj->m[8];
+ right->w = modelViewProj->m[15] - modelViewProj->m[12];
+
+ top->x = modelViewProj->m[3] - modelViewProj->m[1];
+ top->y = modelViewProj->m[7] - modelViewProj->m[5];
+ top->z = modelViewProj->m[11] - modelViewProj->m[9];
+ top->w = modelViewProj->m[15] - modelViewProj->m[13];
+
+ bottom->x = modelViewProj->m[3] + modelViewProj->m[1];
+ bottom->y = modelViewProj->m[7] + modelViewProj->m[5];
+ bottom->z = modelViewProj->m[11] + modelViewProj->m[9];
+ bottom->w = modelViewProj->m[15] + modelViewProj->m[13];
+
+ near->x = modelViewProj->m[3] + modelViewProj->m[2];
+ near->y = modelViewProj->m[7] + modelViewProj->m[6];
+ near->z = modelViewProj->m[11] + modelViewProj->m[10];
+ near->w = modelViewProj->m[15] + modelViewProj->m[14];
+
+ far->x = modelViewProj->m[3] - modelViewProj->m[2];
+ far->y = modelViewProj->m[7] - modelViewProj->m[6];
+ far->z = modelViewProj->m[11] - modelViewProj->m[10];
+ far->w = modelViewProj->m[15] - modelViewProj->m[14];
+
+ float len = length(left->xyz);
+ *left /= len;
+ len = length(right->xyz);
+ *right /= len;
+ len = length(top->xyz);
+ *top /= len;
+ len = length(bottom->xyz);
+ *bottom /= len;
+ len = length(near->xyz);
+ *near /= len;
+ len = length(far->xyz);
+ *far /= len;
+}
+
+__inline__ static bool __attribute__((overloadable, always_inline))
+rsIsSphereInFrustum(float4 *sphere,
+ float4 *left, float4 *right,
+ float4 *top, float4 *bottom,
+ float4 *near, float4 *far) {
+
+ float distToCenter = dot(left->xyz, sphere->xyz) + left->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(right->xyz, sphere->xyz) + right->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(top->xyz, sphere->xyz) + top->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(near->xyz, sphere->xyz) + near->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(far->xyz, sphere->xyz) + far->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ return true;
+}
+
+
+/////////////////////////////////////////////////////
// int ops
/////////////////////////////////////////////////////
diff --git a/libs/rs/scriptc/rs_types.rsh b/libs/rs/scriptc/rs_types.rsh
index 367af46..a010096 100644
--- a/libs/rs/scriptc/rs_types.rsh
+++ b/libs/rs/scriptc/rs_types.rsh
@@ -73,6 +73,8 @@ typedef struct {
float m[4];
} rs_matrix2x2;
+typedef float4 rs_quaternion;
+
#define RS_PACKED __attribute__((packed, aligned(4)))
#endif