本文整理汇总了C++中Program::Link方法的典型用法代码示例。如果您正苦于以下问题:C++ Program::Link方法的具体用法?C++ Program::Link怎么用?C++ Program::Link使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Program
的用法示例。
在下文中一共展示了Program::Link方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make
static Program make(void)
{
VertexShader vs;
vs.Source(
"#version 330\n"
"uniform mat4 CameraMatrix,ModelMatrix;"
"in vec4 Position;"
"void main(void)"
"{"
" gl_Position = CameraMatrix * ModelMatrix * Position;"
"}"
).Compile();
FragmentShader fs;
fs.Source(
"#version 330\n"
"void main(void)"
"{"
"}"
).Compile();
Program prog;
prog << vs << fs;
prog.Link().Use();
return std::move(prog);
}
示例2: make_prog
static Program make_prog(FBTexExample& example)
{
Program prog(ObjectDesc("Thread"));
prog.AttachShader(example.vertex_shader);
FragmentShader fs(ObjectDesc("Thread fragment"));
fs.Source(
"#version 330\n"
"in vec3 vertNormal;"
"in vec3 vertLight;"
"in vec2 vertTexCoord;"
"out vec3 fragColor;"
"void main(void)"
"{"
" float d = max(dot("
" vertNormal, "
" normalize(vertLight)"
" ), 0.0);"
" float i = int("
" vertTexCoord.x*18.0+"
" vertTexCoord.y*14.0 "
" ) % 2;"
" vec3 Red = vec3(1.0, 0.2, 0.2);"
" vec3 White = vec3(1.0, 1.0, 1.0);"
" fragColor = (0.4+0.8*d)*mix(Red, White, i);"
"}"
);
fs.Compile();
prog.AttachShader(fs);
prog.Link().Use();
return std::move(prog);
}
示例3: make
static Program make(void)
{
Program prog;
prog << VertexShader(ObjectDesc("Mesh"),
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec4 Position;"
"void main(void)"
"{"
" gl_Position = "
" ProjectionMatrix*CameraMatrix*ModelMatrix*Position;"
"}"
);
prog << FragmentShader(ObjectDesc("Mesh"),
"#version 330\n"
"out vec3 fragColor;"
"void main(void)"
"{"
" fragColor = vec3(0.1);"
"}"
);
prog.Link();
return prog;
}
示例4: make_prog
static Program make_prog(void)
{
Program prog;
VertexShader vs;
vs.Source(
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"mat4 Matrix = ProjectionMatrix*CameraMatrix*ModelMatrix;"
"in vec4 Position;"
"void main(void)"
"{"
" gl_Position = Matrix*Position;"
"}"
);
FragmentShader fs;
fs.Source(
"#version 330\n"
"void main(void){ }"
);
prog.AttachShader(vs).AttachShader(fs);
prog.Link().Validate().Use();
return std::move(prog);
}
示例5: make
static Program make(const VertexShader& vs)
{
Program prog;
FragmentShader fs(ObjectDesc("Draw"));
fs.Source(
"#version 140\n"
"const vec3 LightColor = vec3(0.6, 0.6, 1.0);"
"const vec3 Up = normalize(vec3(0.1, 1.0, 0.1));"
"uniform vec3 LightScreenPos;"
"uniform vec2 ScreenSize;"
"uniform sampler2DRect LightMap;"
"uniform sampler2DShadow ShadowMap;"
"in vec3 vertNormal;"
"in vec3 vertLightDir;"
"in vec4 vertShadowCoord;"
"out vec3 fragColor;"
"void main(void)"
"{"
" vec3 ShadowCoord = (vertShadowCoord.xyz/vertShadowCoord.w)*0.5 + 0.5;"
" float s = 0.0f;"
" if("
" ShadowCoord.x >= 0.0 && "
" ShadowCoord.x <= 1.0 && "
" ShadowCoord.y >= 0.0 && "
" ShadowCoord.y <= 1.0 && "
" ShadowCoord.z <= 1.0"
" ) s = texture(ShadowMap, ShadowCoord);"
" float a = 0.1*(max(dot(vertNormal, Up)+0.1, 0.0)+0.1);"
" float d = max(dot(vertNormal, vertLightDir)+0.1, 0.0)+a;"
" vec2 LMCoord = gl_FragCoord.xy;"
" vec2 LPos = (LightScreenPos.xy*0.5+0.5)*ScreenSize;"
" vec2 Ray = LMCoord - LPos;"
" float Len = length(Ray);"
" int NSampl = int(max(abs(Ray.x), abs(Ray.y)))+1;"
" vec2 RayStep = Ray / NSampl;"
" float r = texture(LightMap, LMCoord).r;"
" NSampl = min(NSampl, int(min(ScreenSize.x, ScreenSize.y)*0.25));"
" for(int s=0; s!=NSampl;++s)"
" {"
" r += texture(LightMap, LPos+RayStep*s).r;"
" }"
" r /= NSampl;"
" r = min(r, 1.0);"
" fragColor = LightColor * (mix(a, d, s) + r);"
"}"
).Compile();
prog.AttachShader(vs).AttachShader(fs);
prog.Link().Use();
return prog;
}
示例6: vert_attr
RectangleExample(void)
{
prog << "#version 330\n"
"in vec2 Position;"
"in vec3 Color;"
"out vec3 vertColor;"
"void main(void)"
"{"
" vertColor = Color;"
" gl_Position = vec4(Position, 0.0, 1.0);"
"}"_glsl_vs;
prog << "#version 330\n"
"in vec3 vertColor;"
"out vec4 fragColor;"
"void main(void)"
"{"
" fragColor = vec4(vertColor, 1.0);"
"}"_glsl_fs;
prog.Link();
prog.Use();
// bind the VAO for the rectangle
rectangle.Bind();
GLfloat rectangle_verts[8] = {
-1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, -1.0f,
1.0f, 1.0f
};
// bind the VBO for the rectangle vertices
verts.Bind(Buffer::Target::Array);
// upload the data
Buffer::Data(Buffer::Target::Array, 8, rectangle_verts);
// setup the vertex attribs array for the vertices
VertexAttribArray vert_attr(prog, "Position");
vert_attr.Setup(2, DataType::Float);
vert_attr.Enable();
GLfloat rectangle_colors[12] = {
0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f,
};
// bind the VBO for the rectangle colors
colors.Bind(Buffer::Target::Array);
// upload the data
Buffer::Data(Buffer::Target::Array, 12, rectangle_colors);
// setup the vertex attribs array for the vertices
VertexAttribArray color_attr(prog, "Color");
color_attr.Setup(3, DataType::Float);
color_attr.Enable();
//
gl.ClearDepth(1.0f);
}
示例7: make
static Program make(const LiquidProgramShaders& shaders)
{
Program prog;
prog.AttachShader(shaders.vertex);
prog.AttachShader(shaders.geometry);
prog.AttachShader(shaders.fragment);
prog.Link().Use();
return prog;
}
示例8: make
static Program make(void)
{
Program prog;
prog.AttachShader(LiquidVertShader());
prog.AttachShader(LiquidGeomShader());
prog.AttachShader(LiquidFragShader());
prog.Link().Use();
return prog;
}
示例9: make_prog
static Program make_prog(void)
{
VertexShader vs;
vs.Source(
"#version 130\n"
"uniform mat4 ProjectionMatrix, ModelMatrix, CameraMatrix;"
"uniform vec4 ClipPlane;"
"attribute vec4 Position;"
"attribute vec2 TexCoord;"
"varying vec2 vertTexCoord;"
"void main(void)"
"{"
" vertTexCoord = TexCoord;"
" gl_Position = "
" ModelMatrix *"
" Position;"
" gl_ClipDistance[0] = dot(ClipPlane, gl_Position);"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" gl_Position;"
"}"
);
vs.Compile();
FragmentShader fs;
fs.Source(
"#version 130\n"
"varying vec2 vertTexCoord;"
"void main(void)"
"{"
" float i = ("
" int(vertTexCoord.x*36) % 2+"
" int(vertTexCoord.y*24) % 2"
" ) % 2;"
" if(gl_FrontFacing)"
" {"
" gl_FragColor = vec4(1-i/2, 1-i/2, 1-i/2, 1.0);"
" }"
" else"
" {"
" gl_FragColor = vec4(0+i/2, 0+i/2, 0+i/2, 1.0);"
" }"
"}"
);
fs.Compile();
Program prog;
prog.AttachShader(vs);
prog.AttachShader(fs);
prog.Link();
prog.Use();
return prog;
}
示例10: return
Program * ProgramManager::AddProgram(const String &vertFileName, const String &fragFileName)
{
ProgramMapIterator it = mPrograms.find(vertFileName);
if (it != mPrograms.end())
return (*it).second;
InputStream *vertStream = FileSystem::GetPtr()->GetInputStream(vertFileName);
if (!vertStream)
{
LogError("Unable to open vertex shader file %s", vertFileName);
return NULL;
}
InputStream *fragStream = FileSystem::GetPtr()->GetInputStream(fragFileName);
if (!fragStream)
{
LogError("Unable to open fragment shader file %s", fragFileName);
return NULL;
}
Program *program = mGraphicsDevice->CreateProgram(vertFileName);
if (!program->LoadShader(Program::ShaderType_Vertex, vertStream))
{
LogError("Unable to load vertex shader %s", vertStream->GetFileName());
SafeDelete(program);
return NULL;
}
if (!program->LoadShader(Program::ShaderType_Fragment, fragStream))
{
LogError("Unable to load frag shader %s", fragStream->GetFileName());
SafeDelete(program);
return NULL;
}
if (!program->Link())
{
LogError("Unable to link program %s", vertStream->GetFileName());
SafeDelete(program);
return NULL;
}
mPrograms[vertStream->GetFileName()] = program;
return program;
}
示例11: make_prog
static Program make_prog(void)
{
VertexShader vs;
vs.Source(
"#version 330\n"
"in vec4 Position;"
"in vec3 Normal;"
"out vec3 vertColor;"
"out vec3 vertNormal;"
"out vec3 vertLight;"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"uniform vec3 LightPos;"
"void main(void)"
"{"
" gl_Position = ModelMatrix * Position;"
" vertColor = abs(normalize(Normal+vec3(1, 1, 1)));"
" vertNormal = mat3(ModelMatrix)*Normal;"
" vertLight = LightPos - gl_Position.xyz;"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}"
);
vs.Compile();
FragmentShader fs;
fs.Source(
"#version 330\n"
"in vec3 vertColor;"
"in vec3 vertNormal;"
"in vec3 vertLight;"
"out vec4 fragColor;"
"void main(void)"
"{"
" float l = dot(vertLight, vertLight);"
" float d = l > 0.0 ? dot(vertNormal, normalize(vertLight)) / l : 0.0;"
" float i = 0.2 + max(d*3.2, 0.0);"
" fragColor = vec4(vertColor*i, 1.0);"
"}"
);
fs.Compile();
Program prog;
prog.AttachShader(vs);
prog.AttachShader(fs);
prog.Link();
return prog;
}
示例12: GLuint
Particle(const VertexShader& vs, FragmentShader&& frag)
: sphere_instr(make_sphere.Instructions())
, sphere_indices(make_sphere.Indices())
, fs(std::forward<FragmentShader>(frag))
{
// attach the shaders to the program
prog.AttachShader(vs);
prog.AttachShader(fs);
// link and use it
prog.Link();
prog.Use();
projection_matrix = (prog/"ProjectionMatrix");
camera_matrix = (prog/"CameraMatrix");
model_matrix = (prog/"ModelMatrix");
light_pos = (prog/"LightPos");
// bind the VAO for the sphere
sphere.Bind();
const GLuint n_attr = 2;
// pointers to the vertex attribute data build functions
typedef GLuint (shapes::Sphere::*Func)(std::vector<GLfloat>&) const;
Func func[n_attr] = {
&shapes::Sphere::Positions,
&shapes::Sphere::Normals,
};
// managed references to the VBOs
Reference<Buffer> vbo[n_attr] = {verts, normals};
// vertex attribute identifiers from the shaders
const GLchar* ident[n_attr] = {"Position", "Normal"};
for(GLuint i=0; i!=n_attr; ++i)
{
// bind the VBO
vbo[i].Bind(Buffer::Target::Array);
// make the data
std::vector<GLfloat> data;
GLuint n_per_vertex = (make_sphere.*func[i])(data);
// upload the data
Buffer::Data(Buffer::Target::Array, data);
// setup the vertex attrib
VertexArrayAttrib attr(prog, ident[i]);
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
}
示例13: make_face_prog
static Program make_face_prog(void)
{
FragmentShader fs;
fs.Source(
"#version 330\n"
"in vec3 geomNormal;"
"in vec3 geomLight;"
"in float geomGlow;"
"flat in int geomTop;"
"uniform vec3 TopColor, SideColor;"
"const vec3 LightColor = vec3(1.0, 1.0, 1.0);"
"out vec4 fragColor;"
"void main(void)"
"{"
" float d = max(dot("
" normalize(geomLight),"
" normalize(geomNormal)"
" ), 0.0);"
" vec3 color;"
" if(geomTop != 0)"
" {"
" color = TopColor * d +"
" LightColor * pow(d, 8.0);"
" }"
" else"
" {"
" color = SideColor * geomGlow +"
" LightColor *"
" pow(d, 2.0) * 0.2;"
" }"
" fragColor = vec4(color, 1.0);"
"}"
);
fs.Compile();
Program prog;
prog.AttachShader(fs);
prog.MakeSeparable();
prog.Link();
ProgramUniform<Vec3f>(prog, "TopColor").Set(0.2f, 0.2f, 0.2f);
ProgramUniform<Vec3f>(prog, "SideColor").Set(0.9f, 0.9f, 0.2f);
return prog;
}
示例14: make_frame_prog
static Program make_frame_prog(void)
{
FragmentShader fs;
fs.Source(
"#version 330\n"
"out vec4 fragColor;"
"void main(void)"
"{"
" fragColor = vec4(0.2, 0.1, 0.0, 1.0);"
"}"
);
fs.Compile();
Program prog;
prog.AttachShader(fs);
prog.MakeSeparable();
prog.Link();
return prog;
}
示例15: make
static Program make(void)
{
Program result;
VertexShader vs;
vs.Source(
"#version 330\n"
"#define side 128\n"
"uniform mat4 ProjectionMatrix, CameraMatrix;"
"uniform float Fade;"
"uniform sampler2D Offsets;"
"uniform sampler2D Heights;"
"in vec4 Position;"
"void main(void)"
"{"
" ivec2 Coord = ivec2(gl_InstanceID%side, gl_InstanceID/side);"
" vec2 Offs = texelFetch(Offsets, Coord, 0).xy;"
" float Height = 1.0-texelFetch(Heights, Coord, 0).r;"
" gl_Position = Position;"
" gl_Position.xz += Offs;"
" gl_Position.y *= max(Height*Fade*side/2, 0.5);"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}"
).Compile();
FragmentShader fs;
fs.Source(
"#version 330\n"
"void main(void) { }"
).Compile();
result.AttachShader(vs).AttachShader(fs);
result.Link().Validate().Use();
return std::move(result);
}