summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2011-05-27 11:37:45 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-05-27 11:37:45 -0700
commit41d8165b94243953c286b92260e283fb6032a529 (patch)
tree92ea1af811fd32530561ffce4a4b369819ea8873 /libs
parent5ff0f99b23da389f59fe736c4c670c60f13be8ea (diff)
parent66db3ab50f9aeb1d45c50a079a4f8836b2e3864e (diff)
downloadframeworks_base-41d8165b94243953c286b92260e283fb6032a529.zip
frameworks_base-41d8165b94243953c286b92260e283fb6032a529.tar.gz
frameworks_base-41d8165b94243953c286b92260e283fb6032a529.tar.bz2
Merge "Cleaup of rsComponent to remove GL types."
Diffstat (limited to 'libs')
-rw-r--r--libs/rs/driver/rsdAllocation.cpp58
-rw-r--r--libs/rs/driver/rsdAllocation.h7
-rw-r--r--libs/rs/driver/rsdMeshObj.cpp2
-rw-r--r--libs/rs/rsComponent.cpp40
-rw-r--r--libs/rs/rsComponent.h2
5 files changed, 51 insertions, 58 deletions
diff --git a/libs/rs/driver/rsdAllocation.cpp b/libs/rs/driver/rsdAllocation.cpp
index f58fe1a..2e13e9d 100644
--- a/libs/rs/driver/rsdAllocation.cpp
+++ b/libs/rs/driver/rsdAllocation.cpp
@@ -41,13 +41,42 @@ const static GLenum gFaceOrder[] = {
};
+GLenum rsdTypeToGLType(RsDataType t) {
+ switch (t) {
+ case RS_TYPE_UNSIGNED_5_6_5: return GL_UNSIGNED_SHORT_5_6_5;
+ case RS_TYPE_UNSIGNED_5_5_5_1: return GL_UNSIGNED_SHORT_5_5_5_1;
+ case RS_TYPE_UNSIGNED_4_4_4_4: return GL_UNSIGNED_SHORT_4_4_4_4;
+
+ //case RS_TYPE_FLOAT_16: return GL_HALF_FLOAT;
+ case RS_TYPE_FLOAT_32: return GL_FLOAT;
+ case RS_TYPE_UNSIGNED_8: return GL_UNSIGNED_BYTE;
+ case RS_TYPE_UNSIGNED_16: return GL_UNSIGNED_SHORT;
+ case RS_TYPE_SIGNED_8: return GL_BYTE;
+ case RS_TYPE_SIGNED_16: return GL_SHORT;
+ default: break;
+ }
+ return 0;
+}
+
+GLenum rsdKindToGLFormat(RsDataKind k) {
+ switch (k) {
+ case RS_KIND_PIXEL_L: return GL_LUMINANCE;
+ case RS_KIND_PIXEL_A: return GL_ALPHA;
+ case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA;
+ case RS_KIND_PIXEL_RGB: return GL_RGB;
+ case RS_KIND_PIXEL_RGBA: return GL_RGBA;
+ case RS_KIND_PIXEL_DEPTH: return GL_DEPTH_COMPONENT16;
+ default: break;
+ }
+ return 0;
+}
+
+
static void Update2DTexture(const Allocation *alloc, const void *ptr, uint32_t xoff, uint32_t yoff,
uint32_t lod, RsAllocationCubemapFace face,
uint32_t w, uint32_t h) {
DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
- const GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType();
- const GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat();
rsAssert(drv->textureID);
glBindTexture(drv->glTarget, drv->textureID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -55,16 +84,13 @@ static void Update2DTexture(const Allocation *alloc, const void *ptr, uint32_t x
if (alloc->mHal.state.hasFaces) {
t = gFaceOrder[face];
}
- glTexSubImage2D(t, lod, xoff, yoff, w, h, format, type, ptr);
+ glTexSubImage2D(t, lod, xoff, yoff, w, h, drv->glFormat, drv->glType, ptr);
}
static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool isFirstUpload) {
DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
- GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType();
- GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat();
-
glBindTexture(drv->glTarget, drv->textureID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -85,15 +111,15 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is
}
if (isFirstUpload) {
- glTexImage2D(t, lod, format,
+ glTexImage2D(t, lod, drv->glFormat,
alloc->mHal.state.type->getLODDimX(lod),
alloc->mHal.state.type->getLODDimY(lod),
- 0, format, type, p);
+ 0, drv->glFormat, drv->glType, p);
} else {
glTexSubImage2D(t, lod, 0, 0,
alloc->mHal.state.type->getLODDimX(lod),
alloc->mHal.state.type->getLODDimY(lod),
- format, type, p);
+ drv->glFormat, drv->glType, p);
}
}
}
@@ -107,10 +133,7 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is
static void UploadToTexture(const Context *rsc, const Allocation *alloc) {
DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
- GLenum type = alloc->mHal.state.type->getElement()->getComponent().getGLType();
- GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat();
-
- if (!type || !format) {
+ if (!drv->glType || !drv->glFormat) {
return;
}
@@ -139,8 +162,7 @@ static void UploadToTexture(const Context *rsc, const Allocation *alloc) {
static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) {
DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
- GLenum format = alloc->mHal.state.type->getElement()->getComponent().getGLFormat();
- if (!format) {
+ if (!drv->glFormat) {
return;
}
@@ -154,7 +176,7 @@ static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) {
return;
}
glBindRenderbuffer(GL_RENDERBUFFER, drv->renderTargetID);
- glRenderbufferStorage(GL_RENDERBUFFER, format,
+ glRenderbufferStorage(GL_RENDERBUFFER, drv->glFormat,
alloc->mHal.state.dimensionX, alloc->mHal.state.dimensionY);
}
rsdGLCheckError(rsc, "AllocateRenderTarget");
@@ -208,6 +230,10 @@ bool rsdAllocationInit(const Context *rsc, Allocation *alloc, bool forceZero) {
}
}
+ drv->glType = rsdTypeToGLType(alloc->mHal.state.type->getElement()->getComponent().getType());
+ drv->glFormat = rsdKindToGLFormat(alloc->mHal.state.type->getElement()->getComponent().getKind());
+
+
alloc->mHal.drvState.mallocPtr = ptr;
drv->mallocPtr = (uint8_t *)ptr;
alloc->mHal.drv = drv;
diff --git a/libs/rs/driver/rsdAllocation.h b/libs/rs/driver/rsdAllocation.h
index 45a538b..d7385ce 100644
--- a/libs/rs/driver/rsdAllocation.h
+++ b/libs/rs/driver/rsdAllocation.h
@@ -39,10 +39,17 @@ struct DrvAllocation {
uint8_t * mallocPtr;
GLenum glTarget;
+ GLenum glType;
+ GLenum glFormat;
+
bool uploadDeferred;
};
+GLenum rsdTypeToGLType(RsDataType t);
+GLenum rsdKindToGLFormat(RsDataKind k);
+
+
bool rsdAllocationInit(const android::renderscript::Context *rsc,
android::renderscript::Allocation *alloc,
bool forceZero);
diff --git a/libs/rs/driver/rsdMeshObj.cpp b/libs/rs/driver/rsdMeshObj.cpp
index 260595c..c220ac1 100644
--- a/libs/rs/driver/rsdMeshObj.cpp
+++ b/libs/rs/driver/rsdMeshObj.cpp
@@ -114,7 +114,7 @@ bool RsdMeshObj::init() {
mAttribs[userNum].size = c.getVectorSize();
mAttribs[userNum].offset = elem->getFieldOffsetBytes(fieldI);
- mAttribs[userNum].type = c.getGLType();
+ mAttribs[userNum].type = rsdTypeToGLType(c.getType());
mAttribs[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized();
mAttribs[userNum].stride = stride;
String8 tmp(RS_SHADER_ATTR);
diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp
index e2ae043..e65febb 100644
--- a/libs/rs/rsComponent.cpp
+++ b/libs/rs/rsComponent.cpp
@@ -16,11 +16,6 @@
#include "rsComponent.h"
-#ifndef ANDROID_RS_SERIALIZE
-#include <GLES/gl.h>
-#include <GLES2/gl2.h>
-#endif
-
using namespace android;
using namespace android::renderscript;
@@ -181,40 +176,6 @@ bool Component::isReference() const {
return (mType >= RS_TYPE_ELEMENT);
}
-uint32_t Component::getGLType() const {
-#ifndef ANDROID_RS_SERIALIZE
- switch (mType) {
- case RS_TYPE_UNSIGNED_5_6_5: return GL_UNSIGNED_SHORT_5_6_5;
- case RS_TYPE_UNSIGNED_5_5_5_1: return GL_UNSIGNED_SHORT_5_5_5_1;
- case RS_TYPE_UNSIGNED_4_4_4_4: return GL_UNSIGNED_SHORT_4_4_4_4;
-
- //case RS_TYPE_FLOAT_16: return GL_HALF_FLOAT;
- case RS_TYPE_FLOAT_32: return GL_FLOAT;
- case RS_TYPE_UNSIGNED_8: return GL_UNSIGNED_BYTE;
- case RS_TYPE_UNSIGNED_16: return GL_UNSIGNED_SHORT;
- case RS_TYPE_SIGNED_8: return GL_BYTE;
- case RS_TYPE_SIGNED_16: return GL_SHORT;
- default: break;
- }
-#endif //ANDROID_RS_SERIALIZE
- return 0;
-}
-
-uint32_t Component::getGLFormat() const {
-#ifndef ANDROID_RS_SERIALIZE
- switch (mKind) {
- case RS_KIND_PIXEL_L: return GL_LUMINANCE;
- case RS_KIND_PIXEL_A: return GL_ALPHA;
- case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA;
- case RS_KIND_PIXEL_RGB: return GL_RGB;
- case RS_KIND_PIXEL_RGBA: return GL_RGBA;
- case RS_KIND_PIXEL_DEPTH: return GL_DEPTH_COMPONENT16;
- default: break;
- }
-#endif //ANDROID_RS_SERIALIZE
- return 0;
-}
-
String8 Component::getGLSLType() const {
if (mType == RS_TYPE_SIGNED_32) {
switch (mVectorSize) {
@@ -244,6 +205,7 @@ String8 Component::getGLSLType() const {
return String8();
}
+
static const char * gTypeBasicStrings[] = {
"NONE",
"F16",
diff --git a/libs/rs/rsComponent.h b/libs/rs/rsComponent.h
index 1bb4ff4..a448f0e 100644
--- a/libs/rs/rsComponent.h
+++ b/libs/rs/rsComponent.h
@@ -32,8 +32,6 @@ public:
void set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize=1);
- uint32_t getGLType() const;
- uint32_t getGLFormat() const;
String8 getGLSLType() const;
void dumpLOGV(const char *prefix) const;