GteVertexColorEffect.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 VertexColorEffect::VertexColorEffect(std::shared_ptr<ProgramFactory> const& factory)
13  :
14  mPVWMatrix(nullptr)
15 {
16  int i = factory->GetAPI();
17  mProgram = factory->CreateFromSources(*msVSSource[i], *msPSSource[i], "");
18  if (mProgram)
19  {
20  mPVWMatrixConstant = std::make_shared<ConstantBuffer>(sizeof(Matrix4x4<float>), true);
23 
24  mProgram->GetVShader()->Set("PVWMatrix", mPVWMatrixConstant);
25  }
26 }
27 
28 void VertexColorEffect::SetPVWMatrixConstant(std::shared_ptr<ConstantBuffer> const& pvwMatrix)
29 {
30  mPVWMatrixConstant = pvwMatrix;
31  mProgram->GetVShader()->Set("PVWMatrix", mPVWMatrixConstant);
32 }
33 
34 
36 "uniform PVWMatrix\n"
37 "{\n"
38 " mat4 pvwMatrix;\n"
39 "};\n"
40 "\n"
41 "layout(location = 0) in vec3 modelPosition;\n"
42 "layout(location = 1) in vec4 modelColor;\n"
43 "layout(location = 0) out vec4 vertexColor;\n"
44 "\n"
45 "void main()\n"
46 "{\n"
47 " vertexColor = modelColor;\n"
48 "#if GTE_USE_MAT_VEC\n"
49 " gl_Position = pvwMatrix * vec4(modelPosition, 1.0f);\n"
50 "#else\n"
51 " gl_Position = vec4(modelPosition, 1.0f) * pvwMatrix;\n"
52 "#endif\n"
53 "}\n";
54 
56 "layout(location = 0) in vec4 vertexColor;\n"
57 "layout(location = 0) out vec4 pixelColor;\n"
58 "\n"
59 "void main()\n"
60 "{\n"
61 " pixelColor = vertexColor;\n"
62 "}\n";
63 
65 "cbuffer PVWMatrix\n"
66 "{\n"
67 " float4x4 pvwMatrix;\n"
68 "};\n"
69 "\n"
70 "struct VS_INPUT\n"
71 "{\n"
72 " float3 modelPosition : POSITION;\n"
73 " float4 modelColor : COLOR0;\n"
74 "};\n"
75 "\n"
76 "struct VS_OUTPUT\n"
77 "{\n"
78 " float4 vertexColor : COLOR0;\n"
79 " float4 clipPosition : SV_POSITION;\n"
80 "};\n"
81 "\n"
82 "VS_OUTPUT VSMain (VS_INPUT input)\n"
83 "{\n"
84 " VS_OUTPUT output;\n"
85 "#if GTE_USE_MAT_VEC\n"
86 " output.clipPosition = mul(pvwMatrix, float4(input.modelPosition, 1.0f));\n"
87 "#else\n"
88 " output.clipPosition = mul(float4(input.modelPosition, 1.0f), pvwMatrix);\n"
89 "#endif\n"
90 " output.vertexColor = input.modelColor;\n"
91 " return output;\n"
92 "}\n"
93 "\n"
94 "struct PS_INPUT\n"
95 "{\n"
96 " float4 vertexColor : COLOR0;\n"
97 "};\n"
98 "\n"
99 "struct PS_OUTPUT\n"
100 "{\n"
101 " float4 pixelColor0 : SV_TARGET0;\n"
102 "};\n"
103 "\n"
104 "PS_OUTPUT PSMain(PS_INPUT input)\n"
105 "{\n"
106 " PS_OUTPUT output;\n"
107 " output.pixelColor0 = input.vertexColor;\n"
108 " return output;\n"
109 "}\n";
110 
112 {
114  &msHLSLSource
115 };
116 
118 {
120  &msHLSLSource
121 };
std::shared_ptr< ConstantBuffer > mPVWMatrixConstant
static std::string const * msVSSource[ProgramFactory::PF_NUM_API]
static std::string const msHLSLSource
Matrix4x4< float > * mPVWMatrix
static std::string const msGLSLPSSource
static std::string const msGLSLVSSource
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
VertexColorEffect(std::shared_ptr< ProgramFactory > const &factory)
void SetPVWMatrixConstant(std::shared_ptr< ConstantBuffer > const &pvwMatrix)
static Matrix Identity()
Definition: GteMatrix.h:490
std::shared_ptr< VisualProgram > mProgram
static std::string const * msPSSource[ProgramFactory::PF_NUM_API]


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:02