Ejemplo n.º 1
0
Archivo: parser.c Proyecto: Saruta/a2c
struct prog *parse_prog(void)
{
  algolist_t algolist = parse_algolist();
  vardecllist_t globvar;
  typedecllist_t type_decls;
  constdecllist_t const_decls;
  if( lookahead[0]->type == CONST)
  {
    const_decls = parse_constdecls();
  }
  else
    const_decls = empty_constdecllist();
  if (lookahead[0]->type == VARIABLES)
  {
    eat(VARIABLES); eat(EOL);
    globvar = parse_vardecls();
  }
  else
    globvar = empty_vardecllist();
  if (lookahead[0]->type == TYPES)
    type_decls = parse_typedecls();
  else
    type_decls = empty_typedecllist();
  eat(BEGIN); eat(EOL);
  instructionlist_t instrs = parse_block();
  eat(END);
  if (lookahead[0]->type == EOL) eat(EOL);
  eat(ENDOFFILE);
  struct entry_point *entrypoint = make_entry_point(globvar, instrs, type_decls, const_decls);
  return make_prog(algolist, entrypoint);
}
Ejemplo n.º 2
0
	FlowMapProg(GLint tex_size)
	 : Program(make_prog())
	 , hmap_1(prog(), "HMap1")
	 , hmap_2(prog(), "HMap2")
	 , time(prog(), "Time")
	{
		Uniform<GLint>(prog(), "HMapSize").Set(tex_size);
	}
Ejemplo n.º 3
0
	DisplayScene(void)
	 : gl()
	 , prog(make_prog())
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	 , ishape(shapes.end())
	 , shape_time(0)
	 , blank_time(0)
	{ }
Ejemplo n.º 4
0
    ParallaxExample()
      : prog(make_prog())
      , projection_matrix(prog, "ProjectionMatrix")
      , camera_matrix(prog, "CameraMatrix")
      , camera_position(prog, "CameraPosition")
      , light_position(prog, "LightPosition")
      , shape(
          List("Position")("TexCoord").Get(),
          shapes::Plane(
            Vec3f(),
            Vec3f(1.0f, 0.0f, 0.0f),
            Vec3f(0.0f, 0.0f, -1.0f),
            32,
            32)) {
        shape.UseInProgram(prog);

        auto tex_image = images::LoadTexture("stones_color_hmap");

        Texture::Active(0);
        try {
            UniformSampler(prog, "ColorMap").Set(0);
            gl.Bound(Texture::Target::_2D, color_tex)
              .MinFilter(TextureMinFilter::LinearMipmapLinear)
              .MagFilter(TextureMagFilter::Linear)
              .WrapS(TextureWrap::Repeat)
              .WrapT(TextureWrap::Repeat)
              .Image2D(tex_image)
              .GenerateMipmap();
        } catch(Error&) {
        }

        Texture::Active(1);
        try {
            UniformSampler(prog, "BumpMap").Set(1);
            gl.Bound(Texture::Target::_2D, bump_tex)
              .MinFilter(TextureMinFilter::LinearMipmapLinear)
              .MagFilter(TextureMagFilter::Linear)
              .WrapS(TextureWrap::Repeat)
              .WrapT(TextureWrap::Repeat)
              .Image2D(
                images::NormalMap(tex_image, images::NormalMap::FromAlpha()))
              .GenerateMipmap();
        } catch(Error&) {
        }

        gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
        gl.ClearDepth(1.0f);

        (Capability::DepthTest) << true;
        (Capability::CullFace) << false;

        (Functionality::ClipDistance | 0) << true;
        (Functionality::ClipDistance | 1) << true;
        (Functionality::ClipDistance | 2) << true;
    }
	FBTexThread(FBTexExample& example)
	 : gl()
	 , prog(make_prog(example))
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	 , shape(List("Position")("Normal")("TexCoord").Get(), shapes::TwistedTorus(), prog)
	 , tex_side(512)
	 , parent_ready(example.parent_ready)
	{
		example.thread_ready = &thread_ready;

		Uniform<Vec3f>(prog, "LightPos").Set(20.0f, 30.0f, 40.0f);

		Texture::Active(0);
		{
			auto bound_tex = Bind(example.tex, Texture::Target::_2D);
			bound_tex.Image2D(
				0,
				PixelDataInternalFormat::RGBA,
				tex_side, tex_side,
				0,
				PixelDataFormat::RGBA,
				PixelDataType::UnsignedByte,
				nullptr
			);
			bound_tex.MinFilter(TextureMinFilter::Linear);
			bound_tex.MagFilter(TextureMagFilter::Linear);
			bound_tex.WrapS(TextureWrap::Repeat);
			bound_tex.WrapT(TextureWrap::Repeat);
		}

		{
			auto bound_fbo = Bind(fbo, Framebuffer::Target::Draw);
			auto bound_rbo = Bind(rbo, Renderbuffer::Target::Renderbuffer);

 			bound_rbo.Storage(
				PixelDataInternalFormat::DepthComponent,
				tex_side,
				tex_side
			);
			bound_fbo.AttachTexture(FramebufferAttachment::Color, example.tex, 0);
			bound_fbo.AttachRenderbuffer(FramebufferAttachment::Depth, rbo);
		}

		Use();
	}
