| /* |
| * Copyright (C) 2016 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 <gapic/encoder.h> |
| #include <gapic/coder/gles.h> |
| #include "gles_spy.h" |
| |
| namespace gapii { |
| |
| // getProgramInfo returns a ProgramInfo, populated with the details of all the |
| // attributes and uniforms exposed by program. |
| std::shared_ptr<ProgramInfo> GlesSpy::getProgramInfo(int32_t program) { |
| using namespace gapic::coder::gles; |
| |
| // Allocate temporary buffer large enough to hold any of the returned strings. |
| int32_t infoLogLength = 0; |
| mImports.glGetProgramiv(program, GLenum::GL_INFO_LOG_LENGTH, &infoLogLength); |
| int32_t activeAttributeMaxLength = 0; |
| mImports.glGetProgramiv(program, GLenum::GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttributeMaxLength); |
| int32_t activeUniformMaxLength = 0; |
| mImports.glGetProgramiv(program, GLenum::GL_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformMaxLength); |
| const int strSize = std::max(infoLogLength, std::max(activeAttributeMaxLength, activeUniformMaxLength)); |
| char* str = mScratch.create<char>(strSize); |
| int32_t strLen = 0; |
| |
| auto pi = std::shared_ptr<ProgramInfo>(new ProgramInfo()); |
| |
| int32_t linkStatus = 0; |
| mImports.glGetProgramiv(program, GLenum::GL_LINK_STATUS, &linkStatus); |
| pi->mLinkStatus = linkStatus; |
| |
| mImports.glGetProgramInfoLog(program, strSize, &strLen, str); |
| pi->mInfoLog = std::string(str, strLen); |
| |
| int32_t activeUniforms = 0; |
| mImports.glGetProgramiv(program, GLenum::GL_ACTIVE_UNIFORMS, &activeUniforms); |
| for (int32_t i = 0; i < activeUniforms; i++) { |
| ActiveUniform au; |
| mImports.glGetActiveUniform(program, i, strSize, &strLen, &au.mArraySize, &au.mType, str); |
| au.mName = std::string(str, strLen); |
| au.mLocation = mImports.glGetUniformLocation(program, str); |
| pi->mActiveUniforms[i] = au; |
| } |
| |
| int32_t activeAttributes = 0; |
| mImports.glGetProgramiv(program, GLenum::GL_ACTIVE_ATTRIBUTES, &activeAttributes); |
| for (int32_t i = 0; i < activeAttributes; i++) { |
| ActiveAttribute aa; |
| mImports.glGetActiveAttrib(program, i, strSize, &strLen, &aa.mArraySize, &aa.mType, str); |
| aa.mName = std::string(str, strLen); |
| aa.mLocation = mImports.glGetAttribLocation(program, str); |
| pi->mActiveAttributes[i] = aa; |
| } |
| |
| GAPID_DEBUG("Created ProgramInfo: LinkStatus=%i ActiveUniforms=%i ActiveAttributes=%i", |
| linkStatus, activeUniforms, activeAttributes); |
| |
| return pi; |
| } |
| |
| void GlesSpy::addGlLinkProgramExtra(gapic::coder::gles::GlLinkProgram& atom) { |
| auto pi = getProgramInfo(atom.mProgram); |
| atom.mextras.append(mScratch.make<ProgramInfo::CoderType>(pi->encodeable(mScratch))); |
| try { |
| subSetProgramInfo([]{}, atom.mProgram, pi); |
| } catch (gapii::AbortException& e) { |
| GAPID_DEBUG("Aborted subSetProgramInfo"); |
| } |
| } |
| |
| void GlesSpy::addGlProgramBinaryExtra(gapic::coder::gles::GlProgramBinary& atom) { |
| auto pi = getProgramInfo(atom.mProgram); |
| atom.mextras.append(mScratch.make<ProgramInfo::CoderType>(pi->encodeable(mScratch))); |
| try { |
| subSetProgramInfo([]{}, atom.mProgram, pi); |
| } catch (gapii::AbortException& e) { |
| GAPID_DEBUG("Aborted subSetProgramInfo"); |
| } |
| } |
| |
| } |