13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _GLUSHADERPROGRAM_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _GLUSHADERPROGRAM_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES Utilities 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------ 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Shader and Program helpers. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderUtil.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "qpTestLog.h" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestLog; 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace glu 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass RenderContext; 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Shader information (compile status, log, etc.). 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ShaderInfo 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderType type; //!< Shader type. 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string source; //!< Shader source. 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string infoLog; //!< Compile info log. 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool compileOk; //!< Did compilation succeed? 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 compileTimeUs; //!< Compile time in microseconds (us). 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderInfo (void) : compileOk(false), compileTimeUs(0) {} 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Program information (link status, log). 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ProgramInfo 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string infoLog; //!< Link info log. 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool linkOk; //!< Did link succeed? 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 linkTimeUs; //!< Link time in microseconds (us). 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramInfo (void) : linkOk(false), linkTimeUs(0) {} 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 70d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulos * \brief Combined shader compilation and program linking info. 71d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulos *//*--------------------------------------------------------------------*/ 72d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulosstruct ShaderProgramInfo 73d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulos{ 74d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulos glu::ProgramInfo program; 75d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulos std::vector<glu::ShaderInfo> shaders; 76d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulos}; 77d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulos 78d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulos/*--------------------------------------------------------------------*//*! 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Shader object. 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Shader 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 8453365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi Shader (const glw::Functions& gl, ShaderType shaderType); 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Shader (const RenderContext& renderCtx, ShaderType shaderType); 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Shader (void); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setSources (int numSourceStrings, const char* const* sourceStrings, const int* lengths); 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void compile (void); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 getShader (void) const { return m_shader; } 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ShaderInfo& getInfo (void) const { return m_info; } 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderType getType (void) const { return getInfo().type; } 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool getCompileStatus (void) const { return getInfo().compileOk; } 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string& getSource (void) const { return getInfo().source; } 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string& getInfoLog (void) const { return getInfo().infoLog; } 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 operator* (void) const { return getShader(); } 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Shader (const Shader& other); 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Shader& operator= (const Shader& other); 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10553365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi const glw::Functions& m_gl; 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_shader; //!< Shader handle. 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderInfo m_info; //!< Client-side clone of state for debug / perf reasons. 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Program object. 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Program 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 11653365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi Program (const glw::Functions& gl); 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Program (const RenderContext& renderCtx); 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Program (const RenderContext& renderCtx, deUint32 program); 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Program (void); 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void attachShader (deUint32 shader); 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void detachShader (deUint32 shader); 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void bindAttribLocation (deUint32 location, const char* name); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void transformFeedbackVaryings (int count, const char* const* varyings, deUint32 bufferMode); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void link (void); 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 getProgram (void) const { return m_program; } 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ProgramInfo& getInfo (void) const { return m_info; } 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool getLinkStatus (void) const { return getInfo().linkOk; } 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string& getInfoLog (void) const { return getInfo().infoLog; } 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isSeparable (void) const; 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setSeparable (bool separable); 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getUniformLocation (const std::string& name); 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 operator* (void) const { return getProgram(); } 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Program (const Program& other); 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Program& operator= (const Program& other); 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 14653365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi const glw::Functions& m_gl; 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_program; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramInfo m_info; 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Program pipeline object. 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ProgramPipeline 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramPipeline (const RenderContext& renderCtx); 15953365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi ProgramPipeline (const glw::Functions& gl); 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ProgramPipeline (void); 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 getPipeline (void) const { return m_pipeline; } 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void useProgramStages (deUint32 stages, deUint32 program); 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void activeShaderProgram (deUint32 program); 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isValid (void); 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramPipeline (const ProgramPipeline& other); 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramPipeline& operator= (const ProgramPipeline& other); 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 17153365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi const glw::Functions& m_gl; 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_pipeline; 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ProgramSources; 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Shader program manager. 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ShaderProgram manages both Shader and Program objects, and provides 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * convenient API for constructing such programs. 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ShaderProgram 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 18653365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi ShaderProgram (const glw::Functions& gl, const ProgramSources& sources); 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderProgram (const RenderContext& renderCtx, const ProgramSources& sources); 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ShaderProgram (void); 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isOk (void) const { return m_program.getLinkStatus(); } 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 getProgram (void) const { return m_program.getProgram(); } 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool hasShader (glu::ShaderType shaderType) const { return !m_shaders[shaderType].empty(); } 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getNumShaders (glu::ShaderType shaderType) const { return (int)m_shaders[shaderType].size(); } 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ShaderInfo& getShaderInfo (glu::ShaderType shaderType, int shaderNdx = 0) const { return m_shaders[shaderType][shaderNdx]->getInfo(); } 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ProgramInfo& getProgramInfo (void) const { return m_program.getInfo(); } 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderProgram (const ShaderProgram& other); 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderProgram& operator= (const ShaderProgram& other); 20153365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi void init (const glw::Functions& gl, const ProgramSources& sources); 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Shader*> m_shaders[SHADERTYPE_LAST]; 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Program m_program; 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Utilities. 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2093c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint32 getGLShaderType (ShaderType shaderType); 2103c827367444ee418f129b2c238299f49d3264554Jarkko PoyrydeUint32 getGLShaderTypeBit (ShaderType shaderType); 2113c827367444ee418f129b2c238299f49d3264554Jarkko PoyryqpShaderType getLogShaderType (ShaderType shaderType); 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 213d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulostcu::TestLog& operator<< (tcu::TestLog& log, const ShaderInfo& shaderInfo); 214d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulostcu::TestLog& operator<< (tcu::TestLog& log, const ShaderProgramInfo& shaderProgramInfo); 215d5fdfc3ffc0a14e62100470e65ad56bc72c48ea8Pyry Haulostcu::TestLog& operator<< (tcu::TestLog& log, const ProgramSources& sources); 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestLog& operator<< (tcu::TestLog& log, const Shader& shader); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TestLog& operator<< (tcu::TestLog& log, const ShaderProgram& program); 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ProgramSources utilities and implementation. 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct AttribLocationBinding 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string name; 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 location; 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AttribLocationBinding (void) : location(0) {} 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AttribLocationBinding (const std::string& name_, deUint32 location_) : name(name_), location(location_) {} 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TransformFeedbackMode 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 mode; 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransformFeedbackMode (void) : mode(0) {} 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransformFeedbackMode (deUint32 mode_) : mode(mode_) {} 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TransformFeedbackVarying 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string name; 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry explicit TransformFeedbackVarying (const std::string& name_) : name(name_) {} 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ProgramSeparable 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool separable; 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry explicit ProgramSeparable (bool separable_) : separable(separable_) {} 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename Iterator> 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TransformFeedbackVaryings 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Iterator begin; 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Iterator end; 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TransformFeedbackVaryings (Iterator begin_, Iterator end_) : begin(begin_), end(end_) {} 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ShaderSource 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderType shaderType; 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string source; 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderSource (void) : shaderType(SHADERTYPE_LAST) {} 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderSource (glu::ShaderType shaderType_, const std::string& source_) : shaderType(shaderType_), source(source_) { DE_ASSERT(!source_.empty()); } 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct VertexSource : public ShaderSource 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VertexSource (const std::string& source_) : ShaderSource(glu::SHADERTYPE_VERTEX, source_) {} 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct FragmentSource : public ShaderSource 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FragmentSource (const std::string& source_) : ShaderSource(glu::SHADERTYPE_FRAGMENT, source_) {} 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct GeometrySource : public ShaderSource 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GeometrySource (const std::string& source_) : ShaderSource(glu::SHADERTYPE_GEOMETRY, source_) {} 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ComputeSource : public ShaderSource 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ComputeSource (const std::string& source_) : ShaderSource(glu::SHADERTYPE_COMPUTE, source_) {} 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TessellationControlSource : public ShaderSource 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TessellationControlSource (const std::string& source_) : ShaderSource(glu::SHADERTYPE_TESSELLATION_CONTROL, source_) {} 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TessellationEvaluationSource : public ShaderSource 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TessellationEvaluationSource (const std::string& source_) : ShaderSource(glu::SHADERTYPE_TESSELLATION_EVALUATION, source_) {} 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ProgramSources 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<std::string> sources[SHADERTYPE_LAST]; 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<AttribLocationBinding> attribLocationBindings; 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 transformFeedbackBufferMode; //!< TF buffer mode, or GL_NONE. 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<std::string> transformFeedbackVaryings; 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool separable; 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramSources (void) : transformFeedbackBufferMode(0), separable(false) {} 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramSources& operator<< (const AttribLocationBinding& binding) { attribLocationBindings.push_back(binding); return *this; } 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramSources& operator<< (const TransformFeedbackMode& mode) { transformFeedbackBufferMode = mode.mode; return *this; } 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramSources& operator<< (const TransformFeedbackVarying& varying) { transformFeedbackVaryings.push_back(varying.name); return *this; } 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramSources& operator<< (const ShaderSource& shaderSource) { sources[shaderSource.shaderType].push_back(shaderSource.source); return *this; } 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramSources& operator<< (const ProgramSeparable& progSeparable) { separable = progSeparable.separable; return *this; } 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry template<typename Iterator> 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramSources& operator<< (const TransformFeedbackVaryings<Iterator>& varyings); 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<typename Iterator> 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline ProgramSources& ProgramSources::operator<< (const TransformFeedbackVaryings<Iterator>& varyings) 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (Iterator cur = varyings.begin; cur != varyings.end; ++cur) 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry transformFeedbackVaryings.push_back(*cur); 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *this; 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Helper for constructing vertex-fragment source pair. 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline ProgramSources makeVtxFragSources (const std::string& vertexSrc, const std::string& fragmentSrc) 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ProgramSources sources; 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sources.sources[SHADERTYPE_VERTEX].push_back(vertexSrc); 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sources.sources[SHADERTYPE_FRAGMENT].push_back(fragmentSrc); 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return sources; 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // glu 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _GLUSHADERPROGRAM_HPP 340