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


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