Merge "Cleanup GL setup code and remove legacy 1.1 paths. Reset pointers to NULL when allocations are unbound."

This commit is contained in:
Jason Sams
2010-09-16 18:21:29 -07:00
committed by Android (Google) Code Review
16 changed files with 31 additions and 128 deletions

View File

@@ -724,10 +724,7 @@ RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h
const Element *src = static_cast<const Element *>(_src);
const Element *dst = static_cast<const Element *>(_dst);
// Check for pow2 on pre es 2.0 versions.
rsAssert(rsc->checkVersion2_0() || (!(w & (w-1)) && !(h & (h-1))));
//LOGE("rsi_AllocationCreateFromBitmap %i %i %i %i %i", w, h, dstFmt, srcFmt, genMips);
//LOGE("%p rsi_AllocationCreateFromBitmap %i %i %i", rsc, w, h, genMips);
rsi_TypeBegin(rsc, _dst);
rsi_TypeAdd(rsc, RS_DIMENSION_X, w);
rsi_TypeAdd(rsc, RS_DIMENSION_Y, h);

View File

@@ -90,6 +90,7 @@ public:
void decRefs(const void *ptr, size_t ct) const;
void sendDirty() const;
bool getHasGraphicsMipmaps() const {return mTextureGenMipmap;}
protected:
ObjectBaseRef<const Type> mType;

View File

@@ -232,23 +232,15 @@ void Context::timerPrint()
bool Context::setupCheck()
{
if (checkVersion2_0()) {
if (!mShaderCache.lookup(this, mVertex.get(), mFragment.get())) {
LOGE("Context::setupCheck() 1 fail");
return false;
}
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);
if (!mShaderCache.lookup(this, mVertex.get(), mFragment.get())) {
LOGE("Context::setupCheck() 1 fail");
return false;
}
mFragmentStore->setupGL2(this, &mStateFragmentStore);
mFragment->setupGL2(this, &mStateFragment, &mShaderCache);
mRaster->setupGL2(this, &mStateRaster);
mVertex->setupGL2(this, &mStateVertex, &mShaderCache);
return true;
}
@@ -940,6 +932,7 @@ RsContext rsContextCreateGL(RsDevice vdev, uint32_t version, bool useDepth)
LOGV("rsContextCreateGL %p, %i", vdev, useDepth);
Device * dev = static_cast<Device *>(vdev);
Context *rsc = new Context(dev, true, useDepth);
LOGV("rsContextCreateGL ret %p ", rsc);
return rsc;
}

View File

@@ -153,9 +153,6 @@ public:
void timerPrint();
void timerFrame();
bool checkVersion1_1() const {return (mGL.mMajorVersion > 1) || (mGL.mMinorVersion >= 1); }
bool checkVersion2_0() const {return mGL.mMajorVersion >= 2; }
struct {
bool mLogTimes;
bool mLogScripts;

View File

@@ -103,13 +103,8 @@ void ProgramFragment::setConstantColor(float r, float g, float b, float a)
mDirty = true;
}
void ProgramFragment::setupGL(const Context *rsc, ProgramFragmentState *state)
{
}
void ProgramFragment::setupGL2(const Context *rsc, ProgramFragmentState *state, ShaderCache *sc)
{
//LOGE("sgl2 frag1 %x", glGetError());
if ((state->mLast.get() == this) && !mDirty) {
return;
@@ -131,12 +126,12 @@ void ProgramFragment::setupGL2(const Context *rsc, ProgramFragmentState *state,
glBindTexture(GL_TEXTURE_2D, mTextures[ct]->getTextureID());
rsc->checkError("ProgramFragment::setupGL2 tex bind");
if (mSamplers[ct].get()) {
mSamplers[ct]->setupGL(rsc, mTextures[ct]->getType()->getIsNp2());
mSamplers[ct]->setupGL(rsc, mTextures[ct].get());
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
rsc->checkError("ProgramFragment::setupGL2 tex env");
}

View File

@@ -34,7 +34,6 @@ public:
uint32_t paramLength);
virtual ~ProgramFragment();
virtual void setupGL(const Context *, ProgramFragmentState *);
virtual void setupGL2(const Context *, ProgramFragmentState *, ShaderCache *sc);
virtual void createShader();

View File

@@ -61,52 +61,6 @@ void ProgramRaster::setCullMode(RsCullMode mode)
mDirty = true;
}
void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
{
if (state->mLast.get() == this && !mDirty) {
return;
}
state->mLast.set(this);
mDirty = false;
if (mPointSmooth) {
glEnable(GL_POINT_SMOOTH);
} else {
glDisable(GL_POINT_SMOOTH);
}
glLineWidth(mLineWidth);
if (mLineSmooth) {
glEnable(GL_LINE_SMOOTH);
} else {
glDisable(GL_LINE_SMOOTH);
}
if (rsc->checkVersion1_1()) {
#ifndef ANDROID_RS_BUILD_FOR_HOST
if (mPointSprite) {
glEnable(GL_POINT_SPRITE_OES);
} else {
glDisable(GL_POINT_SPRITE_OES);
}
#endif //ANDROID_RS_BUILD_FOR_HOST
}
switch(mCull) {
case RS_CULL_BACK:
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
break;
case RS_CULL_FRONT:
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
break;
case RS_CULL_NONE:
glDisable(GL_CULL_FACE);
break;
}
}
void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state)
{
if (state->mLast.get() == this && !mDirty) {

View File

@@ -34,7 +34,6 @@ public:
bool pointSprite);
virtual ~ProgramRaster();
virtual void setupGL(const Context *, ProgramRasterState *);
virtual void setupGL2(const Context *, ProgramRasterState *);
virtual void serialize(OStream *stream) const;
virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; }

