* commit 'df36dd200c55a6ad463b46bab0ffff49d21206ff': update parameters in uploadToTexture() for GLES20
This commit is contained in:
@@ -242,19 +242,19 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege
|
|||||||
switch (bitmap->getConfig()) {
|
switch (bitmap->getConfig()) {
|
||||||
case SkBitmap::kA8_Config:
|
case SkBitmap::kA8_Config:
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(),
|
uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
|
||||||
texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
|
texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
|
||||||
texture->blend = true;
|
texture->blend = true;
|
||||||
break;
|
break;
|
||||||
case SkBitmap::kRGB_565_Config:
|
case SkBitmap::kRGB_565_Config:
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
|
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
|
||||||
uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(),
|
uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
|
||||||
texture->width, texture->height, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
|
texture->width, texture->height, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
|
||||||
texture->blend = false;
|
texture->blend = false;
|
||||||
break;
|
break;
|
||||||
case SkBitmap::kARGB_8888_Config:
|
case SkBitmap::kARGB_8888_Config:
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
|
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
|
||||||
uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(),
|
uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
|
||||||
texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
|
texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
|
||||||
// Do this after calling getPixels() to make sure Skia's deferred
|
// Do this after calling getPixels() to make sure Skia's deferred
|
||||||
// decoding happened
|
// decoding happened
|
||||||
@@ -294,27 +294,49 @@ void TextureCache::uploadLoFiTexture(bool resize, SkBitmap* bitmap,
|
|||||||
SkCanvas canvas(rgbaBitmap);
|
SkCanvas canvas(rgbaBitmap);
|
||||||
canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL);
|
canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL);
|
||||||
|
|
||||||
uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), width, height,
|
uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), rgbaBitmap.bytesPerPixel(),
|
||||||
GL_UNSIGNED_BYTE, rgbaBitmap.getPixels());
|
width, height, GL_UNSIGNED_BYTE, rgbaBitmap.getPixels());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei stride,
|
void TextureCache::uploadToTexture(bool resize, GLenum format, GLsizei stride, GLsizei bpp,
|
||||||
GLsizei width, GLsizei height, GLenum type, const GLvoid * data) {
|
GLsizei width, GLsizei height, GLenum type, const GLvoid * data) {
|
||||||
// TODO: With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
|
|
||||||
// if the stride doesn't match the width
|
|
||||||
const bool useStride = stride != width && Extensions::getInstance().hasUnpackRowLength();
|
const bool useStride = stride != width && Extensions::getInstance().hasUnpackRowLength();
|
||||||
if (useStride) {
|
if ((stride == width) || useStride) {
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
|
if (useStride) {
|
||||||
}
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
|
||||||
|
}
|
||||||
|
|
||||||
if (resize) {
|
if (resize) {
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data);
|
||||||
|
} else {
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useStride) {
|
||||||
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
|
// With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
|
||||||
}
|
// if the stride doesn't match the width
|
||||||
|
|
||||||
if (useStride) {
|
GLvoid * temp = (GLvoid *) malloc(width * height * bpp);
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
if (!temp) return;
|
||||||
|
|
||||||
|
uint8_t * pDst = (uint8_t *)temp;
|
||||||
|
uint8_t * pSrc = (uint8_t *)data;
|
||||||
|
for (GLsizei i = 0; i < height; i++) {
|
||||||
|
memcpy(pDst, pSrc, width * bpp);
|
||||||
|
pDst += width * bpp;
|
||||||
|
pSrc += stride * bpp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resize) {
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, temp);
|
||||||
|
} else {
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ private:
|
|||||||
void generateTexture(SkBitmap* bitmap, Texture* texture, bool regenerate = false);
|
void generateTexture(SkBitmap* bitmap, Texture* texture, bool regenerate = false);
|
||||||
|
|
||||||
void uploadLoFiTexture(bool resize, SkBitmap* bitmap, uint32_t width, uint32_t height);
|
void uploadLoFiTexture(bool resize, SkBitmap* bitmap, uint32_t width, uint32_t height);
|
||||||
void uploadToTexture(bool resize, GLenum format, GLsizei stride,
|
void uploadToTexture(bool resize, GLenum format, GLsizei stride, GLsizei bpp,
|
||||||
GLsizei width, GLsizei height, GLenum type, const GLvoid * data);
|
GLsizei width, GLsizei height, GLenum type, const GLvoid * data);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|||||||
Reference in New Issue
Block a user