Ejemplo n.º 6
0
	TorusExample(void)
	 : make_torus(1.0, 0.5, 36, 24)
	 , torus_instr(make_torus.Instructions())
	 , torus_indices(make_torus.Indices())
	 , prog(make_prog())
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	{
		Uniform<Vec4f>(prog, "ClipPlane").Set(0.f, 0.f, 1.f, 0.f);

		// bind the VAO for the torus
		torus.Bind();

		// bind the VBO for the torus vertices
		verts.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_torus.Positions(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the vertices
			VertexArrayAttrib attr(prog, "Position");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		// bind the VBO for the torus UV-coordinates
		texcoords.Bind(Buffer::Target::Array);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_torus.TexCoordinates(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the vertices
			VertexArrayAttrib attr(prog, "TexCoord");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}
		//
		gl.ClearColor(0.8f, 0.8f, 0.7f, 0.0f);
		gl.ClearDepth(1.0f);
		gl.FrontFace(make_torus.FaceWinding());
		gl.Enable(Capability::DepthTest);
		gl.Enable(Functionality::ClipDistance, 0);
	}
Ejemplo n.º 7
0
	FBTexExample(void)
	 : gl()
	 , vertex_shader(ObjectDesc("Vertex"))
	 , prog(make_prog())
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	 , cube(List("Position")("Normal")("TexCoord").Get(), shapes::Cube(), prog)
	 , width(800)
	 , height(600)
	{
		UniformSampler(prog, "TexUnit").Set(0);
		Uniform<Vec3f>(prog, "LightPos").Set(40.0f, 40.0f, -80.0f);

		Texture::Active(0);
		tex.Bind(Texture::Target::_2D);

		Use();
	}
Ejemplo n.º 8
0
	TriangleExample(void)
	 : gl()
	 , prog(make_prog())
	{
		triangle.Bind();
		GLfloat triangle_pos[9] = {
			-1.0f,-1.0f, 0.0f,
			 1.0f,-1.0f, 0.0f,
			-1.0f, 1.0f, 0.0f
		};

		positions.Bind(oglplus::Buffer::Target::Array);

		oglplus::Buffer::Data(
			oglplus::Buffer::Target::Array,
			triangle_pos
		);

		oglplus::VertexAttribArray(prog, "Position")
			.Setup<GLfloat>(3)
			.Enable();

		gl.ClearColor(1.0, 0.0, 1.0, 0.0);
	}
Ejemplo n.º 9
0
	ScreenProg(void)
	 : Program(make_prog())
	 , background(prog(), "Background")
	 , normal_map(prog(), "NormalMap")
	{ }
Ejemplo n.º 10
0
	ReflectionExample(void)
	 : make_cube(0.5,0.5,0.5, 0.1,0.1,0.1, 3,3,3)
	 , cube_indices(make_cube.Indices())
	 , cube_instr(make_cube.Instructions())
	 , prog(make_prog())
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	{
		gl.Use(prog);

		// bind the VAO for the cube
		gl.Bind(cube);

		// bind the VBO for the cube vertices
		gl.Bind(Buffer::Target::Array, cube_verts);
		{
			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
			VertexArrayAttrib attr(prog, "Position");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		// bind the VBO for the cube normals
		gl.Bind(Buffer::Target::Array, cube_normals);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Normals(data);
			// upload the data
			Buffer::Data(Buffer::Target::Array, data);
			// setup the vertex attribs array for the normals
			VertexArrayAttrib attr(prog, "Normal");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		// bind the VAO for the plane
		gl.Bind(plane);

		// bind the VBO for the plane vertices
		gl.Bind(Buffer::Target::Array, plane_verts);
		{
			GLfloat data[4*3] = {
				-2.0f, 0.0f,  2.0f,
				-2.0f, 0.0f, -2.0f,
				 2.0f, 0.0f,  2.0f,
				 2.0f, 0.0f, -2.0f
			};
			// upload the data
			Buffer::Data(Buffer::Target::Array, 4*3, data);
			// setup the vertex attribs array for the vertices
			prog.Use();
			VertexArrayAttrib attr(prog, "Position");
			attr.Setup<Vec3f>();
			attr.Enable();
		}

		// bind the VBO for the cube normals
		gl.Bind(Buffer::Target::Array, plane_normals);
		{
			GLfloat data[4*3] = {
				-0.1f, 1.0f,  0.1f,
				-0.1f, 1.0f, -0.1f,
				 0.1f, 1.0f,  0.1f,
				 0.1f, 1.0f, -0.1f
			};
			// upload the data
			Buffer::Data(Buffer::Target::Array, 4*3, data);
			// setup the vertex attribs array for the normals
			prog.Use();
			VertexArrayAttrib attr(prog, "Normal");
			attr.Setup<Vec3f>();
			attr.Enable();
		}
		gl.Bind(NoVertexArray());

		Uniform<Vec3f>(prog, "LightPos").Set(1.5, 2.0, 2.5);
		//
		gl.ClearColor(0.2f, 0.2f, 0.2f, 0.0f);
		gl.ClearDepth(1.0f);
		gl.ClearStencil(0);
	}
Ejemplo n.º 11
0
	CubeExample(void)
	 : cube_instr(make_cube.Instructions())
	 , cube_indices(make_cube.Indices())
	 , prog(make_prog())
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	{

		// bind the VAO for the cube
		gl.Bind(cube);

		gl.Bind(Buffer::Target::Array, verts);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Positions(data);
			Buffer::Data(Buffer::Target::Array, data);
			VertexArrayAttrib attr(prog, "Position");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		gl.Bind(Buffer::Target::Array, normals);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Normals(data);
			Buffer::Data(Buffer::Target::Array, data);
			VertexArrayAttrib attr(prog, "Normal");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		gl.Bind(Buffer::Target::Array, texcoords);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.TexCoordinates(data);
			Buffer::Data(Buffer::Target::Array, data);
			VertexArrayAttrib attr(prog, "TexCoord");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		// setup the texture
		gl.Bound(Texture::Target::_2D, tex)
			.Image2D(images::LoadTexture("honeycomb"))
			.GenerateMipmap()
			.MinFilter(TextureMinFilter::LinearMipmapLinear)
			.MagFilter(TextureMagFilter::Linear)
			.WrapS(TextureWrap::MirroredRepeat)
			.WrapT(TextureWrap::MirroredRepeat)
			.Anisotropy(2);
		//
		UniformSampler(prog, "TexUnit").Set(0);
		Uniform<Vec3f>(prog, "LightPos").Set(Vec3f(1.0f, 2.0f, 3.0f));
		//
		gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
		gl.ClearDepth(1.0f);
		gl.Enable(Capability::DepthTest);
		gl.Enable(Capability::Blend);
		gl.BlendFunc(
			BlendFn::SrcAlpha,
			BlendFn::OneMinusSrcAlpha
		);

		gl.Enable(Capability::CullFace);
		gl.FrontFace(make_cube.FaceWinding());
	}
Ejemplo n.º 12
0
	CubeExample(void)
	 : cube_instr(make_cube.Instructions())
	 , cube_indices(make_cube.Indices())
	 , prog(make_prog())
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	 , model_matrix(prog, "ModelMatrix")
	 , light_pos(prog, "LightPos")
	{
		gl.Bind(cube);

		gl.Bind(Buffer::Target::Array, verts);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Positions(data);
			gl.Current(Buffer::Target::Array).Data(data);
			VertexArrayAttrib attr(prog, "Position");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		gl.Bind(Buffer::Target::Array, normals);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Normals(data);
			gl.Current(Buffer::Target::Array).Data(data);
			VertexArrayAttrib attr(prog, "Normal");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		gl.Bind(Buffer::Target::Array, tangents);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.Tangents(data);
			gl.Current(Buffer::Target::Array).Data(data);
			VertexArrayAttrib attr(prog, "Tangent");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		gl.Bind(Buffer::Target::Array, texcoords);
		{
			std::vector<GLfloat> data;
			GLuint n_per_vertex = make_cube.TexCoordinates(data);
			gl.Current(Buffer::Target::Array).Data(data);
			VertexArrayAttrib attr(prog, "TexCoord");
			attr.Setup<GLfloat>(n_per_vertex);
			attr.Enable();
		}

		// setup the textures
		{
			Texture::Active(0);
			UniformSampler(prog, "ColorTex").Set(0);

			gl.Bind(Texture::Target::_2D, colorTex);
			gl.Current(Texture::Target::_2D)
				.MinFilter(TextureMinFilter::LinearMipmapLinear)
				.MagFilter(TextureMagFilter::Linear)
				.WrapS(TextureWrap::Repeat)
				.WrapT(TextureWrap::Repeat)
				.Image2D(images::LoadTexture("wooden_crate"))
				.GenerateMipmap();
		}
		{
			Texture::Active(1);
			UniformSampler(prog, "NormalTex").Set(1);

			gl.Bind(Texture::Target::_2D, normalTex);
			gl.Current(Texture::Target::_2D)
				.MinFilter(TextureMinFilter::LinearMipmapLinear)
				.MagFilter(TextureMagFilter::Linear)
				.WrapS(TextureWrap::Repeat)
				.WrapT(TextureWrap::Repeat)
				.Image2D(
					images::NormalMap(
						images::LoadTexture("wooden_crate-hmap")
					)
				).GenerateMipmap();
		}
		//
		gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
		gl.ClearDepth(1.0f);
		gl.Enable(Capability::DepthTest);

		gl.Enable(Capability::CullFace);
		gl.FrontFace(make_cube.FaceWinding());
	}