View File

@@ -56,41 +56,6 @@ ProgramStore::~ProgramStore()
{
}
void ProgramStore::setupGL(const Context *rsc, ProgramStoreState *state)
{
if (state->mLast.get() == this) {
return;
}
state->mLast.set(this);
glColorMask(mColorRWriteEnable,
mColorGWriteEnable,
mColorBWriteEnable,
mColorAWriteEnable);
if (mBlendEnable) {
glEnable(GL_BLEND);
glBlendFunc(mBlendSrc, mBlendDst);
} else {
glDisable(GL_BLEND);
}
//LOGE("pfs %i, %i, %x", mDepthWriteEnable, mDepthTestEnable, mDepthFunc);
glDepthMask(mDepthWriteEnable);
if(mDepthTestEnable || mDepthWriteEnable) {
glEnable(GL_DEPTH_TEST);
glDepthFunc(mDepthFunc);
} else {
glDisable(GL_DEPTH_TEST);
}
if (mDitherEnable) {
glEnable(GL_DITHER);
} else {
glDisable(GL_DITHER);
}
}
void ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state)
{
if (state->mLast.get() == this) {

View File

@@ -32,7 +32,6 @@ public:
ProgramStore(Context *);
virtual ~ProgramStore();
virtual void setupGL(const Context *, ProgramStoreState *);
virtual void setupGL2(const Context *, ProgramStoreState *);
void setDepthFunc(RsDepthFunc);

View File

@@ -68,11 +68,6 @@ static void logMatrix(const char *txt, const float *f)
LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[3], f[7], f[11], f[15]);
}
void ProgramVertex::setupGL(const Context *rsc, ProgramVertexState *state)
{
assert(0);
}
void ProgramVertex::loadShader(Context *rsc) {
Program::loadShader(rsc, GL_VERTEX_SHADER);
}

View File

@@ -35,7 +35,6 @@ public:
ProgramVertex(Context *, bool texMat);
virtual ~ProgramVertex();
virtual void setupGL(const Context *rsc, ProgramVertexState *state);
virtual void setupGL2(const Context *rsc, ProgramVertexState *state, ShaderCache *sc);

View File

@@ -59,7 +59,7 @@ Sampler::~Sampler()
{
}
void Sampler::setupGL(const Context *rsc, bool npot)
void Sampler::setupGL(const Context *rsc, const Allocation *tex)
{
GLenum trans[] = {
GL_NEAREST, //RS_SAMPLER_NEAREST,
@@ -77,13 +77,17 @@ void Sampler::setupGL(const Context *rsc, bool npot)
GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP
};
if (!rsc->ext_OES_texture_npot() && npot) {
if (!rsc->ext_OES_texture_npot() && tex->getType()->getIsNp2()) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, transNP[mMinFilter]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, transNP[mMagFilter]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, transNP[mWrapS]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, transNP[mWrapT]);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, trans[mMinFilter]);
if (tex->getHasGraphicsMipmaps()) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, trans[mMinFilter]);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, transNP[mMinFilter]);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, trans[mMagFilter]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, trans[mWrapS]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, trans[mWrapT]);

View File

@@ -41,7 +41,7 @@ public:
virtual ~Sampler();
void bind(Allocation *);
void setupGL(const Context *, bool npot);
void setupGL(const Context *, const Allocation *);
void bindToContext(SamplerState *, uint32_t slot);
void unbindFromContext(SamplerState *);

View File

@@ -56,9 +56,16 @@ void ScriptC::setupScript(Context *rsc)
= nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) {
if (!mSlots[ct].get())
if (mSlots[ct].get() && !mTypes[ct].get()) {
mTypes[ct].set(mSlots[ct]->getType());
}
if (!mTypes[ct].get())
continue;
void *ptr = mSlots[ct]->getPtr();
void *ptr = NULL;
if (mSlots[ct].get()) {
ptr = mSlots[ct]->getPtr();
}
void **dest = ((void ***)mEnviroment.mFieldAddress)[ct];
//LOGE("setupScript %i %p = %p %p %i", ct, dest, ptr, mSlots[ct]->getType(), mSlots[ct]->getType()->getDimX());

View File

@@ -65,7 +65,6 @@ public:
//void addLegacy(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset);
void add(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name);
void setupGL(const Context *rsc, class VertexArrayState *) const;
void setupGL2(const Context *rsc, class VertexArrayState *, ShaderCache *) const;
void logAttrib(uint32_t idx, uint32_t slot) const;