Valkka  1.6.1
OpenSource Video Management
shader.h
1 #ifndef SHADERS_HEADER_GUARD
2 #define SHADERS_HEADER_GUARD
3 /*
4  * shaders.h : OpenGL shaders for YUV to RGB interpolation
5  *
6  * (c) Copyright 2017-2024 Sampsa Riikonen
7  *
8  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi> and Markus Kaukonen <markus.kaukonen@iki.fi>
9  *
10  * This file is part of the Valkka library.
11  *
12  * Valkka is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>
24  *
25  */
26 
38 // #include<GL/glew.h>
39 // #include<GL/glx.h>
40 #include "common.h"
41 #include "macro.h"
42 
52 class Shader {
53 
54 public:
57  Shader();
58  virtual ~Shader();
59  ban_copy_ctor(Shader);
60  ban_copy_asm(Shader);
61 
62 protected: // functions that return shader programs
63  virtual const char* vertex_shader() =0;
64  virtual const char* fragment_shader() =0;
65  const char* vertex_shader_obj();
66  const char* fragment_shader_obj();
67 
68 
69 public: // declare GLint variable references here with "* SHADER PROGRAM VAR"
70  GLint transform;
71  GLint transform_obj;
72  GLint position;
73  GLint texcoord;
74  GLint object;
75 
76 protected:
77  GLuint program;
78  GLuint program_obj;
79 
80 public:
81  void compile();
82  void virtual findVars();
83  void scale(GLfloat fx, GLfloat fy);
84  void use();
85  void use_obj();
86  void validate();
87 
88 };
89 
90 
91 
92 class RGBShader : public Shader {
93 
94 public:
95  RGBShader();
96  ~RGBShader();
97  ban_copy_ctor(RGBShader);
98  ban_copy_asm(RGBShader);
99 
100 protected: // functions that return shader programs
101  const char* vertex_shader();
102  const char* fragment_shader();
103 
104 };
105 
106 
107 
108 class YUVShader : public Shader {
109 
110 public:
111  YUVShader();
112  ~YUVShader();
113  ban_copy_ctor(YUVShader);
114  ban_copy_asm(YUVShader);
115 
116 public: // declare GLint variable references here with "* SHADER PROGRAM VAR"
117  GLint texy;
118  GLint texu;
119  GLint texv;
120 
121 protected: // functions that return shader programs
122  const char* vertex_shader();
123  const char* fragment_shader();
124 
125 public:
126  void findVars();
127 
128 };
129 
130 
131 
132 #endif
Definition: shader.h:92
A general purpose shader class.
Definition: shader.h:52
GLuint program_obj
OpenGL reference to vertex & fragment shader program for rendering overlay objects.
Definition: shader.h:78
Shader()
Default constructor.
Definition: shader.cpp:184
GLint texcoord
OpenGL VERTEX SHADER PROGRAM VAR : texture coordinate array. Typically "hard-coded" into the shader c...
Definition: shader.h:73
GLint position
OpenGL VERTEX SHADER PROGRAM VAR : position vertex array. Typically "hard-coded" into the shader code...
Definition: shader.h:72
void scale(GLfloat fx, GLfloat fy)
Set transformation matrix to simple scaling.
Definition: shader.cpp:316
void compile()
Compile shader.
Definition: shader.cpp:200
void validate()
Validate shader program.
Definition: shader.cpp:346
virtual void findVars()
Link shader program variable references to the shader program.
Definition: shader.cpp:302
void use()
Use shader program for bitmap rendering.
Definition: shader.cpp:330
void use_obj()
Use shader program for overlay object drawing.
Definition: shader.cpp:338
GLint transform_obj
OpenGL VERTEX SHADER PROGRAM VAR : transformation matrix. For the object overlay shader program.
Definition: shader.h:71
GLuint program
OpenGL reference to vertex & fragment shader program for rendering bitmap.
Definition: shader.h:77
GLint transform
OpenGL VERTEX SHADER PROGRAM VAR : transformation matrix.
Definition: shader.h:70
virtual ~Shader()
Default destructor.
Definition: shader.cpp:192
Definition: shader.h:108
GLint texy
OpenGL VERTEX SHADER PROGRAM VAR : Y texture.
Definition: shader.h:117
void findVars()
Link shader program variable references to the shader program.
Definition: shader.cpp:398
GLint texu
OpenGL VERTEX SHADER PROGRAM VAR : U texture.
Definition: shader.h:118
GLint texv
OpenGL VERTEX SHADER PROGRAM VAR : V texture.
Definition: shader.h:119
List of common header files.