13f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian/* 23f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * Copyright 2013 The Android Open Source Project 33f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * 43f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 53f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * you may not use this file except in compliance with the License. 63f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * You may obtain a copy of the License at 73f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * 83f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 93f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * 103f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * Unless required by applicable law or agreed to in writing, software 113f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 123f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * See the License for the specific language governing permissions and 143f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * limitations under the License. 153f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian */ 163f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 173f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#ifndef SF_RENDER_ENGINE_PROGRAM_H 183f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#define SF_RENDER_ENGINE_PROGRAM_H 193f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 203f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <stdint.h> 213f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 223f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <GLES2/gl2.h> 233f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 243f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "Description.h" 253f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include "ProgramCache.h" 263f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 273f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopiannamespace android { 283f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 293f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass String8; 303f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 313f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian/* 323f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian * Abstracts a GLSL program comprising a vertex and fragment shader 333f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian */ 343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Program { 353f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianpublic: 363f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // known locations for position and texture coordinates 373f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian enum { position=0, texCoords=1 }; 383f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 393f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian Program(const ProgramCache::Key& needs, const char* vertex, const char* fragment); 403f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian ~Program(); 413f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 423f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* whether this object is usable */ 433f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian bool isValid() const; 443f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 453f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* Binds this program to the GLES context */ 463f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void use(); 473f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 483f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* Returns the location of the specified attribute */ 493f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLuint getAttrib(const char* name) const; 503f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 513f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* Returns the location of the specified uniform */ 523f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLint getUniform(const char* name) const; 533f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 543f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* set-up uniforms from the description */ 553f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void setUniforms(const Description& desc); 563f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 573f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 583f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianprivate: 593f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLuint buildShader(const char* source, GLenum type); 603f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian String8& dumpShader(String8& result, GLenum type); 613f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 623f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // whether the initialization succeeded 633f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian bool mInitialized; 643f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 653f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // Name of the OpenGL program and shaders 663f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLuint mProgram; 673f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLuint mVertexShader; 683f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLuint mFragmentShader; 693f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 703f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* location of the projection matrix uniform */ 713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLint mProjectionMatrixLoc; 723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 73ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian /* location of the color matrix uniform */ 74ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian GLint mColorMatrixLoc; 75ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian 763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* location of the texture matrix uniform */ 773f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLint mTextureMatrixLoc; 783f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* location of the sampler uniform */ 803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLint mSamplerLoc; 813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 823f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* location of the alpha plane uniform */ 833f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLint mAlphaPlaneLoc; 843f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 853f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian /* location of the color uniform */ 863f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian GLint mColorLoc; 873f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian}; 883f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 893f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 903f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian} /* namespace android */ 913f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 923f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#endif /* SF_RENDER_ENGINE_PROGRAM_H */ 93