1 /*
2  * Copyright (C) 2016 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 
17 #ifndef SHADERTOY_SHADER_H
18 #define SHADERTOY_SHADER_H
19 
20 #include <GLES3/gl31.h>
21 
22 #include <fstream>
23 #include <sstream>
24 
25 struct InputTextures {
26   GLuint id;
27   GLint uniform_location;
28   int width;
29   int height;
30 };
31 
32 class ShadertoyShader {
33  public:
34   ShadertoyShader();
35   ~ShadertoyShader();
36 
37   void CreateShaderFromString(const std::string& shader_string);
38   void PrepareForDraw(int width, int height, float global_time, int frame, float time_delta);
39 
40  private:
41    void CreateShader(const std::string fragment_string);
42    void GetUniformLocations();
43 
44    GLint uiResolution_;
45    GLint uiGlobalTime_;
46    GLint uiFrame_;
47    GLint uiTimeDelta_;
48    GLint uiChannel0_;
49    GLint unViewport_;
50    GLint unCorners_;
51 
52    GLuint shader_program_;
53 
54    struct InputTextures input_textures_[4];
55 };
56 
57 
58 
59 #endif // SHADERTOY_SHADER_H
60