GteConstantColorEffect.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.1 (2016/11/13)
7 
8 #include <GTEnginePCH.h>
10 using namespace gte;
11 
12 ConstantColorEffect::ConstantColorEffect(std::shared_ptr<ProgramFactory> const& factory,
13  Vector4<float> const& color)
14  :
15  mPVWMatrix(nullptr),
16  mColor(nullptr)
17 {
18  int i = factory->GetAPI();
19  mProgram = factory->CreateFromSources(*msVSSource[i], *msPSSource[i], "");
20  if (mProgram)
21  {
22  mPVWMatrixConstant = std::make_shared<ConstantBuffer>(sizeof(Matrix4x4<float>), true);
25 
26  mColorConstant = std::make_shared<ConstantBuffer>(sizeof(Vector4<float>), true);
28  *mColor = color;
29 
30  mProgram->GetVShader()->Set("PVWMatrix", mPVWMatrixConstant);
31  mProgram->GetVShader()->Set("ConstantColor", mColorConstant);
32  }
33 }
34 
35 void ConstantColorEffect::SetPVWMatrixConstant(std::shared_ptr<ConstantBuffer> const& pvwMatrix)
36 {
37  mPVWMatrixConstant = pvwMatrix;
38  mProgram->GetVShader()->Set("PVWMatrix", mPVWMatrixConstant);
39 }
40 
41 
43 "uniform PVWMatrix\n"
44 "{\n"
45 " mat4 pvwMatrix;\n"
46 "};\n"
47 "\n"
48 "uniform ConstantColor\n"
49 "{\n"
50 " vec4 constantColor;\n"
51 "};\n"
52 "\n"
53 "layout(location = 0) in vec3 modelPosition;\n"
54 "\n"
55 "layout(location = 0) out vec4 vertexColor;\n"
56 "\n"
57 "void main()\n"
58 "{\n"
59 "#if GTE_USE_MAT_VEC\n"
60 " gl_Position = pvwMatrix * vec4(modelPosition, 1.0f);\n"
61 "#else\n"
62 " gl_Position = vec4(modelPosition, 1.0f) * pvwMatrix;\n"
63 "#endif\n"
64 " vertexColor = constantColor;\n"
65 "}\n";
66 
68 "layout(location = 0) in vec4 vertexColor;\n"
69 "\n"
70 "layout(location = 0) out vec4 pixelColor0;\n"
71 "\n"
72 "void main()\n"
73 "{\n"
74 " pixelColor0 = vertexColor;\n"
75 "}\n";
76 
78 "cbuffer PVWMatrix\n"
79 "{\n"
80 " float4x4 pvwMatrix;\n"
81 "};\n"
82 "\n"
83 "cbuffer ConstantColor\n"
84 "{\n"
85 " float4 constantColor;\n"
86 "};\n"
87 "\n"
88 "struct VS_INPUT\n"
89 "{\n"
90 " float3 modelPosition : POSITION;\n"
91 "};\n"
92 "\n"
93 "struct VS_OUTPUT\n"
94 "{\n"
95 " float4 vertexColor : COLOR0;\n"
96 " float4 clipPosition : SV_POSITION;\n"
97 "};\n"
98 "\n"
99 "VS_OUTPUT VSMain(VS_INPUT input)\n"
100 "{\n"
101 " VS_OUTPUT output;\n"
102 "#if GTE_USE_MAT_VEC\n"
103 " output.clipPosition = mul(pvwMatrix, float4(input.modelPosition, 1.0f));\n"
104 "#else\n"
105 " output.clipPosition = mul(float4(input.modelPosition, 1.0f), pvwMatrix);\n"
106 "#endif\n"
107 " output.vertexColor = constantColor;\n"
108 " return output;\n"
109 "}\n"
110 "\n"
111 "struct PS_INPUT\n"
112 "{\n"
113 " float4 vertexColor : COLOR0;\n"
114 "};\n"
115 "\n"
116 "struct PS_OUTPUT\n"
117 "{\n"
118 " float4 pixelColor0 : SV_TARGET0;\n"
119 "};\n"
120 "\n"
121 "PS_OUTPUT PSMain(PS_INPUT input)\n"
122 "{\n"
123 " PS_OUTPUT output;\n"
124 " output.pixelColor0 = input.vertexColor;\n"
125 " return output;\n"
126 "}\n";
127 
129 {
131  &msHLSLSource
132 };
133 
135 {
137  &msHLSLSource
138 };
GLuint color
Definition: glcorearb.h:1256
static std::string const msGLSLVSSource
std::shared_ptr< ConstantBuffer > mPVWMatrixConstant
Matrix4x4< float > * mPVWMatrix
void SetPVWMatrixConstant(std::shared_ptr< ConstantBuffer > const &pvwMatrix)
static std::string const * msVSSource[ProgramFactory::PF_NUM_API]
std::shared_ptr< ConstantBuffer > mColorConstant
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
ConstantColorEffect(std::shared_ptr< ProgramFactory > const &factory, Vector4< float > const &color)
static std::string const msGLSLPSSource
static std::string const * msPSSource[ProgramFactory::PF_NUM_API]
static Matrix Identity()
Definition: GteMatrix.h:490
std::shared_ptr< VisualProgram > mProgram
static std::string const msHLSLSource


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59