summaryrefslogtreecommitdiffstats
path: root/libs/rs
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-11-30 14:49:55 -0800
committerJason Sams <rjsams@android.com>2009-11-30 15:34:03 -0800
commit54c0ec14e016e4a1bf3ceab40ed6ca5447da4725 (patch)
tree343acd699d50a4090b451d05135aa7887a6a7984 /libs/rs
parent5154ae7665743b114c71f90dcc577dc50c63b398 (diff)
downloadframeworks_base-54c0ec14e016e4a1bf3ceab40ed6ca5447da4725.zip
frameworks_base-54c0ec14e016e4a1bf3ceab40ed6ca5447da4725.tar.gz
frameworks_base-54c0ec14e016e4a1bf3ceab40ed6ca5447da4725.tar.bz2
Beging GL2 user shaders. Switch master to using GL2 by default.
Diffstat (limited to 'libs/rs')
-rw-r--r--libs/rs/rs.spec10
-rw-r--r--libs/rs/rsContext.cpp2
-rw-r--r--libs/rs/rsProgram.cpp8
-rw-r--r--libs/rs/rsProgram.h2
-rw-r--r--libs/rs/rsProgramFragment.cpp19
-rw-r--r--libs/rs/rsProgramVertex.cpp32
-rw-r--r--libs/rs/rsShaderCache.cpp8
7 files changed, 62 insertions, 19 deletions
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index a4e72d9..c7ae18a 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -372,6 +372,11 @@ ProgramFragmentBegin {
param bool pointSpriteEnable
}
+ProgramFragmentSetShader {
+ param const char * text
+ param uint32_t length
+ }
+
ProgramFragmentBindTexture {
param RsProgramFragment pf
param uint32_t slot
@@ -414,6 +419,11 @@ ProgramVertexSetTextureMatrixEnable {
param bool enable
}
+ProgramVertexSetShader {
+ param const char * text
+ param uint32_t length
+ }
+
ProgramVertexAddLight {
param RsLight light
}
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 427a6cc..3d2caff 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -467,7 +467,7 @@ void Context::setSurface(uint32_t w, uint32_t h, Surface *sur)
if (!mEGL.mContext) {
first = true;
pthread_mutex_lock(&gInitMutex);
- initEGL(false);
+ initEGL(true);
pthread_mutex_unlock(&gInitMutex);
}
diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp
index 8e9ba08..db40f16 100644
--- a/libs/rs/rsProgram.cpp
+++ b/libs/rs/rsProgram.cpp
@@ -67,7 +67,7 @@ bool Program::loadShader(uint32_t type)
mShaderID = glCreateShader(type);
rsAssert(mShaderID);
- LOGV("Loading shader type %x", type);
+ LOGV("Loading shader type %x, ID %i", type, mShaderID);
LOGE(mShader.string());
if (mShaderID) {
@@ -96,3 +96,9 @@ bool Program::loadShader(uint32_t type)
LOGV("--Shader load result %x ", glGetError());
return true;
}
+
+void Program::setShader(const char *txt, uint32_t len)
+{
+ mUserShader.setTo(txt, len);
+}
+
diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h
index 06c72f9..abd461b 100644
--- a/libs/rs/rsProgram.h
+++ b/libs/rs/rsProgram.h
@@ -40,6 +40,7 @@ public:
virtual void createShader();
uint32_t getShaderID() const {return mShaderID;}
+ void setShader(const char *, uint32_t len);
uint32_t getAttribCount() const {return mAttribCount;}
uint32_t getUniformCount() const {return mUniformCount;}
@@ -56,6 +57,7 @@ protected:
mutable bool mDirty;
String8 mShader;
+ String8 mUserShader;
uint32_t mShaderID;
uint32_t mAttribCount;
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index daefc2c..b239ce8 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -175,19 +175,27 @@ void ProgramFragment::createShader()
//mShader.append(" gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n");
mShader.append(" vec4 col = varColor;\n");
+ if (mTextureEnableMask) {
+ if (mPointSpriteEnable) {
+ mShader.append(" vec2 tex0 = gl_PointCoord;\n");
+ } else {
+ mShader.append(" vec2 tex0 = varTex0.xy;\n");
+ }
+ }
+
mask = mTextureEnableMask;
texNum = 0;
while (mask) {
if (mask & 1) {
switch(mEnvModes[texNum]) {
case RS_TEX_ENV_MODE_REPLACE:
- mShader.append(" col = texture2D(uni_Tex0, varTex0.xy);\n");
+ mShader.append(" col = texture2D(uni_Tex0, tex0);\n");
break;
case RS_TEX_ENV_MODE_MODULATE:
- mShader.append(" col *= texture2D(uni_Tex0, varTex0.xy);\n");
+ mShader.append(" col *= texture2D(uni_Tex0, tex0);\n");
break;
case RS_TEX_ENV_MODE_DECAL:
- mShader.append(" col = texture2D(uni_Tex0, varTex0.xy);\n");
+ mShader.append(" col = texture2D(uni_Tex0, tex0);\n");
break;
}
@@ -338,6 +346,11 @@ void rsi_ProgramFragmentSetSlot(Context *rsc, uint32_t slot, bool enable, RsTexE
rsc->mStateFragment.mPF->setTexEnable(slot, enable);
}
+void rsi_ProgramFragmentSetShader(Context *rsc, const char *txt, uint32_t len)
+{
+ rsc->mStateFragment.mPF->setShader(txt, len);
+}
+
RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc)
{
ProgramFragment *pf = rsc->mStateFragment.mPF;
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index 1776b02b..482739c 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -117,18 +117,24 @@ void ProgramVertex::createShader()
mShader.append("varying vec4 varColor;\n");
mShader.append("varying vec4 varTex0;\n");
- mShader.append("void main() {\n");
- mShader.append(" gl_Position = uni_MVP * attrib_Position;\n");
- mShader.append(" varColor = attrib_Color;\n");
- if (mTextureMatrixEnable) {
- mShader.append(" varTex0 = uni_TexMatrix * attrib_T0;\n");
+ if (mUserShader.length() > 1) {
+ mShader.append(mUserShader);
} else {
- mShader.append(" varTex0 = attrib_T0;\n");
+ mShader.append("void main() {\n");
+ mShader.append(" gl_Position = uni_MVP * attrib_Position;\n");
+ mShader.append(" gl_PointSize = attrib_PointSize.x;\n");
+
+ mShader.append(" varColor = attrib_Color;\n");
+ if (mTextureMatrixEnable) {
+ mShader.append(" varTex0 = uni_TexMatrix * attrib_T0;\n");
+ } else {
+ mShader.append(" varTex0 = attrib_T0;\n");
+ }
+ //mShader.append(" pos.x = pos.x / 480.0;\n");
+ //mShader.append(" pos.y = pos.y / 800.0;\n");
+ //mShader.append(" gl_Position = pos;\n");
+ mShader.append("}\n");
}
- //mShader.append(" pos.x = pos.x / 480.0;\n");
- //mShader.append(" pos.y = pos.y / 800.0;\n");
- //mShader.append(" gl_Position = pos;\n");
- mShader.append("}\n");
}
void ProgramVertex::setupGL2(const Context *rsc, ProgramVertexState *state, ShaderCache *sc)
@@ -211,7 +217,6 @@ void ProgramVertex::init(Context *rsc)
createShader();
}
-
///////////////////////////////////////////////////////////////////////
ProgramVertexState::ProgramVertexState()
@@ -294,6 +299,11 @@ void rsi_ProgramVertexSetTextureMatrixEnable(Context *rsc, bool enable)
rsc->mStateVertex.mPV->setTextureMatrixEnable(enable);
}
+void rsi_ProgramVertexSetShader(Context *rsc, const char *txt, uint32_t len)
+{
+ rsc->mStateVertex.mPV->setShader(txt, len);
+}
+
void rsi_ProgramVertexAddLight(Context *rsc, RsLight light)
{
rsc->mStateVertex.mPV->addLight(static_cast<const Light *>(light));
diff --git a/libs/rs/rsShaderCache.cpp b/libs/rs/rsShaderCache.cpp
index 2727e6c..4b16677 100644
--- a/libs/rs/rsShaderCache.cpp
+++ b/libs/rs/rsShaderCache.cpp
@@ -49,6 +49,7 @@ bool ShaderCache::lookup(ProgramVertex *vtx, ProgramFragment *frag)
if (!frag->getShaderID()) {
frag->loadShader();
}
+ //LOGV("ShaderCache lookup vtx %i, frag %i", vtx->getShaderID(), frag->getShaderID());
for (uint32_t ct=0; ct < mEntryCount; ct++) {
if ((mEntries[ct].vtx == vtx->getShaderID()) &&
@@ -57,6 +58,7 @@ bool ShaderCache::lookup(ProgramVertex *vtx, ProgramFragment *frag)
//LOGV("SC using program %i", mEntries[ct].program);
glUseProgram(mEntries[ct].program);
mCurrent = &mEntries[ct];
+ //LOGV("ShaderCache hit, using %i", ct);
return true;
}
}
@@ -75,8 +77,8 @@ bool ShaderCache::lookup(ProgramVertex *vtx, ProgramFragment *frag)
mEntries = e;
}
- LOGV("vtx %i, frag %i", vtx->getShaderID(), frag->getShaderID());
- LOGE("e0 %x", glGetError());
+ //LOGV("ShaderCache miss, using %i", mEntryCount);
+ //LOGE("e0 %x", glGetError());
entry_t *e = &mEntries[mEntryCount];
mCurrent = e;
@@ -125,7 +127,7 @@ bool ShaderCache::lookup(ProgramVertex *vtx, ProgramFragment *frag)
}
}
- LOGV("SC made program %i", e->program);
+ //LOGV("SC made program %i", e->program);
glUseProgram(e->program);
mEntryCount++;
return true;