2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef _GL_SHARED_GROUP_H_
17 #define _GL_SHARED_GROUP_H_
26 #include <GLES/glext.h>
27 #include <GLES2/gl2.h>
28 #include <GLES2/gl2ext.h>
33 #include <utils/KeyedVector.h>
34 #include <utils/List.h>
35 #include <utils/String8.h>
36 #include <utils/threads.h>
37 #include "FixedBuffer.h"
42 BufferData(GLsizeiptr size, void * data);
44 FixedBuffer m_fixedBuffer;
49 typedef struct _IndexInfo {
54 GLint hostLocsPerElement;
56 GLint samplerValue; // only set for sampler uniforms
64 android::Vector<GLuint> m_shaders;
68 INDEX_FLAG_SAMPLER_EXTERNAL = 0x00000001,
72 void initProgramData(GLuint numIndexes);
74 virtual ~ProgramData();
75 void setIndexInfo(GLuint index, GLint base, GLint size, GLenum type);
76 void setIndexFlags(GLuint index, GLuint flags);
77 GLuint getIndexForLocation(GLint location);
78 GLenum getTypeForLocation(GLint location);
80 bool needUniformLocationWAR() const { return m_locShiftWAR; }
81 void setupLocationShiftWAR();
82 GLint locationWARHostToApp(GLint hostLoc, GLint arrIndex);
83 GLint locationWARAppToHost(GLint appLoc);
85 GLint getNextSamplerUniform(GLint index, GLint* val, GLenum* target);
86 bool setSamplerUniform(GLint appLoc, GLint val, GLenum* target);
88 bool attachShader(GLuint shader);
89 bool detachShader(GLuint shader);
90 size_t getNumShaders() const { return m_shaders.size(); }
91 GLuint getShader(size_t i) const { return m_shaders[i]; }
95 typedef android::List<android::String8> StringList;
96 StringList samplerExternalNames;
100 class GLSharedGroup {
102 android::DefaultKeyedVector<GLuint, BufferData*> m_buffers;
103 android::DefaultKeyedVector<GLuint, ProgramData*> m_programs;
104 android::DefaultKeyedVector<GLuint, ShaderData*> m_shaders;
105 mutable android::Mutex m_lock;
107 void refShaderDataLocked(ssize_t shaderIdx);
108 void unrefShaderDataLocked(ssize_t shaderIdx);
113 bool isObject(GLuint obj);
114 BufferData * getBufferData(GLuint bufferId);
115 void addBufferData(GLuint bufferId, GLsizeiptr size, void * data);
116 void updateBufferData(GLuint bufferId, GLsizeiptr size, void * data);
117 GLenum subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsizeiptr size, void * data);
118 void deleteBufferData(GLuint);
120 bool isProgram(GLuint program);
121 bool isProgramInitialized(GLuint program);
122 void addProgramData(GLuint program);
123 void initProgramData(GLuint program, GLuint numIndexes);
124 void attachShader(GLuint program, GLuint shader);
125 void detachShader(GLuint program, GLuint shader);
126 void deleteProgramData(GLuint program);
127 void setProgramIndexInfo(GLuint program, GLuint index, GLint base, GLint size, GLenum type, const char* name);
128 GLenum getProgramUniformType(GLuint program, GLint location);
129 void setupLocationShiftWAR(GLuint program);
130 GLint locationWARHostToApp(GLuint program, GLint hostLoc, GLint arrIndex);
131 GLint locationWARAppToHost(GLuint program, GLint appLoc);
132 bool needUniformLocationWAR(GLuint program);
133 GLint getNextSamplerUniform(GLuint program, GLint index, GLint* val, GLenum* target) const;
134 bool setSamplerUniform(GLuint program, GLint appLoc, GLint val, GLenum* target);
136 bool addShaderData(GLuint shader);
137 // caller must hold a reference to the shader as long as it holds the pointer
138 ShaderData* getShaderData(GLuint shader);
139 void unrefShaderData(GLuint shader);
142 typedef SmartPtr<GLSharedGroup> GLSharedGroupPtr;
144 #endif //_GL_SHARED_GROUP_H_