diff options
| author | Jesse Hall <jessehall@google.com> | 2012-04-16 12:49:39 -0700 |
|---|---|---|
| committer | Jesse Hall <jessehall@google.com> | 2012-04-16 15:54:18 -0700 |
| commit | ce6c3389061fb9fcdefc94fab2044a8e11600b52 (patch) | |
| tree | fedd1a11cbd21ec14bf00be83b8712054f8c5506 /emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp | |
| parent | ad0111a77b0f0908cc945dc6e8e8949b75cb8886 (diff) | |
| download | sdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.zip sdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.tar.gz sdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.tar.bz2 | |
Move emulator GLES from development.git to sdk.git
The emulator GLES support has two interfaces: a host shared library
interface used by QEMU, and a protocol between the platform and the
host. The host library interface is not versioned; QEMU and the GLES
renderer must match. The protocol on the other hand must be backwards
compatible: a new GLES renderer must support an older platform image.
Thus for branching purposes it makes more sense to put the GLES
renderer in sdk.git, which is branched along with qemu.git for SDK
releases. Platform images will be built against the protocol version
in the platform branch of sdk.git.
Change-Id: I2c3bce627ecfd0a4b3e688d1839fe10755a21e58
Diffstat (limited to 'emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp')
| -rw-r--r-- | emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp b/emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp new file mode 100644 index 0000000..81152f6 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp @@ -0,0 +1,109 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <GLcommon/TextureUtils.h> +#include <GLcommon/GLESmacros.h> +#include <GLcommon/GLDispatch.h> +#include <GLcommon/GLESvalidate.h> +#include <stdio.h> +#include <cmath> + +int getCompressedFormats(int* formats){ + if(formats){ + //Palette + formats[0] = GL_PALETTE4_RGBA8_OES; + formats[1] = GL_PALETTE4_RGBA4_OES; + formats[2] = GL_PALETTE8_RGBA8_OES; + formats[3] = GL_PALETTE8_RGBA4_OES; + formats[4] = GL_PALETTE4_RGB8_OES; + formats[5] = GL_PALETTE8_RGB8_OES; + formats[6] = GL_PALETTE4_RGB5_A1_OES; + formats[7] = GL_PALETTE8_RGB5_A1_OES; + formats[8] = GL_PALETTE4_R5_G6_B5_OES; + formats[9] = GL_PALETTE8_R5_G6_B5_OES; + //ETC + formats[MAX_SUPPORTED_PALETTE] = GL_ETC1_RGB8_OES; + } + return MAX_SUPPORTED_PALETTE + MAX_ETC_SUPPORTED; +} + +void doCompressedTexImage2D(GLEScontext * ctx, GLenum target, GLint level, + GLenum internalformat, GLsizei width, + GLsizei height, GLint border, + GLsizei imageSize, const GLvoid* data, void * funcPtr) +{ + /* XXX: This is just a hack to fix the resolve of glTexImage2D problem + It will be removed when we'll no longer link against ligGL */ + typedef void (GLAPIENTRY *glTexImage2DPtr_t ) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); + glTexImage2DPtr_t glTexImage2DPtr; + glTexImage2DPtr = (glTexImage2DPtr_t)funcPtr; + + switch (internalformat) { + case GL_ETC1_RGB8_OES: + { + GLint format = GL_RGB; + GLint type = GL_UNSIGNED_BYTE; + + GLsizei compressedSize = etc1_get_encoded_data_size(width, height); + SET_ERROR_IF((compressedSize > imageSize), GL_INVALID_VALUE); + + const int32_t align = ctx->getUnpackAlignment()-1; + const int32_t bpr = ((width * 3) + align) & ~align; + const size_t size = bpr * height; + + etc1_byte* pOut = new etc1_byte[size]; + int res = etc1_decode_image((const etc1_byte*)data, pOut, width, height, 3, bpr); + SET_ERROR_IF(res!=0, GL_INVALID_VALUE); + glTexImage2DPtr(target,level,format,width,height,border,format,type,pOut); + delete [] pOut; + } + break; + + case GL_PALETTE4_RGB8_OES: + case GL_PALETTE4_RGBA8_OES: + case GL_PALETTE4_R5_G6_B5_OES: + case GL_PALETTE4_RGBA4_OES: + case GL_PALETTE4_RGB5_A1_OES: + case GL_PALETTE8_RGB8_OES: + case GL_PALETTE8_RGBA8_OES: + case GL_PALETTE8_R5_G6_B5_OES: + case GL_PALETTE8_RGBA4_OES: + case GL_PALETTE8_RGB5_A1_OES: + { + SET_ERROR_IF(level > log2(ctx->getMaxTexSize()) || + border !=0 || level > 0 || + !GLESvalidate::texImgDim(width,height,ctx->getMaxTexSize()+2),GL_INVALID_VALUE) + + int nMipmaps = -level + 1; + GLsizei tmpWidth = width; + GLsizei tmpHeight = height; + + for(int i = 0; i < nMipmaps ; i++) + { + GLenum uncompressedFrmt; + unsigned char* uncompressed = uncompressTexture(internalformat,uncompressedFrmt,width,height,imageSize,data,i); + glTexImage2DPtr(target,i,uncompressedFrmt,tmpWidth,tmpHeight,border,uncompressedFrmt,GL_UNSIGNED_BYTE,uncompressed); + tmpWidth/=2; + tmpHeight/=2; + delete[] uncompressed; + } + } + break; + + default: + SET_ERROR_IF(1, GL_INVALID_ENUM); + break; + } +} |
