summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/rsContext.cpp')
-rw-r--r--libs/rs/rsContext.cpp64
1 files changed, 42 insertions, 22 deletions
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 3652f0a..f815badb 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -50,11 +50,12 @@ static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) {
}
}
-void Context::initEGL()
+void Context::initEGL(bool useGL2)
{
mEGL.mNumConfigs = -1;
EGLint configAttribs[128];
EGLint *configAttribsPtr = configAttribs;
+ EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
memset(configAttribs, 0, sizeof(configAttribs));
@@ -62,6 +63,12 @@ void Context::initEGL()
configAttribsPtr[1] = EGL_WINDOW_BIT;
configAttribsPtr += 2;
+ if (useGL2) {
+ configAttribsPtr[0] = EGL_RENDERABLE_TYPE;
+ configAttribsPtr[1] = EGL_OPENGL_ES2_BIT;
+ configAttribsPtr += 2;
+ }
+
if (mUseDepth) {
configAttribsPtr[0] = EGL_DEPTH_SIZE;
configAttribsPtr[1] = 16;
@@ -91,7 +98,11 @@ void Context::initEGL()
//eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs);
- mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL);
+ if (useGL2) {
+ mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, context_attribs2);
+ } else {
+ mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL);
+ }
checkEglError("eglCreateContext");
if (mEGL.mContext == EGL_NO_CONTEXT) {
LOGE("eglCreateContext returned EGL_NO_CONTEXT");
@@ -225,10 +236,20 @@ void Context::timerPrint()
void Context::setupCheck()
{
- mFragmentStore->setupGL(this, &mStateFragmentStore);
- mFragment->setupGL(this, &mStateFragment);
- mRaster->setupGL(this, &mStateRaster);
- mVertex->setupGL(this, &mStateVertex);
+ if (checkVersion2_0()) {
+ mShaderCache.lookup(mVertex.get(), mFragment.get());
+
+ mFragmentStore->setupGL2(this, &mStateFragmentStore);
+ mFragment->setupGL2(this, &mStateFragment, &mShaderCache);
+ mRaster->setupGL2(this, &mStateRaster);
+ mVertex->setupGL2(this, &mStateVertex, &mShaderCache);
+
+ } else {
+ mFragmentStore->setupGL(this, &mStateFragmentStore);
+ mFragment->setupGL(this, &mStateFragment);
+ mRaster->setupGL(this, &mStateRaster);
+ mVertex->setupGL(this, &mStateVertex);
+ }
}
static bool getProp(const char *str)
@@ -250,10 +271,6 @@ void * Context::threadProc(void *vrsc)
rsc->props.mLogScripts = getProp("debug.rs.script");
rsc->props.mLogObjects = getProp("debug.rs.objects");
- //pthread_mutex_lock(&gInitMutex);
- //rsc->initEGL();
- //pthread_mutex_unlock(&gInitMutex);
-
ScriptTLSStruct *tlsStruct = new ScriptTLSStruct;
if (!tlsStruct) {
LOGE("Error allocating tls storage");
@@ -274,6 +291,7 @@ void * Context::threadProc(void *vrsc)
rsc->setFragment(NULL);
rsc->mStateFragmentStore.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
rsc->setFragmentStore(NULL);
+ rsc->mStateVertexArray.init(rsc);
rsc->mRunning = true;
bool mDraw = true;
@@ -457,7 +475,7 @@ void Context::setSurface(uint32_t w, uint32_t h, Surface *sur)
if (!mEGL.mContext) {
first = true;
pthread_mutex_lock(&gInitMutex);
- initEGL();
+ initEGL(true);
pthread_mutex_unlock(&gInitMutex);
}
@@ -488,14 +506,24 @@ void Context::setSurface(uint32_t w, uint32_t h, Surface *sur)
//LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
LOGV("GL Version %s", mGL.mVersion);
- LOGV("GL Vendor %s", mGL.mVendor);
+ //LOGV("GL Vendor %s", mGL.mVendor);
LOGV("GL Renderer %s", mGL.mRenderer);
//LOGV("GL Extensions %s", mGL.mExtensions);
- if ((strlen((const char *)mGL.mVersion) < 12) || memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
+ const char *verptr = NULL;
+ if (strlen((const char *)mGL.mVersion) > 9) {
+ if (!memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
+ verptr = (const char *)mGL.mVersion + 12;
+ }
+ if (!memcmp(mGL.mVersion, "OpenGL ES ", 10)) {
+ verptr = (const char *)mGL.mVersion + 9;
+ }
+ }
+
+ if (!verptr) {
LOGE("Error, OpenGL ES Lite not supported");
} else {
- sscanf((const char *)mGL.mVersion + 13, "%i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
+ sscanf(verptr, " %i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
}
}
@@ -544,13 +572,6 @@ void Context::setRaster(ProgramRaster *pr)
}
}
-void Context::allocationCheck(const Allocation *a)
-{
- mVertex->checkUpdatedAllocation(a);
- mFragment->checkUpdatedAllocation(a);
- mFragmentStore->checkUpdatedAllocation(a);
-}
-
void Context::setVertex(ProgramVertex *pv)
{
if (pv == NULL) {
@@ -558,7 +579,6 @@ void Context::setVertex(ProgramVertex *pv)
} else {
mVertex.set(pv);
}
- mVertex->forceDirty();
}
void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)