本文整理汇总了C++中Context类的典型用法代码示例。如果您正苦于以下问题:C++ Context类的具体用法?C++ Context怎么用?C++ Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FormProcGotoParse
bool
FormProcGotoParse(Units *units, Function *fn, llvm::BasicBlock *block,
Node *node, bool get_address, bool prefixed_with_core,
ParseResult *pr)
{
Context *ctx = units->top()->ctx;
if (!ctx->er->assertArgNums("goto", node, 1, 1)) {
return false;
}
std::vector<Node *> *lst = node->list;
Node *label_node = (*lst)[1];
if (!ctx->er->assertArgIsAtom("goto", label_node, "1")) {
return false;
}
if (!ctx->er->assertAtomIsSymbol("goto", label_node, "1")) {
return false;
}
const char *label_name = label_node->token->str_value.c_str();
Label *label = fn->getLabel(label_name);
if (!label) {
/* If the label does not exist, then this goto becomes a
* deferred goto. */
DeferredGoto *dg = new DeferredGoto;
dg->label_name.append(label_name);
dg->ns = ctx->ns();
dg->index = ctx->ns()->lv_index;
dg->block_marker = block;
Node *myn = new Node();
node->copyTo(myn);
dg->node = myn;
if (block->size() == 0) {
dg->marker = NULL;
} else {
llvm::Instruction *tinstr = &(block->back());
dg->marker = tinstr;
}
fn->deferred_gotos.push_back(dg);
/* Add a no-op instruction to the block, so that label parsing
* does not add an implicit branch from the previous block to
* the new block. This will occur when the previous block
* does not end with a terminator, which will be the case here
* because the goto is deferred. */
llvm::IRBuilder<> builder(block);
builder.CreateBitCast(
ctx->nt->getLLVMZero(),
ctx->nt->getNativeIntType()
);
} else {
/* Get all the variables that exist within the current scope
* and have an index greater than the label's index. Add a
* Destruct call for each of these variables. */
std::vector<Variable *> myvars;
ctx->ns()->getVarsAfterIndex(label->index, &myvars);
ParseResult destruct_pr;
destruct_pr.block = block;
destruct_pr.do_not_destruct = false;
llvm::IRBuilder<> builder(destruct_pr.block);
for (std::vector<Variable *>::iterator b = myvars.begin(),
e = myvars.end();
b != e;
++b) {
builder.SetInsertPoint(destruct_pr.block);
Variable *var = (*b);
destruct_pr.type = var->type;
llvm::Value *var_value = builder.CreateLoad(var->value);
destruct_pr.value = var_value;
Operation::Destruct(ctx, &destruct_pr, &destruct_pr);
}
block = destruct_pr.block;
builder.SetInsertPoint(block);
builder.CreateBr(label->block);
}
pr->set(block, ctx->tr->type_int, ctx->nt->getLLVMZero());
if (!label) {
pr->treat_as_terminator = true;
}
pr->do_not_copy_with_setf = true;
return true;
}
示例2: AddResourceRef
void JSONValue::AddResourceRef(const ResourceRef& value)
{
Context* context = file_->GetContext();
AddString(String(context->GetTypeName(value.type_)) + ";" + value.name_);
}
示例3: draw
// ----------------------------------------------------------------------
void
DrawableNodeDefault::
draw( cairo_t* cr, double t, const Context& C )
const throw(std::runtime_error)
{
Drawable::draw(cr,t,C);
if( visible() )
{
shawn::Vec pos = position(t);
double size = node_properties().size(t);
shawn::Vec bg;
shawn::ConstTagHandle rtag = node().find_tag( "red" );
shawn::ConstTagHandle gtag = node().find_tag( "green" );
shawn::ConstTagHandle btag = node().find_tag( "blue" );
//if(rtag!=NULL && gtag!=NULL && btag!=NULL)
//{
// double r = dynamic_cast<const shawn::DoubleTag*>( rtag.get() )->value();
// double g = dynamic_cast<const shawn::DoubleTag*>( gtag.get() )->value();
// double b = dynamic_cast<const shawn::DoubleTag*>( btag.get() )->value();
//
// bg = shawn::Vec(r,g,b);
//}
//else
//{
bg = node_properties().background(t);
//}
int shape = node_properties().shape(t);
cairo_save(cr);
cairo_translate(cr,pos.x(),pos.y());
cairo_set_line_width( cr, 0 );
switch(shape)
{
case 2:
cairo_rectangle(cr,-size,-size,size*2,size*2);
break;
default:
cairo_arc(cr,0.0,0.0,size,0,2.0*M_PI);
break;
}
blend_set_color(cr,bg);
cairo_fill(cr);
if( C.draft_level()<2 ) {
double lw = node_properties().line_width(t);
shawn::Vec fg = node_properties().foreground(t);
cairo_set_line_width( cr, lw );
switch(shape)
{
case 2:
cairo_rectangle(cr,-size,-size,size*2,size*2);
break;
default:
cairo_arc(cr,0.0,0.0,size,0,2.0*M_PI);
break;
}
blend_set_color(cr,fg);
cairo_stroke(cr);
}
cairo_restore(cr);
}
}
示例4: extensionsString
void ContextTest::extensionsString() {
std::vector<std::string> extensions = _context.extensionStrings();
CORRADE_VERIFY(extensions.size() > 0);
}
示例5: main
int main(int argc, char* argv[])
{
XnStatus nRetVal = XN_STATUS_OK;
nRetVal = xnLogInitFromXmlFile(SAMPLE_XML_PATH);
if (nRetVal != XN_STATUS_OK)
{
printf("Log couldn't be opened: %s. Running without log", xnGetStatusString(nRetVal));
}
if (argc < 3)
{
printf("usage: %s <inputFile> <outputFile>\n", argv[0]);
return -1;
}
const char* strInputFile = argv[1];
const char* strOutputFile = argv[2];
Context context;
nRetVal = context.Init();
CHECK_RC(nRetVal, "Init");
// open input file
Player player;
nRetVal = context.OpenFileRecording("/media/6B58CB581C0AACF6/7.oni", player);
CHECK_RC(nRetVal, "Open input file");
// Get depth node from recording
DepthGenerator depth;
nRetVal = context.FindExistingNode(XN_NODE_TYPE_DEPTH, depth);
CHECK_RC(nRetVal, "Find depth generator");
// Create mock node based on depth node from recording
MockDepthGenerator mockDepth;
nRetVal = mockDepth.CreateBasedOn(depth);
CHECK_RC(nRetVal, "Create mock depth node");
ImageGenerator image;
nRetVal = context.FindExistingNode(XN_NODE_TYPE_IMAGE, image);
CHECK_RC(nRetVal, "Find depth generator");
// Create mock node based on depth node from recording
MockImageGenerator mockImage;
nRetVal = mockImage.CreateBasedOn(image);
CHECK_RC(nRetVal, "Create mock depth node");
// create recorder
Recorder recorder;
nRetVal = recorder.Create(context);
CHECK_RC(nRetVal, "Create recorder");
nRetVal = recorder.SetDestination(XN_RECORD_MEDIUM_FILE, "/home/shaghayegh/up.oni");
CHECK_RC(nRetVal, "Set recorder destination file");
// add depth node to recorder
nRetVal = recorder.AddNodeToRecording(mockDepth);
CHECK_RC(nRetVal, "Add node to recording");
// nRetVal = recorder.AddNodeToRecording(mockImage);
// CHECK_RC(nRetVal, "Add node to recording");
nRetVal = player.SetRepeat(FALSE);
XN_IS_STATUS_OK(nRetVal);
XnUInt32 nNumFrames = 0;
nRetVal = player.GetNumFrames(depth.GetName(), nNumFrames);
CHECK_RC(nRetVal, "Get player number of frames");
DepthMetaData depthMD;
ImageMetaData imageMD;
int frameNum = 0;
String path = "/media/6B58CB581C0AACF6/ebook/Articles/activity_recognition/data1/0512164529/";
while ((nRetVal = depth.WaitAndUpdateData()) != XN_STATUS_EOF)
{
++frameNum;
CHECK_RC(nRetVal, "Read next frame");
// Get depth meta data
depth.GetMetaData(depthMD);
image.GetMetaData(imageMD);
//-----------------------------------------------//
// Transform depth! This is the interesting part //
//-----------------------------------------------//
/* Enable the depth data to be modified. This is done implicitly by depthMD.WritableDepthMap(),
but we're calling it just to be clear. */
nRetVal = depthMD.MakeDataWritable();
CHECK_RC(nRetVal, "Make depth data writable");
// nRetVal = imageMD.MakeDataWritable();
// CHECK_RC(nRetVal, "Make depth data writable");
String ficheroActualRGB;
// ficheroActualRGB = path +"RGB_" + boost::to_string(frameNum) + ".png";
String ficheroActualDepth = path +"Depth_"+ boost::to_string(frameNum) + ".png";
// Mat matFrameImage = imread(ficheroActualRGB, 1);
// resize(matFrameImage, matFrameImage, Size(640, 480), 0, 0, INTER_CUBIC);
Mat matFrameDepth = imread(ficheroActualDepth,1);
resize(matFrameDepth, matFrameDepth, Size(480, 640), 0, 0, INTER_CUBIC);
transformDepthMD(matFrameDepth,depthMD);
// transformImageMD(matFrameImage,imageMD);
// Pass the transformed data to the mock depth generator
nRetVal = mockDepth.SetData(depthMD);
CHECK_RC(nRetVal, "Set mock node new data");
// nRetVal = mockImage.SetData(imageMD);
// CHECK_RC(nRetVal, "Set mock node new data");
/* We need to call recorder.Record explicitly because we're not using WaitAndUpdateAll(). */
nRetVal = recorder.Record();
CHECK_RC(nRetVal, "Record");
//.........这里部分代码省略.........
示例6:
std::unique_ptr<Value>
VariableValueNode::getValue(const Context& context) const {
return context.getValue(_value);
}
示例7: Context
SkImageFilter::Context SkImageFilter::mapContext(const Context& ctx) const {
SkIRect clipBounds = this->onFilterNodeBounds(ctx.clipBounds(), ctx.ctm(),
MapDirection::kReverse_MapDirection);
return Context(ctx.ctm(), clipBounds, ctx.cache());
}
示例8: stop
void Ave::stop(Context &context) {
variableNames.clear();
context.removeSegment(targetSegment->getId());
}
示例9: process
void Ave::process(Context &context) {
using std::min;
const long lastSourceL = context.getLastComputableL(*sourceSegment, *this);
const long firstTargetL = context.getFirstComputableL(*targetSegment, *this);
long lastTargetL = (lastSourceL - sourceSegment->getGrid().getMinL() + 1) / averagingFactor;
if (lastSourceL < sourceSegment->getGrid().getMaxL()) {
lastTargetL--;
}
lastTargetL = min(lastTargetL, context.getLastComputableL(*targetSegment, *this));
context.getLogging().debug("Segment [" + targetSegment->toString() + "]: firstComputableL = " + lexical_cast<string>(firstTargetL), getId());
context.getLogging().debug("Segment [" + targetSegment->toString() + "]: lastComputableL = " + lexical_cast<string>(lastTargetL), getId());
averageVariables(context.getLogging(), firstTargetL, lastTargetL);
context.setFirstRequiredL(*sourceSegment, *this, (lastTargetL + 1) * averagingFactor);
// TODO - this is needed for synchronizing OLC and SYN_COLLOCATED segments, better unite both segments into one
context.setFirstRequiredL(context.getSegment(Constants::SEGMENT_OLC), *this, (lastTargetL + 1) * averagingFactor);
if (context.getSegment(Constants::SEGMENT_OLC_MIS).getGrid().getSizeL() > 1) {
context.setFirstRequiredL(context.getSegment(Constants::SEGMENT_OLC_MIS), *this, (lastTargetL + 1) * averagingFactor);
}
context.setLastComputedL(*targetSegment, *this, lastTargetL);
}
示例10: generate
/*
* This one is specified in, and called from, AppleKeyPairGenContext
*/
void DSAKeyPairGenContext::generate(
const Context &context,
BinaryKey &pubBinKey,
BinaryKey &privBinKey,
uint32 &keyBits)
{
/*
* These casts throw exceptions if the keys are of the
* wrong classes, which would be a major bogon, since we created
* the keys in the above generate() function.
*/
DSABinaryKey &rPubBinKey =
dynamic_cast<DSABinaryKey &>(pubBinKey);
DSABinaryKey &rPrivBinKey =
dynamic_cast<DSABinaryKey &>(privBinKey);
/*
* Parameters from context:
* Key size in bits, required;
* {p,q,g} from generateParams, optional
*/
keyBits = context.getInt(CSSM_ATTRIBUTE_KEY_LENGTH,
CSSMERR_CSP_MISSING_ATTR_KEY_LENGTH);
if(keyBits > DSA_MAX_KEY_SIZE) {
CssmError::throwMe(CSSMERR_CSP_INVALID_ATTR_KEY_LENGTH);
}
CssmData *paramData = context.get<CssmData>(CSSM_ATTRIBUTE_ALG_PARAMS);
NSS_DSAAlgParams algParams;
SecNssCoder coder; // generated algParams mallocd from here
if(paramData != NULL) {
/* this contains the DER encoding of a NSS_DSAAlgParams */
CSSM_RETURN crtn = DSADecodeAlgParams(algParams, paramData->Data,
(unsigned)paramData->Length, coder);
if(crtn) {
CssmError::throwMe(crtn);
}
}
else {
/* no alg params specified; generate them now using null (random) seed */
dsaGenParams(keyBits, NULL, 0, algParams, coder);
}
/* create key, stuff params into it */
rPrivBinKey.mDsaKey = DSA_new();
if(rPrivBinKey.mDsaKey == NULL) {
CssmError::throwMe(CSSMERR_CSP_MEMORY_ERROR);
}
DSA *dsaKey = rPrivBinKey.mDsaKey;
dsaKey->p = cssmDataToBn(algParams.p);
dsaKey->q = cssmDataToBn(algParams.q);
dsaKey->g = cssmDataToBn(algParams.g);
/* generate the key (both public and private capabilities) */
int irtn = DSA_generate_key(dsaKey);
if(!irtn) {
throwRsaDsa("DSA_generate_key");
}
/* public key is subset of private key */
rPubBinKey.mDsaKey = DSA_new();
if(rPrivBinKey.mDsaKey == NULL) {
CssmError::throwMe(CSSMERR_CSP_MEMORY_ERROR);
}
DSA *pub = rPubBinKey.mDsaKey;
DSA *priv = rPrivBinKey.mDsaKey;
pub->p = BN_dup(priv->p);
pub->q = BN_dup(priv->q);
pub->g = BN_dup(priv->g);
pub->pub_key = BN_dup(priv->pub_key);
if((pub->p == NULL) || (pub->q == NULL) || (pub->g == NULL) ||
(pub->pub_key == NULL)) {
CssmError::throwMe(CSSMERR_CSP_MEMORY_ERROR);
}
}
示例11: attr
SphereExample(void)
: sphere_instr(make_sphere.Instructions())
, sphere_indices(make_sphere.Indices())
, hole_count(50)
, hole_diameter(0.30f)
{
// This shader will be used in transform fedback mode
// to transform the vertices used to "cut out the holes"
// the same way the sphere is transformed
vs_tfb.Source(
"#version 330\n"
"uniform mat4 CameraMatrix, ModelMatrix;"
"uniform float Diameter;"
"in vec3 Hole;"
"out vec3 vertTransfHole;"
"void main(void)"
"{"
" vertTransfHole = ("
" CameraMatrix *"
" ModelMatrix *"
" vec4(Hole * (1.0 + 0.5 * Diameter), 0.0)"
" ).xyz;"
"}"
);
// compile, setup transform feedback output variables
// link and use the program
vs_tfb.Compile();
prog_tfb.AttachShader(vs_tfb);
const GLchar* var_name = "vertTransfHole";
prog_tfb.TransformFeedbackVaryings(
1, &var_name,
TransformFeedbackMode::InterleavedAttribs
);
prog_tfb.Link();
prog_tfb.Use();
Uniform<GLfloat> diameter(prog_tfb, "Diameter");
diameter.Set(hole_diameter);
// bind the VAO for the holes
holes.Bind();
// bind the VBO for the hole vertices
hole_verts.Bind(Buffer::Target::Array);
// and the VBO for the transformed hole vertices captured by tfb
transf_hole_verts.Bind(Buffer::Target::TransformFeedback);
{
std::vector<GLfloat> data;
make_hole_data(data, hole_count);
Buffer::Data(Buffer::Target::TransformFeedback, data);
Buffer::Data(Buffer::Target::Array, data);
VertexArrayAttrib attr(prog_tfb, "Hole");
attr.Setup<Vec3f>();
attr.Enable();
}
transf_hole_verts.BindBase(
Buffer::IndexedTarget::TransformFeedback,
0
);
// Set the vertex shader source
vs.Source(
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec4 Position;"
"in vec3 Normal;"
"out vec3 vertNormal;"
"out vec3 vertLight;"
"const vec3 LightPos = vec3(2.0, 3.0, 3.0);"
"void main(void)"
"{"
" gl_Position = ModelMatrix * Position;"
" vertNormal = mat3(ModelMatrix)*Normal;"
" vertLight = LightPos-gl_Position.xyz;"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}"
);
// compile it
vs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"in vec3 vertNormal;"
"in vec3 vertLight;"
"out vec4 fragColor;"
"const int HoleCount = 50;"
"uniform vec3 TransfHole[50];"
"uniform float Diameter;"
"void main(void)"
"{"
" int imax = 0;"
" float dmax = -1.0;"
" for(int i=0; i!=HoleCount; ++i)"
" {"
" float d = dot(vertNormal, TransfHole[i]);"
" if(dmax < d)"
" {"
" dmax = d;"
//.........这里部分代码省略.........
示例12: vert
TessellationExample(void)
: prog()
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
{
VertexShader vert(ObjectDesc("Vertex"));
vert.Source(StrLit(
"#version 330\n"
"uniform mat4 CameraMatrix;"
"in vec4 Position;"
"out vec4 vertPosition;"
"void main(void)"
"{"
" vertPosition = CameraMatrix * Position;"
"}"
));
vert.Compile();
prog << vert;
TessControlShader teco(ObjectDesc("TessControl"));
teco.Source(StrLit(
"#version 330\n"
"#extension ARB_tessellation_shader: enable\n"
"layout(vertices = 16) out;"
"in vec4 vertPosition[];"
"patch out vec3 tecoPosition[16];"
"void main(void)"
"{"
" if(gl_InvocationID == 0)"
" {"
" int tl = 1-int(100.0 / vertPosition[gl_InvocationID].z);"
" gl_TessLevelInner[0] = tl;"
" gl_TessLevelInner[1] = tl;"
" gl_TessLevelOuter[0] = tl;"
" gl_TessLevelOuter[1] = tl;"
" gl_TessLevelOuter[2] = tl;"
" gl_TessLevelOuter[3] = tl;"
" }"
" tecoPosition[gl_InvocationID] = "
" vertPosition[gl_InvocationID].xyz;"
"}"
));
teco.Compile();
prog << teco;
TessEvaluationShader teev(ObjectDesc("TessEvaluation"));
teev.Source(StrLit(
"#version 330\n"
"#extension ARB_tessellation_shader: enable\n"
"layout(quads, equal_spacing, ccw) in;"
"uniform mat4 ProjectionMatrix;"
"patch in vec3 tecoPosition[16];"
"const mat4 B = mat4("
" -1, 3,-3, 1,"
" 3,-6, 3, 0,"
" -3, 3, 0, 0,"
" 1, 0, 0, 0 "
");"
"mat4 Px, Py, Pz;"
"void main(void)"
"{"
" float u = gl_TessCoord.x, v = gl_TessCoord.y;"
" for(int j=0; j!=4; ++j)"
" for(int i=0; i!=4; ++i)"
" {"
" int k = j*4+i;"
" Px[j][i] = tecoPosition[k].x;"
" Py[j][i] = tecoPosition[k].y;"
" Pz[j][i] = tecoPosition[k].z;"
" }"
" mat4 Cx = B * Px * B;"
" mat4 Cy = B * Py * B;"
" mat4 Cz = B * Pz * B;"
" vec4 up = vec4(u*u*u, u*u, u, 1);"
" vec4 vp = vec4(v*v*v, v*v, v, 1);"
" vec4 tempPosition = vec4(dot(Cx * vp, up), dot(Cy * vp, up), dot(Cz * vp, up), 1.0);"
" gl_Position = ProjectionMatrix * tempPosition;"
"}"
));
teev.Compile();
prog << teev;
FragmentShader frag(ObjectDesc("Fragment"));
frag.Source(StrLit(
"#version 330\n"
"out vec3 fragColor;"
"void main(void)"
"{"
//.........这里部分代码省略.........
示例13: lightPos
PoolTilesExample()
: make_plane(
Vec3f(), Vec3f(7.0f, 0.0f, 0.0f), Vec3f(0.0f, 0.0f, -7.0f), 48, 48)
, plane_instr(make_plane.Instructions())
, plane_indices(make_plane.Indices())
, make_shape()
, shape_instr(make_shape.Instructions())
, shape_indices(make_shape.Indices())
, plane_vs(ObjectDesc("Plane vertex"))
, shape_vs(ObjectDesc("Shape vertex"))
, plane_fs(ObjectDesc("Plane fragment"))
, shape_fs(ObjectDesc("Shape fragment"))
, plane_camera_matrix(plane_prog, "CameraMatrix")
, shape_camera_matrix(shape_prog, "CameraMatrix")
, plane_camera_position(plane_prog, "CameraPosition")
, width(800)
, height(600)
, refl_tex_side(width > height ? height : width)
, tile_tex_side(64) {
gl.RequireAtLeast(LimitQuery::MaxCombinedTextureImageUnits, 5);
plane_vs.Source(
"#version 140\n"
"uniform vec3 LightPosition;"
"uniform vec3 CameraPosition;"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec4 Position;"
"in vec2 TexCoord;"
"out vec3 vertLightDir;"
"out vec3 vertViewDir;"
"out vec4 vertReflTexCoord;"
"out vec2 vertTileTexCoord;"
"void main()"
"{"
" gl_Position = ModelMatrix* Position;"
" vertLightDir = normalize(LightPosition - gl_Position.xyz);"
" vertViewDir = normalize(CameraPosition - gl_Position.xyz);"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
" vertReflTexCoord = gl_Position;"
" vertTileTexCoord = TexCoord;"
"}");
plane_vs.Compile();
plane_fs.Source(
"#version 140\n"
"uniform sampler2D RandTex, PictTex, TileTex, NormTex;"
"uniform sampler2D ReflectTex;"
"uniform uint TileCount;"
"uniform float Aspect;"
"in vec3 vertLightDir;"
"in vec3 vertViewDir;"
"in vec4 vertReflTexCoord;"
"in vec2 vertTileTexCoord;"
"out vec4 fragColor;"
"void main()"
"{"
" vec3 Normal = texture("
" NormTex, "
" vertTileTexCoord * TileCount"
" ).rgb;"
" vec3 LightRefl = reflect("
" -normalize(vertLightDir),"
" normalize(Normal)"
" );"
" float Diffuse = max(dot("
" Normal, "
" vertLightDir"
" ), 0.0);"
" float Specular = max(dot("
" LightRefl,"
" vertViewDir"
" ), 0.0);"
" float PlasterLight = 0.3 + max(Diffuse, 0.0);"
" float TileLight = 0.3 + pow(Diffuse, 2.0)*0.9 + pow(Specular, "
"4.0)*2.5;"
" vec2 ReflCoord = vertReflTexCoord.xy;"
" ReflCoord /= vertReflTexCoord.w;"
" ReflCoord *= 0.5;"
" ReflCoord += vec2(Aspect*0.5, 0.5);"
" ReflCoord += vec2(Normal.x, Normal.z)*0.5;"
" vec3 ReflColor = texture("
" ReflectTex, "
" ReflCoord"
" ).rgb;"
" vec3 TileProps = texture("
" TileTex, "
" vertTileTexCoord * TileCount"
" ).rgb;"
" float Pict = texture(PictTex, vertTileTexCoord).r;"
" float Rand = texture(RandTex, vertTileTexCoord).r;"
" float LightVsDark = "
" mix( 0.1, 0.9, Pict)+"
" mix(-0.1, 0.1, Rand);"
" vec3 TileColor = mix("
" vec3(0.1, 0.1, 0.5),"
" vec3(0.4, 0.4, 0.9),"
" LightVsDark "
" );"
" vec3 PlasterColor = vec3(0.9, 0.9, 0.9);"
" fragColor = vec4("
//.........这里部分代码省略.........
示例14: attr
CubeExample(void)
: cube_instr(make_cube.Instructions())
, cube_indices(make_cube.Indices())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
{
// Set the vertex shader source
vs.Source(
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix;"
"in vec4 Position;"
"out vec3 vertColor;"
"void main(void)"
"{"
" float angle = gl_InstanceID * 10 * 2 * 3.14159 / 360.0;"
" float cx = cos(angle);"
" float sx = sin(angle);"
" mat4 ModelMatrix = mat4("
" cx, 0.0, sx, 0.0,"
" 0.0, 1.0, 0.0, 0.0,"
" -sx, 0.0, cx, 0.0,"
" 0.0, 0.0, 0.0, 1.0 "
" ) * mat4("
" 1.0, 0.0, 0.0, 0.0,"
" 0.0, 1.0, 0.0, 0.0,"
" 0.0, 0.0, 1.0, 0.0,"
" 12.0, 0.0, 0.0, 1.0 "
" );"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" ModelMatrix *"
" Position;"
" vertColor = abs(normalize((ModelMatrix*Position).xyz));"
"}"
);
// compile it
vs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"in vec3 vertColor;"
"out vec4 fragColor;"
"void main(void)"
"{"
" fragColor = vec4(vertColor, 1.0);"
"}"
);
// compile it
fs.Compile();
// attach the shaders to the program
prog.AttachShader(vs);
prog.AttachShader(fs);
// link and use it
prog.Link();
prog.Use();
// bind the VAO for the cube
cube.Bind();
// bind the VBO for the cube vertices
verts.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Positions(data);
// upload the data
Buffer::Data(Buffer::Target::Array, data);
// setup the vertex attribs array for the vertices
VertexAttribArray attr(prog, "Position");
attr.Setup(n_per_vertex, DataType::Float);
attr.Enable();
}
//
gl.ClearColor(0.9f, 0.9f, 0.9f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
}
示例15: attr
CubeMapExample(void)
: shape_instr(make_shape.Instructions())
, shape_indices(make_shape.Indices())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
{
// Set the vertex shader source
vs.Source(
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec4 Position;"
"in vec3 Normal;"
"in vec2 TexCoord;"
"out vec3 vertNormal;"
"out vec3 vertLightDir;"
"out vec3 vertLightRefl;"
"out vec3 vertViewDir;"
"out vec3 vertViewRefl;"
"uniform vec3 LightPos;"
"void main(void)"
"{"
" gl_Position = ModelMatrix * Position;"
" vertNormal = mat3(ModelMatrix)*Normal;"
" vertLightDir = LightPos - gl_Position.xyz;"
" vertLightRefl = reflect("
" -normalize(vertLightDir),"
" normalize(vertNormal)"
" );"
" vertViewDir = ("
" vec4(0.0, 0.0, 1.0, 1.0)*"
" CameraMatrix"
" ).xyz;"
" vertViewRefl = reflect("
" normalize(vertViewDir),"
" normalize(vertNormal)"
" );"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}"
);
// compile it
vs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"uniform samplerCube TexUnit;"
"in vec3 vertNormal;"
"in vec3 vertLightDir;"
"in vec3 vertLightRefl;"
"in vec3 vertViewDir;"
"in vec3 vertViewRefl;"
"out vec4 fragColor;"
"void main(void)"
"{"
" float l = length(vertLightDir);"
" float d = dot("
" normalize(vertNormal), "
" normalize(vertLightDir)"
" ) / l;"
" float s = dot("
" normalize(vertLightRefl),"
" normalize(vertViewDir)"
" );"
" vec3 lt = vec3(1.0, 1.0, 1.0);"
" vec3 env = texture(TexUnit, vertViewRefl).rgb;"
" fragColor = vec4("
" env * 0.4 + "
" (lt + env) * 1.5 * max(d, 0.0) + "
" lt * pow(max(s, 0.0), 64), "
" 1.0"
" );"
"}"
);
// compile it
fs.Compile();
// attach the shaders to the program
prog.AttachShader(vs);
prog.AttachShader(fs);
// link and use it
prog.Link();
prog.Use();
// bind the VAO for the shape
shape.Bind();
verts.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_shape.Positions(data);
Buffer::Data(Buffer::Target::Array, data);
VertexAttribArray attr(prog, "Position");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
normals.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
//.........这里部分代码省略.........