GteTexture2Effect.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 Texture2Effect::Texture2Effect(std::shared_ptr<ProgramFactory> const& factory,
13  std::shared_ptr<Texture2> const& texture, SamplerState::Filter filter,
14  SamplerState::Mode mode0, SamplerState::Mode mode1)
15  :
16  mTexture(texture),
17  mPVWMatrix(nullptr)
18 {
19  int api = factory->GetAPI();
20  mProgram = factory->CreateFromSources(*msVSSource[api], *msPSSource[api], "");
21  if (mProgram)
22  {
23  mPVWMatrixConstant = std::make_shared<ConstantBuffer>(sizeof(Matrix4x4<float>), true);
26 
27  mSampler = std::make_shared<SamplerState>();
28  mSampler->filter = filter;
29  mSampler->mode[0] = mode0;
30  mSampler->mode[1] = mode1;
31 
32  mProgram->GetVShader()->Set("PVWMatrix", mPVWMatrixConstant);
33 #if defined(GTE_DEV_OPENGL)
34  mProgram->GetPShader()->Set("baseSampler", texture);
35 #else
36  mProgram->GetPShader()->Set("baseTexture", texture);
37 #endif
38  mProgram->GetPShader()->Set("baseSampler", mSampler);
39  }
40 }
41 
42 void Texture2Effect::SetPVWMatrixConstant(std::shared_ptr<ConstantBuffer> const& pvwMatrix)
43 {
44  mPVWMatrixConstant = pvwMatrix;
45  mProgram->GetVShader()->Set("PVWMatrix", mPVWMatrixConstant);
46 }
47 
48 
50 "uniform PVWMatrix\n"
51 "{\n"
52 " mat4 pvwMatrix;\n"
53 "};\n"
54 "\n"
55 "layout(location = 0) in vec3 modelPosition;\n"
56 "layout(location = 1) in vec2 modelTCoord;\n"
57 "layout(location = 0) out vec2 vertexTCoord;\n"
58 "\n"
59 "void main()\n"
60 "{\n"
61 " vertexTCoord = modelTCoord;\n"
62 "#if GTE_USE_MAT_VEC\n"
63 " gl_Position = pvwMatrix * vec4(modelPosition, 1.0f);\n"
64 "#else\n"
65 " gl_Position = vec4(modelPosition, 1.0f) * pvwMatrix;\n"
66 "#endif\n"
67 "}\n";
68 
69 
71 "uniform sampler2D baseSampler;\n"
72 "\n"
73 "layout(location = 0) in vec2 vertexTCoord;\n"
74 "layout(location = 0) out vec4 pixelColor;\n"
75 "\n"
76 "void main()\n"
77 "{\n"
78 " pixelColor = texture(baseSampler, vertexTCoord);\n"
79 "}\n";
80 
81 
83 "cbuffer PVWMatrix\n"
84 "{\n"
85 " float4x4 pvwMatrix;\n"
86 "};\n"
87 "\n"
88 "struct VS_INPUT\n"
89 "{\n"
90 " float3 modelPosition : POSITION;\n"
91 " float2 modelTCoord : TEXCOORD0;\n"
92 "};\n"
93 "\n"
94 "struct VS_OUTPUT\n"
95 "{\n"
96 " float2 vertexTCoord : TEXCOORD0;\n"
97 " float4 clipPosition : SV_POSITION;\n"
98 "};\n"
99 "\n"
100 "VS_OUTPUT VSMain(VS_INPUT input)\n"
101 "{\n"
102 " VS_OUTPUT output;\n"
103 "#if GTE_USE_MAT_VEC\n"
104 " output.clipPosition = mul(pvwMatrix, float4(input.modelPosition, 1.0f));\n"
105 "#else\n"
106 " output.clipPosition = mul(float4(input.modelPosition, 1.0f), pvwMatrix);\n"
107 "#endif\n"
108 " output.vertexTCoord = input.modelTCoord;\n"
109 " return output;\n"
110 "}\n"
111 "\n"
112 "Texture2D baseTexture;\n"
113 "SamplerState baseSampler;\n"
114 "\n"
115 "struct PS_INPUT\n"
116 "{\n"
117 " float2 vertexTCoord : TEXCOORD0;\n"
118 "};\n"
119 "\n"
120 "struct PS_OUTPUT\n"
121 "{\n"
122 " float4 pixelColor0 : SV_TARGET0;\n"
123 "};\n"
124 "\n"
125 "PS_OUTPUT PSMain(PS_INPUT input)\n"
126 "{\n"
127 " PS_OUTPUT output;\n"
128 " output.pixelColor0 = baseTexture.Sample(baseSampler, input.vertexTCoord);\n"
129 " return output;\n"
130 "}\n";
131 
133 {
135  &msHLSLSource
136 };
137 
139 {
141  &msHLSLSource
142 };
static std::string const * msPSSource[ProgramFactory::PF_NUM_API]
static std::string const msGLSLVSSource
static std::string const * msVSSource[ProgramFactory::PF_NUM_API]
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
GLuint texture
Definition: glcorearb.h:410
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1292
Matrix4x4< float > * mPVWMatrix
void SetPVWMatrixConstant(std::shared_ptr< ConstantBuffer > const &pvwMatrix)
std::shared_ptr< SamplerState > mSampler
static std::string const msGLSLPSSource
static Matrix Identity()
Definition: GteMatrix.h:490
Texture2Effect(std::shared_ptr< ProgramFactory > const &factory, std::shared_ptr< Texture2 > const &texture, SamplerState::Filter filter, SamplerState::Mode mode0, SamplerState::Mode mode1)
std::shared_ptr< VisualProgram > mProgram
std::shared_ptr< ConstantBuffer > mPVWMatrixConstant
static std::string const msHLSLSource


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