1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef _GL_SHARED_GROUP_H_ 17 #define _GL_SHARED_GROUP_H_ 18 19 #define GL_API 20 #ifndef ANDROID 21 #define GL_APIENTRY 22 #define GL_APIENTRYP 23 #endif 24 25 #include <GLES/gl.h> 26 #include <GLES/glext.h> 27 #include <GLES2/gl2.h> 28 #include <GLES2/gl2ext.h> 29 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include "ErrorLog.h" 33 #include <utils/KeyedVector.h> 34 #include <utils/threads.h> 35 #include <utils/List.h> 36 #include "FixedBuffer.h" 37 #include "SmartPtr.h" 38 39 struct BufferData { 40 BufferData(); 41 BufferData(GLsizeiptr size, void * data); 42 GLsizeiptr m_size; 43 FixedBuffer m_fixedBuffer; 44 }; 45 46 class ProgramData { 47 private: 48 typedef struct _IndexInfo { 49 GLint base; 50 GLint size; 51 GLenum type; 52 GLint appBase; 53 GLint hostLocsPerElement; 54 } IndexInfo; 55 56 GLuint m_numIndexes; 57 IndexInfo* m_Indexes; 58 bool m_initialized; 59 bool m_locShiftWAR; 60 public: 61 ProgramData(); 62 void initProgramData(GLuint numIndexes); 63 bool isInitialized(); 64 virtual ~ProgramData(); 65 void setIndexInfo(GLuint index, GLint base, GLint size, GLenum type); 66 GLuint getIndexForLocation(GLint location); 67 GLenum getTypeForLocation(GLint location); 68 69 bool needUniformLocationWAR() const { return m_locShiftWAR; } 70 void setupLocationShiftWAR(); 71 GLint locationWARHostToApp(GLint hostLoc, GLint arrIndex); 72 GLint locationWARAppToHost(GLint appLoc); 73 74 }; 75 76 class GLSharedGroup { 77 private: 78 android::DefaultKeyedVector<GLuint, BufferData*> m_buffers; 79 android::DefaultKeyedVector<GLuint, ProgramData*> m_programs; 80 android::List<GLuint> m_shaders; 81 mutable android::Mutex m_lock; 82 public: 83 GLSharedGroup(); 84 ~GLSharedGroup(); 85 BufferData * getBufferData(GLuint bufferId); 86 void addBufferData(GLuint bufferId, GLsizeiptr size, void * data); 87 void updateBufferData(GLuint bufferId, GLsizeiptr size, void * data); 88 GLenum subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsizeiptr size, void * data); 89 void deleteBufferData(GLuint); 90 91 bool isProgram(GLuint program); 92 bool isProgramInitialized(GLuint program); 93 void addProgramData(GLuint program); 94 void initProgramData(GLuint program, GLuint numIndexes); 95 void deleteProgramData(GLuint program); 96 void setProgramIndexInfo(GLuint program, GLuint index, GLint base, GLint size, GLenum type); 97 GLenum getProgramUniformType(GLuint program, GLint location); 98 void setupLocationShiftWAR(GLuint program); 99 GLint locationWARHostToApp(GLuint program, GLint hostLoc, GLint arrIndex); 100 GLint locationWARAppToHost(GLuint program, GLint appLoc); 101 bool needUniformLocationWAR(GLuint program); 102 103 void addShaderData(GLuint shader); 104 bool isShader(GLuint shader); 105 void deleteShaderData(GLuint shader); 106 107 }; 108 109 typedef SmartPtr<GLSharedGroup> GLSharedGroupPtr; 110 111 #endif //_GL_SHARED_GROUP_H_ 112