diff options
Diffstat (limited to 'emulator/opengl')
5 files changed, 77 insertions, 17 deletions
diff --git a/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp b/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp index 31527af7e..eeaa25c3e 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp @@ -68,7 +68,15 @@ static EglConfig* pixelFormatToConfig(int index,int renderableType,EGLNativePixe getPixelFormatAttrib(*frmt,MAC_SAMPLES_PER_PIXEL,&samples); getPixelFormatAttrib(*frmt,MAC_COLOR_SIZE,&colorSize); - getPixelFormatAttrib(*frmt,MAC_ALPHA_SIZE,&alpha); + /* All configs can end up having an alpha channel even if none was requested. + * The default config chooser in GLSurfaceView will therefore not find any + * matching config. Thus, make sure alpha is zero (or at least signalled as + * zero to the calling EGL layer) for the configs where it was intended to + * be zero. */ + if (getPixelFormatDefinitionAlpha(index) == 0) + alpha = 0; + else + getPixelFormatAttrib(*frmt,MAC_ALPHA_SIZE,&alpha); getPixelFormatAttrib(*frmt,MAC_DEPTH_SIZE,&depth); getPixelFormatAttrib(*frmt,MAC_STENCIL_SIZE,&stencil); diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.h b/emulator/opengl/host/libs/Translator/EGL/MacNative.h index 82ab66763..c8a1df2bc 100644 --- a/emulator/opengl/host/libs/Translator/EGL/MacNative.h +++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.h @@ -33,6 +33,7 @@ extern "C"{ int getNumPixelFormats(); void* getPixelFormat(int i); +int getPixelFormatDefinitionAlpha(int i); void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val); void* nsCreateContext(void* format,void* share); void nsWindowMakeCurrent(void* context,void* nativeWin); diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.m b/emulator/opengl/host/libs/Translator/EGL/MacNative.m index 68286553f..a2cea93cb 100644 --- a/emulator/opengl/host/libs/Translator/EGL/MacNative.m +++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.m @@ -75,6 +75,34 @@ void* getPixelFormat(int i){ return [[NSOpenGLPixelFormat alloc] initWithAttributes:attrib_lists[i]]; } +int getPixelFormatDefinitionAlpha(int i) { + int size; + NSOpenGLPixelFormatAttribute** attrib_lists = getPixelFormatsAttributes(&size); + NSOpenGLPixelFormatAttribute* attribs = attrib_lists[i]; + while (*attribs) { + switch (*attribs) { + // These are the ones that take a value, according to the current + // NSOpenGLPixelFormat docs + case NSOpenGLPFAAuxBuffers: + case NSOpenGLPFAColorSize: + case NSOpenGLPFADepthSize: + case NSOpenGLPFAStencilSize: + case NSOpenGLPFAAccumSize: + case NSOpenGLPFARendererID: + case NSOpenGLPFAScreenMask: + attribs += 2; + break; + case NSOpenGLPFAAlphaSize: + return attribs[1]; + break; + // All other attributes are boolean attributes that don't take a value + default: + attribs++; + } + } + return 0; +} + void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val){ NSOpenGLPixelFormat *frmt = (NSOpenGLPixelFormat *)pixelFormat; [frmt getValues:val forAttribute:attrib forVirtualScreen:0]; diff --git a/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp b/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp index 5ba609b08..2d6f11932 100644 --- a/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp +++ b/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp @@ -35,13 +35,14 @@ bool Range::rangeUnion(const Range& r,Range& rOut) const { int size = max_end - min_start; if(size) { rOut.setRange(min_start,max_end-min_start); - return false; + return true; } return false; } void RangeList::addRange(const Range& r) { - list.push_back(r); + if(r.getSize()) + list.push_back(r); } void RangeList::addRanges(const RangeList& rl) { diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp index 8504f7f78..c7da37afc 100644 --- a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp +++ b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp @@ -16,10 +16,19 @@ #include "GLSharedGroup.h" +/**** KeyedVector utilities ****/ + +template <typename T> +static void clearObjectMap(android::DefaultKeyedVector<GLuint, T>& v) { + for (size_t i = 0; i < v.size(); i++) + delete v.valueAt(i); + v.clear(); +} + /**** BufferData ****/ BufferData::BufferData() : m_size(0) {}; -BufferData::BufferData(GLsizeiptr size, void * data) : m_size(size) +BufferData::BufferData(GLsizeiptr size, void * data) : m_size(size) { void * buffer = NULL; if (size>0) buffer = m_fixedBuffer.alloc(size); @@ -55,7 +64,7 @@ ProgramData::~ProgramData() } void ProgramData::setIndexInfo(GLuint index, GLint base, GLint size, GLenum type) -{ +{ if (index>=m_numIndexes) return; m_Indexes[index].base = base; @@ -87,7 +96,7 @@ GLuint ProgramData::getIndexForLocation(GLint location) for (GLuint i=0;i<m_numIndexes;++i) { GLint dist = location - m_Indexes[i].base; - if (dist >= 0 && + if (dist >= 0 && (minDist < 0 || dist < minDist)) { index = i; minDist = dist; @@ -126,7 +135,7 @@ GLint ProgramData::locationWARHostToApp(GLint hostLoc, GLint arrIndex) GLuint index = getIndexForLocation(hostLoc); if (index<m_numIndexes) { if (arrIndex > 0) { - m_Indexes[index].hostLocsPerElement = + m_Indexes[index].hostLocsPerElement = (hostLoc - m_Indexes[index].base) / arrIndex; } return m_Indexes[index].appBase + arrIndex; @@ -226,12 +235,15 @@ GLSharedGroup::~GLSharedGroup() { m_buffers.clear(); m_programs.clear(); + clearObjectMap(m_buffers); + clearObjectMap(m_programs); + clearObjectMap(m_shaders); } BufferData * GLSharedGroup::getBufferData(GLuint bufferId) { android::AutoMutex _lock(m_lock); - return m_buffers.valueFor(bufferId); + return m_buffers.valueFor(bufferId); } void GLSharedGroup::addBufferData(GLuint bufferId, GLsizeiptr size, void * data) @@ -243,32 +255,42 @@ void GLSharedGroup::addBufferData(GLuint bufferId, GLsizeiptr size, void * data) void GLSharedGroup::updateBufferData(GLuint bufferId, GLsizeiptr size, void * data) { android::AutoMutex _lock(m_lock); - m_buffers.replaceValueFor(bufferId, new BufferData(size, data)); + ssize_t idx = m_buffers.indexOfKey(bufferId); + if (idx >= 0) { + delete m_buffers.valueAt(idx); + m_buffers.editValueAt(idx) = new BufferData(size, data); + } else { + m_buffers.add(bufferId, new BufferData(size, data)); + } } GLenum GLSharedGroup::subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsizeiptr size, void * data) { android::AutoMutex _lock(m_lock); BufferData * buf = m_buffers.valueFor(bufferId); - if ((!buf) || (buf->m_size < offset+size) || (offset < 0) || (size<0)) return GL_INVALID_VALUE; + if ((!buf) || (buf->m_size < offset+size) || (offset < 0) || (size<0)) return GL_INVALID_VALUE; //it's safe to update now memcpy((char*)buf->m_fixedBuffer.ptr() + offset, data, size); - return GL_NO_ERROR; + return GL_NO_ERROR; } void GLSharedGroup::deleteBufferData(GLuint bufferId) { android::AutoMutex _lock(m_lock); - m_buffers.removeItem(bufferId); + ssize_t idx = m_buffers.indexOfKey(bufferId); + if (idx >= 0) { + delete m_buffers.valueAt(idx); + m_buffers.removeItemsAt(idx); + } } void GLSharedGroup::addProgramData(GLuint program) { android::AutoMutex _lock(m_lock); ProgramData *pData = m_programs.valueFor(program); - if (pData) - { + if (pData) + { m_programs.removeItem(program); delete pData; } @@ -290,7 +312,7 @@ bool GLSharedGroup::isProgramInitialized(GLuint program) { android::AutoMutex _lock(m_lock); ProgramData* pData = m_programs.valueFor(program); - if (pData) + if (pData) { return pData->isInitialized(); } @@ -303,7 +325,7 @@ void GLSharedGroup::deleteProgramData(GLuint program) ProgramData *pData = m_programs.valueFor(program); if (pData) delete pData; - m_programs.removeItem(program); + m_programs.removeItem(program); } void GLSharedGroup::attachShader(GLuint program, GLuint shader) @@ -363,7 +385,7 @@ GLenum GLSharedGroup::getProgramUniformType(GLuint program, GLint location) android::AutoMutex _lock(m_lock); ProgramData* pData = m_programs.valueFor(program); GLenum type=0; - if (pData) + if (pData) { type = pData->getTypeForLocation(location); } |
