aboutsummaryrefslogtreecommitdiff
path: root/modules/gles/gl_command.h
blob: 8906eeea8c3107d7bade0e7796d50e9603363598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * gl_command.h - GL command class
 *
 *  Copyright (c) 2018 Intel Corporation
 *
 * 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.
 *
 * Author: Yinhang Liu <yinhangx.liu@intel.com>
 */

#ifndef XCAM_GL_COMMAND_H
#define XCAM_GL_COMMAND_H

#include <list>
#include <gles/gles_std.h>

namespace XCam {

namespace UniformOps {

template <typename TType>
GLenum uniform (GLint location, TType value);

template <typename TType>
GLenum uniform_array (GLint location, const TType *value, GLsizei count);

template <typename TType, uint32_t TDim>
GLenum uniform_vect (GLint location, const TType *value, GLsizei count = 1);

template <typename TType, uint32_t TDim>
GLenum uniform_mat (GLint location, const TType *value, GLsizei count = 1);
}

class GLCommand
{
public:
    virtual ~GLCommand () {}
    virtual XCamReturn run (GLuint program) = 0;

protected:
    explicit GLCommand () {}

private:
    XCAM_DEAD_COPY (GLCommand);
};
typedef std::list<SmartPtr<GLCommand> > GLCmdList;

class GLCmdUniform
    : public GLCommand
{
public:
    virtual ~GLCmdUniform ();
    virtual XCamReturn run (GLuint program);

protected:
    explicit GLCmdUniform (const GLchar *name);

private:
    GLint get_uniform_location (GLuint program, const GLchar *name);
    virtual GLenum uniform (GLint location) = 0;

protected:
    GLchar        _name[XCAM_GL_NAME_LENGTH];
};

/* uniform single variable */
template <typename TType>
class GLCmdUniformT
    : public GLCmdUniform
{
public:
    GLCmdUniformT (const GLchar *name, TType value)
        : GLCmdUniform (name)
        , _value (value)
    {}
    ~GLCmdUniformT () {}

private:
    virtual GLenum uniform (GLint location) {
        return UniformOps::uniform <TType> (location, _value);
    }

private:
    TType        _value;
};

/* uniform array: TType array[TCount] */
template <typename TType, int TCount>
class GLCmdUniformTArray
    : public GLCmdUniform
{
public:
    GLCmdUniformTArray (const GLchar *name, const TType *value)
        : GLCmdUniform (name)
    {
        XCAM_ASSERT (value);
        memcpy (&_value[0], value, sizeof (TType) * TCount);
    }
    ~GLCmdUniformTArray () {}

private:
    virtual GLenum uniform (GLint location) {
        return UniformOps::uniform_array <TType> (location, _value, TCount);
    }

private:
    TType        _value[TCount];
};

/* uniform vectors: TType vec{TDim}[TCount]*/
template <typename TType, int TDim, int TCount = 1>
class GLCmdUniformTVect
    : public GLCmdUniform
{
public:
    GLCmdUniformTVect (const GLchar *name, const TType *value)
        : GLCmdUniform (name)
    {
        XCAM_ASSERT (value);
        memcpy (&_value[0], value, sizeof (TType) * TDim * TCount);
    }
    ~GLCmdUniformTVect () {}

private:
    virtual GLenum uniform (GLint location) {
        return UniformOps::uniform_vect <TType, TDim> (location, _value, TCount);
    }

private:
    TType        _value[TDim * TCount];
};

/* uniform matrix: TType mat{TColumns}x{TRows}[TCount], only support square matrix */
template <typename TType, int TColumns, int TRows, int TCount = 1>
class GLCmdUniformTMat
    : public GLCmdUniform
{
public:
    GLCmdUniformTMat (const GLchar *name, const TType *value)
        : GLCmdUniform (name)
    {
        XCAM_ASSERT (value);
        memcpy (&_value[0], value, sizeof (TType) * TColumns * TRows * TCount);
    }
    ~GLCmdUniformTMat () {}

private:
    virtual GLenum uniform (GLint location) {
        XCAM_FAIL_RETURN (
            ERROR, TColumns == TRows, -1,
            "uniform_mat only support square matrix, invalid dimension:%dx%d", TColumns, TRows);

        return UniformOps::uniform_mat <TType, TColumns> (location, _value, TCount);
    }

private:
    TType        _value[TColumns * TRows * TCount];
};

class GLBuffer;

class GLCmdBindBufBase
    : public GLCommand
{
public:
    GLCmdBindBufBase (const SmartPtr<GLBuffer> &buf, uint32_t index);
    virtual ~GLCmdBindBufBase ();

    virtual XCamReturn run (GLuint program);

private:
    SmartPtr<GLBuffer>        _buf;
    uint32_t                  _index;
};

class GLCmdBindBufRange
    : public GLCommand
{
public:
    GLCmdBindBufRange (const SmartPtr<GLBuffer> &buf, uint32_t index, uint32_t offset_x = 0);
    GLCmdBindBufRange (
        const SmartPtr<GLBuffer> &buf, uint32_t index, NV12PlaneIdx plane, uint32_t offset_in_plane = 0);
    virtual ~GLCmdBindBufRange ();

    virtual XCamReturn run (GLuint program);

private:
    SmartPtr<GLBuffer>        _buf;
    uint32_t                  _index;
    uint32_t                  _offset;
    uint32_t                  _size;
};

}

#endif // XCAM_GL_COMMAND_H