~hikiko/nux/arb-srgba-shader

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
/*
 * Copyright 2010 Inalogic® Inc.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License, as
 * published by the  Free Software Foundation; either version 2.1 or 3.0
 * of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License along with this program. If not, see <http://www.gnu.org/licenses/>
 *
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 *
 */


#ifndef TEMPLATEPRIMITIVEBUFFER_H
#define TEMPLATEPRIMITIVEBUFFER_H

namespace nux
{

  class IOpenGLVertexBuffer;
  class IOpenGLIndexBuffer;
  class GpuDevice;

  typedef struct
  {
    Vector4 v0;
    Vector4 v1;
    Vector4 v2;
    Vector4 v3;
  } QuadAttributeParam;

  class TemplateQuadBuffer
  {
  public:
    TemplateQuadBuffer(GpuDevice *, ShaderType Type = SHADER_TYPE_GLSL, int NumQuads = 256);
    ~TemplateQuadBuffer();
    //! Bind GLSL parameter
    void BindAttribute(INT AttributeLocation, UINT AttributeIndex);
    //! Bind NVidia CG parameter

#if (NUX_ENABLE_CG_SHADERS)
    void BindCGAttribute(CGparameter AttributeLocation, UINT AttributeIndex);
    void UnBindCGAttribute(CGparameter AttributeLocation);
#endif
    void UnBindAttribute(INT AttributeLocation);
    void UnBind();
    void Render(INT NumPrimitives);
    //! Set the Vertices's attribute on a per quad basis.
    /*!
        Set the Vertices's attribute on a per quad basis.
        All vertex of the quad will have the same value for the attribute index.
    */
    void SetPerQuadAttribute(UINT AttributeIndex, INT Num, Vector4 *);

    //! Set the Vertices's attribute on a per vertex basis.
    /*!
        Set the vertex attribute on a per vertex basis.
    */
    void SetPerVertexAttribute(UINT AttributeIndex, INT Num, Vector4 *pVector);
    void UnSetQuadAttribute(UINT AttributeIndex);

    void SetNumQuads(int NumQuads);
    int GetNumQuads() const;

  protected:
    //IOpenGLVertexBuffer* m_VB;
    ObjectPtr<IOpenGLIndexBuffer> m_IB;
    void FormatQuads();

  private:

    ShaderType m_ShaderType;
    ObjectPtr<IOpenGLVertexBuffer> VertexAttributeBuffer[16];
    GpuDevice *m_pDeviceFactory;
    INT m_NumVertex;
    INT m_NumQuad;
  };

}

#endif //TEMPLATEPRIMITIVEBUFFER_H