summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-08-25 11:34:49 -0700
committerJason Sams <rjsams@android.com>2009-08-25 11:44:30 -0700
commitafcb25c65e8145d15aaf50a0ca38333954a97000 (patch)
treecde38a0b146b55928647db9d609e440986143b81
parentebb52f16d9c06b6ff64574110b62eced58b66219 (diff)
downloadrs-afcb25c65e8145d15aaf50a0ca38333954a97000.tar.gz
Add support for selecting the color bit depth and if the application used a depth buffer.
-rw-r--r--RenderScript.h2
-rw-r--r--java/Fall/src/com/android/fall/rs/FallView.java2
-rw-r--r--java/Film/src/com/android/film/FilmView.java2
-rw-r--r--java/Fountain/src/com/android/fountain/FountainView.java2
-rw-r--r--java/Rollo/src/com/android/rollo/RolloView.java2
-rw-r--r--rsContext.cpp143
-rw-r--r--rsContext.h41
-rw-r--r--rsObjectBase.cpp5
-rw-r--r--rsProgram.cpp6
-rw-r--r--rsProgram.h4
-rw-r--r--rsProgramFragment.cpp6
-rw-r--r--rsProgramFragment.h2
-rw-r--r--rsProgramFragmentStore.cpp2
-rw-r--r--rsProgramFragmentStore.h2
-rw-r--r--rsProgramVertex.cpp2
-rw-r--r--rsProgramVertex.h2
16 files changed, 128 insertions, 97 deletions
diff --git a/RenderScript.h b/RenderScript.h
index 2f60c9fe..1e24cd2e 100644
--- a/RenderScript.h
+++ b/RenderScript.h
@@ -49,7 +49,7 @@ typedef void * RsProgramFragmentStore;
RsDevice rsDeviceCreate();
void rsDeviceDestroy(RsDevice);
-RsContext rsContextCreate(RsDevice, void *, uint32_t version);
+RsContext rsContextCreate(RsDevice, void *, uint32_t version, bool useDepth);
void rsContextDestroy(RsContext);
void rsObjDestroyOOB(RsContext, void *);
diff --git a/java/Fall/src/com/android/fall/rs/FallView.java b/java/Fall/src/com/android/fall/rs/FallView.java
index fa2caa70..7468d2bb 100644
--- a/java/Fall/src/com/android/fall/rs/FallView.java
+++ b/java/Fall/src/com/android/fall/rs/FallView.java
@@ -36,7 +36,7 @@ class FallView extends RSSurfaceView {
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
- RenderScript RS = createRenderScript();
+ RenderScript RS = createRenderScript(false);
mRender = new FallRS(w, h);
mRender.init(RS, getResources());
}
diff --git a/java/Film/src/com/android/film/FilmView.java b/java/Film/src/com/android/film/FilmView.java
index 73b74148..1c5b2bc1 100644
--- a/java/Film/src/com/android/film/FilmView.java
+++ b/java/Film/src/com/android/film/FilmView.java
@@ -52,7 +52,7 @@ public class FilmView extends RSSurfaceView {
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
- mRS = createRenderScript();
+ mRS = createRenderScript(true);
mRender = new FilmRS();
mRender.init(mRS, getResources(), w, h);
}
diff --git a/java/Fountain/src/com/android/fountain/FountainView.java b/java/Fountain/src/com/android/fountain/FountainView.java
index 2768e2c7..7826161c 100644
--- a/java/Fountain/src/com/android/fountain/FountainView.java
+++ b/java/Fountain/src/com/android/fountain/FountainView.java
@@ -52,7 +52,7 @@ public class FountainView extends RSSurfaceView {
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
- mRS = createRenderScript();
+ mRS = createRenderScript(false);
mRender = new FountainRS();
mRender.init(mRS, getResources(), w, h);
}
diff --git a/java/Rollo/src/com/android/rollo/RolloView.java b/java/Rollo/src/com/android/rollo/RolloView.java
index 3e1c54d9..7524a0e3 100644
--- a/java/Rollo/src/com/android/rollo/RolloView.java
+++ b/java/Rollo/src/com/android/rollo/RolloView.java
@@ -54,7 +54,7 @@ public class RolloView extends RSSurfaceView {
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
- mRS = createRenderScript();
+ mRS = createRenderScript(false);
mRender = new RolloRS();
mRender.init(mRS, getResources(), w, h);
}
diff --git a/rsContext.cpp b/rsContext.cpp
index 413caabe..c8c69a8c 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -18,6 +18,7 @@
#include "rsContext.h"
#include "rsThreadIO.h"
#include <ui/FramebufferNativeWindow.h>
+#include <ui/EGLUtils.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
@@ -29,41 +30,64 @@ pthread_key_t Context::gThreadTLSKey = 0;
void Context::initEGL()
{
- mNumConfigs = -1;
+ mEGL.mNumConfigs = -1;
+ EGLint configAttribs[128];
+ EGLint *configAttribsPtr = configAttribs;
+
+ memset(configAttribs, 0, sizeof(configAttribs));
+
+ configAttribsPtr[0] = EGL_SURFACE_TYPE;
+ configAttribsPtr[1] = EGL_WINDOW_BIT;
+ configAttribsPtr += 2;
+
+ if (mUseDepth) {
+ configAttribsPtr[0] = EGL_DEPTH_SIZE;
+ configAttribsPtr[1] = 16;
+ configAttribsPtr += 2;
+ }
+ configAttribsPtr[0] = EGL_NONE;
+ rsAssert(configAttribsPtr < (configAttribs + (sizeof(configAttribs) / sizeof(EGLint))));
+
+ mEGL.mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ eglInitialize(mEGL.mDisplay, &mEGL.mMajorVersion, &mEGL.mMinorVersion);
+
+ status_t err = EGLUtils::selectConfigForNativeWindow(mEGL.mDisplay, configAttribs, mWndSurface, &mEGL.mConfig);
+ if (err) {
+ LOGE("couldn't find an EGLConfig matching the screen format\n");
+ }
+ //eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs);
+
+ if (mWndSurface) {
+ mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig, mWndSurface, NULL);
+ } else {
+ mEGL.mSurface = eglCreateWindowSurface(mEGL.mDisplay, mEGL.mConfig,
+ android_createDisplaySurface(),
+ NULL);
+ }
+
+ mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, NULL, NULL);
+ eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext);
+ eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
+ eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
+
+
+ mGL.mVersion = glGetString(GL_VERSION);
+ mGL.mVendor = glGetString(GL_VENDOR);
+ mGL.mRenderer = glGetString(GL_RENDERER);
+ mGL.mExtensions = glGetString(GL_EXTENSIONS);
+
+ LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
+ LOGV("GL Version %s", mGL.mVersion);
+ LOGV("GL Vendor %s", mGL.mVendor);
+ LOGV("GL Renderer %s", mGL.mRenderer);
+ LOGV("GL Extensions %s", mGL.mExtensions);
+
+ if (memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
+ LOGE("Error, OpenGL ES Lite not supported");
+ }
+ sscanf((const char *)mGL.mVersion + 13, "%i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
- EGLint s_configAttribs[] = {
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
-#if 1
- EGL_RED_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_BLUE_SIZE, 8,
- EGL_ALPHA_SIZE, 8,
-#else
- EGL_RED_SIZE, 5,
- EGL_GREEN_SIZE, 6,
- EGL_BLUE_SIZE, 5,
-#endif
- EGL_DEPTH_SIZE, 16,
- EGL_NONE
- };
-
- mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- eglInitialize(mDisplay, &mMajorVersion, &mMinorVersion);
- eglChooseConfig(mDisplay, s_configAttribs, &mConfig, 1, &mNumConfigs);
-
- if (mWndSurface) {
- mSurface = eglCreateWindowSurface(mDisplay, mConfig, mWndSurface,
- NULL);
- } else {
- mSurface = eglCreateWindowSurface(mDisplay, mConfig,
- android_createDisplaySurface(),
- NULL);
- }
- mContext = eglCreateContext(mDisplay, mConfig, NULL, NULL);
- eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
- eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mWidth);
- eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mHeight);
}
bool Context::runScript(Script *s, uint32_t launchID)
@@ -90,19 +114,22 @@ bool Context::runRootScript()
//glColor4f(1,1,1,1);
//glEnable(GL_LIGHT0);
- glViewport(0, 0, mWidth, mHeight);
-
- glDepthMask(GL_TRUE);
+ glViewport(0, 0, mEGL.mWidth, mEGL.mHeight);
+#if 1
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClearColor(mRootScript->mEnviroment.mClearColor[0],
mRootScript->mEnviroment.mClearColor[1],
mRootScript->mEnviroment.mClearColor[2],
mRootScript->mEnviroment.mClearColor[3]);
- glClearDepthf(mRootScript->mEnviroment.mClearDepth);
- glClear(GL_COLOR_BUFFER_BIT);
- glClear(GL_DEPTH_BUFFER_BIT);
-
+ if (mUseDepth) {
+ glDepthMask(GL_TRUE);
+ glClearDepthf(mRootScript->mEnviroment.mClearDepth);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ } else {
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+#endif
#if RS_LOG_TIMES
timerSet(RS_TIMER_SCRIPT);
#endif
@@ -156,13 +183,13 @@ void Context::timerPrint()
void Context::setupCheck()
{
if (mFragmentStore.get()) {
- mFragmentStore->setupGL(&mStateFragmentStore);
+ mFragmentStore->setupGL(this, &mStateFragmentStore);
}
if (mFragment.get()) {
- mFragment->setupGL(&mStateFragment);
+ mFragment->setupGL(this, &mStateFragment);
}
if (mVertex.get()) {
- mVertex->setupGL(&mStateVertex);
+ mVertex->setupGL(this, &mStateVertex);
}
}
@@ -186,11 +213,11 @@ void * Context::threadProc(void *vrsc)
LOGE("pthread_setspecific %i", status);
}
- rsc->mStateVertex.init(rsc, rsc->mWidth, rsc->mHeight);
+ rsc->mStateVertex.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
rsc->setVertex(NULL);
- rsc->mStateFragment.init(rsc, rsc->mWidth, rsc->mHeight);
+ rsc->mStateFragment.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
rsc->setFragment(NULL);
- rsc->mStateFragmentStore.init(rsc, rsc->mWidth, rsc->mHeight);
+ rsc->mStateFragmentStore.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
rsc->setFragmentStore(NULL);
rsc->mRunning = true;
@@ -204,7 +231,7 @@ void * Context::threadProc(void *vrsc)
#if RS_LOG_TIMES
rsc->timerSet(RS_TIMER_CLEAR_SWAP);
#endif
- eglSwapBuffers(rsc->mDisplay, rsc->mSurface);
+ eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
#if RS_LOG_TIMES
rsc->timerSet(RS_TIMER_INTERNAL);
rsc->timerPrint();
@@ -218,18 +245,19 @@ void * Context::threadProc(void *vrsc)
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
- eglSwapBuffers(rsc->mDisplay, rsc->mSurface);
- eglTerminate(rsc->mDisplay);
+ eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
+ eglTerminate(rsc->mEGL.mDisplay);
rsc->objDestroyOOBRun();
return NULL;
}
-Context::Context(Device *dev, Surface *sur)
+Context::Context(Device *dev, Surface *sur, bool useDepth)
{
dev->addContext(this);
mDev = dev;
mRunning = false;
mExit = false;
+ mUseDepth = useDepth;
int status;
pthread_attr_t threadAttr;
@@ -284,17 +312,6 @@ Context::~Context()
objDestroyOOBDestroy();
}
-void Context::swapBuffers()
-{
- eglSwapBuffers(mDisplay, mSurface);
-}
-
-void rsContextSwap(RsContext vrsc)
-{
- Context *rsc = static_cast<Context *>(vrsc);
- rsc->swapBuffers();
-}
-
void Context::setRootScript(Script *s)
{
mRootScript.set(s);
@@ -520,10 +537,10 @@ void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value)
}
-RsContext rsContextCreate(RsDevice vdev, void *sur, uint32_t version)
+RsContext rsContextCreate(RsDevice vdev, void *sur, uint32_t version, bool useDepth)
{
Device * dev = static_cast<Device *>(vdev);
- Context *rsc = new Context(dev, (Surface *)sur);
+ Context *rsc = new Context(dev, (Surface *)sur, useDepth);
return rsc;
}
diff --git a/rsContext.h b/rsContext.h
index ca67e40e..c58a88c7 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -49,7 +49,7 @@ namespace renderscript {
class Context
{
public:
- Context(Device *, Surface *);
+ Context(Device *, Surface *, bool useDepth);
~Context();
static pthread_key_t gThreadTLSKey;
@@ -111,8 +111,8 @@ public:
mFloatDefines.add(String8(name), value);
}
- uint32_t getWidth() const {return mWidth;}
- uint32_t getHeight() const {return mHeight;}
+ uint32_t getWidth() const {return mEGL.mWidth;}
+ uint32_t getHeight() const {return mEGL.mHeight;}
ThreadIO mIO;
@@ -132,21 +132,38 @@ public:
void timerSet(Timers);
void timerPrint();
+ bool checkVersion1_1() const {return (mGL.mMajorVersion > 1) || (mGL.mMinorVersion >= 1); }
+ bool checkVersion2_0() const {return mGL.mMajorVersion >= 2; }
+
protected:
Device *mDev;
- EGLint mNumConfigs;
- EGLint mMajorVersion;
- EGLint mMinorVersion;
- EGLConfig mConfig;
- EGLContext mContext;
- EGLSurface mSurface;
- EGLint mWidth;
- EGLint mHeight;
- EGLDisplay mDisplay;
+ struct {
+ EGLint mNumConfigs;
+ EGLint mMajorVersion;
+ EGLint mMinorVersion;
+ EGLConfig mConfig;
+ EGLContext mContext;
+ EGLSurface mSurface;
+ EGLint mWidth;
+ EGLint mHeight;
+ EGLDisplay mDisplay;
+ } mEGL;
+
+ struct {
+ const uint8_t * mVendor;
+ const uint8_t * mRenderer;
+ const uint8_t * mVersion;
+ const uint8_t * mExtensions;
+
+ uint32_t mMajorVersion;
+ uint32_t mMinorVersion;
+
+ } mGL;
bool mRunning;
bool mExit;
+ bool mUseDepth;
pthread_t mThreadId;
diff --git a/rsObjectBase.cpp b/rsObjectBase.cpp
index 6a5b7d83..07bbc1e7 100644
--- a/rsObjectBase.cpp
+++ b/rsObjectBase.cpp
@@ -43,6 +43,11 @@ void ObjectBase::decRef() const
mRefCount --;
//LOGV("ObjectBase %p dec ref %i", this, mRefCount);
if (!mRefCount) {
+ if (mName) {
+ LOGV("Deleting RS object %p, name %s", this, mName);
+ } else {
+ LOGV("Deleting RS object %p, no name", this);
+ }
delete this;
}
}
diff --git a/rsProgram.cpp b/rsProgram.cpp
index 6606daaa..18eacfb3 100644
--- a/rsProgram.cpp
+++ b/rsProgram.cpp
@@ -47,9 +47,3 @@ void Program::checkUpdatedAllocation(const Allocation *alloc)
}
}
-void Program::setupGL()
-{
-
-}
-
-
diff --git a/rsProgram.h b/rsProgram.h
index 251072fb..bb3d9ac3 100644
--- a/rsProgram.h
+++ b/rsProgram.h
@@ -32,11 +32,7 @@ public:
Program(Element *in, Element *out);
virtual ~Program();
-
void bindAllocation(Allocation *);
-
- virtual void setupGL();
-
void checkUpdatedAllocation(const Allocation *);
protected:
diff --git a/rsProgramFragment.cpp b/rsProgramFragment.cpp
index 4ef68352..654974fe 100644
--- a/rsProgramFragment.cpp
+++ b/rsProgramFragment.cpp
@@ -40,7 +40,7 @@ ProgramFragment::~ProgramFragment()
{
}
-void ProgramFragment::setupGL(ProgramFragmentState *state)
+void ProgramFragment::setupGL(const Context *rsc, ProgramFragmentState *state)
{
if ((state->mLast.get() == this) && !mDirty) {
return;
@@ -55,7 +55,9 @@ void ProgramFragment::setupGL(ProgramFragmentState *state)
}
glEnable(GL_TEXTURE_2D);
- //glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, mPointSpriteEnable);
+ if (rsc->checkVersion1_1()) {
+ glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, mPointSpriteEnable);
+ }
glBindTexture(GL_TEXTURE_2D, mTextures[ct]->getTextureID());
switch(mEnvModes[ct]) {
diff --git a/rsProgramFragment.h b/rsProgramFragment.h
index bd453420..51117ebe 100644
--- a/rsProgramFragment.h
+++ b/rsProgramFragment.h
@@ -35,7 +35,7 @@ public:
ProgramFragment(Element *in, Element *out, bool pointSpriteEnable);
virtual ~ProgramFragment();
- virtual void setupGL(ProgramFragmentState *);
+ virtual void setupGL(const Context *, ProgramFragmentState *);
diff --git a/rsProgramFragmentStore.cpp b/rsProgramFragmentStore.cpp
index 99eed16f..36ec6153 100644
--- a/rsProgramFragmentStore.cpp
+++ b/rsProgramFragmentStore.cpp
@@ -48,7 +48,7 @@ ProgramFragmentStore::~ProgramFragmentStore()
{
}
-void ProgramFragmentStore::setupGL(ProgramFragmentStoreState *state)
+void ProgramFragmentStore::setupGL(const Context *rsc, ProgramFragmentStoreState *state)
{
if (state->mLast.get() == this) {
return;
diff --git a/rsProgramFragmentStore.h b/rsProgramFragmentStore.h
index 0de5c3a3..e646e03e 100644
--- a/rsProgramFragmentStore.h
+++ b/rsProgramFragmentStore.h
@@ -31,7 +31,7 @@ public:
ProgramFragmentStore(Element *in, Element *out);
virtual ~ProgramFragmentStore();
- virtual void setupGL(ProgramFragmentStoreState *);
+ virtual void setupGL(const Context *, ProgramFragmentStoreState *);
void setDepthFunc(RsDepthFunc);
void setDepthMask(bool);
diff --git a/rsProgramVertex.cpp b/rsProgramVertex.cpp
index 6ef54563..dc57d345 100644
--- a/rsProgramVertex.cpp
+++ b/rsProgramVertex.cpp
@@ -44,7 +44,7 @@ static void logMatrix(const char *txt, const float *f)
LOGV("%6.2f, %6.2f, %6.2f, %6.2f", f[3], f[7], f[11], f[15]);
}
-void ProgramVertex::setupGL(ProgramVertexState *state)
+void ProgramVertex::setupGL(const Context *rsc, ProgramVertexState *state)
{
if ((state->mLast.get() == this) && !mDirty) {
return;
diff --git a/rsProgramVertex.h b/rsProgramVertex.h
index c9ce7aa6..523c3edd 100644
--- a/rsProgramVertex.h
+++ b/rsProgramVertex.h
@@ -33,7 +33,7 @@ public:
ProgramVertex(Element *in, Element *out);
virtual ~ProgramVertex();
- virtual void setupGL(ProgramVertexState *state);
+ virtual void setupGL(const Context *rsc, ProgramVertexState *state);
void setTextureMatrixEnable(bool e) {mTextureMatrixEnable = e;}