Merge "Implement sub updates for mipmap levels and cubmaps." into honeycomb
This commit is contained in:
@@ -188,12 +188,7 @@ void Allocation::uploadToTexture(const Context *rsc) {
|
|||||||
isFirstUpload = true;
|
isFirstUpload = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum target = (GLenum)getGLTarget();
|
upload2DTexture(isFirstUpload);
|
||||||
if (target == GL_TEXTURE_2D) {
|
|
||||||
upload2DTexture(isFirstUpload, mPtr);
|
|
||||||
} else if (target == GL_TEXTURE_CUBE_MAP) {
|
|
||||||
uploadCubeTexture(isFirstUpload);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)) {
|
if (!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)) {
|
||||||
freeScriptMemory();
|
freeScriptMemory();
|
||||||
@@ -202,6 +197,15 @@ void Allocation::uploadToTexture(const Context *rsc) {
|
|||||||
rsc->checkError("Allocation::uploadToTexture");
|
rsc->checkError("Allocation::uploadToTexture");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const static GLenum gFaceOrder[] = {
|
||||||
|
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||||
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||||
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||||
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||||
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||||
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
||||||
|
};
|
||||||
|
|
||||||
void Allocation::update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
|
void Allocation::update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
|
||||||
uint32_t lod, RsAllocationCubemapFace face,
|
uint32_t lod, RsAllocationCubemapFace face,
|
||||||
uint32_t w, uint32_t h) {
|
uint32_t w, uint32_t h) {
|
||||||
@@ -210,10 +214,14 @@ void Allocation::update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
|
|||||||
GLenum target = (GLenum)getGLTarget();
|
GLenum target = (GLenum)getGLTarget();
|
||||||
glBindTexture(target, mTextureID);
|
glBindTexture(target, mTextureID);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, lod, xoff, yoff, w, h, format, type, ptr);
|
GLenum t = GL_TEXTURE_2D;
|
||||||
|
if (mType->getDimFaces()) {
|
||||||
|
t = gFaceOrder[face];
|
||||||
|
}
|
||||||
|
glTexSubImage2D(t, lod, xoff, yoff, w, h, format, type, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Allocation::upload2DTexture(bool isFirstUpload, const void *ptr) {
|
void Allocation::upload2DTexture(bool isFirstUpload) {
|
||||||
GLenum type = mType->getElement()->getComponent().getGLType();
|
GLenum type = mType->getElement()->getComponent().getGLType();
|
||||||
GLenum format = mType->getElement()->getComponent().getGLFormat();
|
GLenum format = mType->getElement()->getComponent().getGLFormat();
|
||||||
|
|
||||||
@@ -221,62 +229,29 @@ void Allocation::upload2DTexture(bool isFirstUpload, const void *ptr) {
|
|||||||
glBindTexture(target, mTextureID);
|
glBindTexture(target, mTextureID);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) {
|
uint32_t faceCount = 1;
|
||||||
const uint8_t *p = (const uint8_t *)ptr;
|
if (mType->getDimFaces()) {
|
||||||
p += mType->getLODOffset(lod);
|
faceCount = 6;
|
||||||
|
|
||||||
if (isFirstUpload) {
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, lod, format,
|
|
||||||
mType->getLODDimX(lod), mType->getLODDimY(lod),
|
|
||||||
0, format, type, p);
|
|
||||||
} else {
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, lod, 0, 0,
|
|
||||||
mType->getLODDimX(lod), mType->getLODDimY(lod),
|
|
||||||
format, type, p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) {
|
for (uint32_t face = 0; face < faceCount; face ++) {
|
||||||
#ifndef ANDROID_RS_BUILD_FOR_HOST
|
|
||||||
glGenerateMipmap(target);
|
|
||||||
#endif //ANDROID_RS_BUILD_FOR_HOST
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Allocation::uploadCubeTexture(bool isFirstUpload) {
|
|
||||||
GLenum type = mType->getElement()->getComponent().getGLType();
|
|
||||||
GLenum format = mType->getElement()->getComponent().getGLFormat();
|
|
||||||
|
|
||||||
GLenum target = (GLenum)getGLTarget();
|
|
||||||
glBindTexture(target, mTextureID);
|
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
||||||
|
|
||||||
GLenum faceOrder[] = {
|
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
||||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
|
|
||||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
|
|
||||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
|
||||||
};
|
|
||||||
|
|
||||||
Adapter2D adapt(getContext(), this);
|
|
||||||
for (uint32_t face = 0; face < 6; face ++) {
|
|
||||||
adapt.setFace(face);
|
|
||||||
|
|
||||||
for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) {
|
for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) {
|
||||||
adapt.setLOD(lod);
|
const uint8_t *p = (const uint8_t *)mPtr;
|
||||||
|
p += mType->getLODFaceOffset(lod, (RsAllocationCubemapFace)face, 0, 0);
|
||||||
|
|
||||||
uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0));
|
GLenum t = GL_TEXTURE_2D;
|
||||||
|
if (mType->getDimFaces()) {
|
||||||
|
t = gFaceOrder[face];
|
||||||
|
}
|
||||||
|
|
||||||
if (isFirstUpload) {
|
if (isFirstUpload) {
|
||||||
glTexImage2D(faceOrder[face], lod, format,
|
glTexImage2D(t, lod, format,
|
||||||
adapt.getDimX(), adapt.getDimY(),
|
mType->getLODDimX(lod), mType->getLODDimY(lod),
|
||||||
0, format, type, ptr);
|
0, format, type, p);
|
||||||
} else {
|
} else {
|
||||||
glTexSubImage2D(faceOrder[face], lod, 0, 0,
|
glTexSubImage2D(t, lod, 0, 0,
|
||||||
adapt.getDimX(), adapt.getDimY(),
|
mType->getLODDimX(lod), mType->getLODDimY(lod),
|
||||||
format, type, ptr);
|
format, type, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,7 +339,7 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod,
|
|||||||
if (mPtr) {
|
if (mPtr) {
|
||||||
const uint8_t *src = static_cast<const uint8_t *>(data);
|
const uint8_t *src = static_cast<const uint8_t *>(data);
|
||||||
uint8_t *dst = static_cast<uint8_t *>(mPtr);
|
uint8_t *dst = static_cast<uint8_t *>(mPtr);
|
||||||
dst += mType->getLODOffset(lod, xoff, yoff);
|
dst += mType->getLODFaceOffset(lod, face, xoff, yoff);
|
||||||
|
|
||||||
//LOGE(" %p %p %i ", dst, src, eSize);
|
//LOGE(" %p %p %i ", dst, src, eSize);
|
||||||
for (uint32_t line=yoff; line < (yoff+h); line++) {
|
for (uint32_t line=yoff; line < (yoff+h); line++) {
|
||||||
|
|||||||
@@ -105,9 +105,6 @@ public:
|
|||||||
return mMipmapControl != RS_ALLOCATION_MIPMAP_NONE;
|
return mMipmapControl != RS_ALLOCATION_MIPMAP_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void upload2DTexture(bool isFirstUpload, const void *ptr);
|
|
||||||
void update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
|
|
||||||
uint32_t lod, RsAllocationCubemapFace face, uint32_t w, uint32_t h);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ObjectBaseRef<const Type> mType;
|
ObjectBaseRef<const Type> mType;
|
||||||
@@ -149,7 +146,9 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void init(Context *rsc, const Type *);
|
void init(Context *rsc, const Type *);
|
||||||
void uploadCubeTexture(bool isFirstUpload);
|
void upload2DTexture(bool isFirstUpload);
|
||||||
|
void update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
|
||||||
|
uint32_t lod, RsAllocationCubemapFace face, uint32_t w, uint32_t h);
|
||||||
|
|
||||||
void allocScriptMemory();
|
void allocScriptMemory();
|
||||||
void freeScriptMemory();
|
void freeScriptMemory();
|
||||||
|
|||||||
@@ -132,6 +132,17 @@ uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) co
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t Type::getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face, uint32_t x, uint32_t y) const {
|
||||||
|
uint32_t offset = mLODs[lod].mOffset;
|
||||||
|
offset += (x + y * mLODs[lod].mX) * mElement->getSizeBytes();
|
||||||
|
|
||||||
|
if (face != 0) {
|
||||||
|
uint32_t faceOffset = getSizeBytes() / 6;
|
||||||
|
offset += faceOffset * face;
|
||||||
|
}
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
void Type::dumpLOGV(const char *prefix) const {
|
void Type::dumpLOGV(const char *prefix) const {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
ObjectBase::dumpLOGV(prefix);
|
ObjectBase::dumpLOGV(prefix);
|
||||||
|
|||||||
@@ -44,12 +44,14 @@ public:
|
|||||||
uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;}
|
uint32_t getLODDimX(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mX;}
|
||||||
uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;}
|
uint32_t getLODDimY(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mY;}
|
||||||
uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;}
|
uint32_t getLODDimZ(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mZ;}
|
||||||
uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;}
|
|
||||||
|
|
||||||
|
uint32_t getLODOffset(uint32_t lod) const {rsAssert(lod < mLODCount); return mLODs[lod].mOffset;}
|
||||||
uint32_t getLODOffset(uint32_t lod, uint32_t x) const;
|
uint32_t getLODOffset(uint32_t lod, uint32_t x) const;
|
||||||
uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const;
|
uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y) const;
|
||||||
uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const;
|
uint32_t getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) const;
|
||||||
|
|
||||||
|
uint32_t getLODFaceOffset(uint32_t lod, RsAllocationCubemapFace face, uint32_t x, uint32_t y) const;
|
||||||
|
|
||||||
uint32_t getLODCount() const {return mLODCount;}
|
uint32_t getLODCount() const {return mLODCount;}
|
||||||
bool getIsNp2() const;
|
bool getIsNp2() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user