当前位置: 首页>>代码示例>>C++>>正文


C++ ProgramObject类代码示例

本文整理汇总了C++中ProgramObject的典型用法代码示例。如果您正苦于以下问题:C++ ProgramObject类的具体用法?C++ ProgramObject怎么用?C++ ProgramObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ProgramObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawArraysInstanced

void VertexBuffer::DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
{
	ProgramObject *p = rc->GetCurProgram();
	if (p) p->updateMatrices();
	Bind();
	glDrawArraysInstanced(mode, first, count, instanceCount);
}
开发者ID:alexgaiv,项目名称:lib3d,代码行数:7,代码来源:vertexbuffer.cpp

示例2: cgGetProgramString

bool csShaderGLCGCommon::WriteToCache (iHierarchicalCache* cache,
                                       const ProfileLimits& limits,
                                       const ProfileLimitsPair& limitsPair, 
                                       const char* tag)
{
  csString objectCode;
  if (program != 0)
    objectCode = cgGetProgramString (program, CG_COMPILED_PROGRAM);
  ProgramObject programObj (objectCode,
    programPositionInvariant ? ProgramObject::flagPositionInvariant : 0,
    unusedParams);
  
  const char* preprocSource (cgGetProgramString (program, CG_PROGRAM_SOURCE));
  csString failReason;
  ProgramObjectID progId;
  if (!shaderPlug->progCache.WriteObject (preprocSource, limits, programObj,
    progId, failReason))
  {
    if (shaderPlug->doVerbose)
    {
      csReport (objectReg, CS_REPORTER_SEVERITY_WARNING, 
	"crystalspace.graphics3d.shader.glcg",
	"Error writing %s program for %s to compile cache: %s",
	GetProgramType(), tag,
	failReason.GetData());
    }
    return false;
  }
  
  programObj.SetID (progId);
  
  return WriteToCache (cache, limits, limitsPair, tag, programObj);
}
开发者ID:GameLemur,项目名称:Crystal-Space,代码行数:33,代码来源:glshader_cgcommon.cpp

示例3: DrawElementsInstanced

void VertexBuffer::DrawElementsInstanced(GLenum mode, GLsizei count,
	GLenum type, GLsizei instanceCount, int offset)
{
	ProgramObject *p = rc->GetCurProgram();
	if (p) p->updateMatrices();
	Bind();
	glDrawElementsInstanced(mode, count, type, (void *)offset, instanceCount);
}
开发者ID:alexgaiv,项目名称:lib3d,代码行数:8,代码来源:vertexbuffer.cpp

示例4: main

int main(int /*argc*/, char ** /*argv*/) {
  BaseApp app;
  ProgramObject program;

  auto mainWindow = app.getMainWindow();

  std::string prefix = app.getResourceDir() + "Shaders/Examples/e06_ModelLoader/";

  PerspectiveCamera cam;
  OrbitManipulator manipulator(&cam);
  manipulator.setupCallbacks(app);
  NodeShared root;

  GLuint query[2];

  
  app.addInitCallback([&]() {
    auto vs = compileShader(GL_VERTEX_SHADER, Loader::text(prefix + "phong.vert"));
    auto fs = compileShader(GL_FRAGMENT_SHADER, Loader::text(prefix + "phong.frag"));
    program = createProgram(vs, fs);

    root = Loader::scene(app.getResourceDir() + "Models/sponza/sponza.fbx");
    glCreateQueries(GL_TIMESTAMP, 2, query);
    SDL_GL_SetSwapInterval(0);
  });

  app.addResizeCallback([&](int w, int h) {
    glViewport(0, 0, w, h);
    cam.setAspect(float(w) / float(h));
  });

  app.addDrawCallback([&]() {


    glQueryCounter(query[0], GL_TIMESTAMP);
    glClearColor(0.2, 0.2, 0.2, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    //bunny

    program.use();
    program.setMatrix4fv("p", value_ptr(cam.getProjection()));
    program.setMatrix4fv("v", value_ptr(cam.getView()));

    drawNode(program, root);
    glQueryCounter(query[1], GL_TIMESTAMP);

    GLuint64 time1, time2;
    glGetQueryObjectui64v(query[0], GL_QUERY_RESULT, &time1);
    glGetQueryObjectui64v(query[1], GL_QUERY_RESULT, &time2);

    std::string s = "fps: " + std::to_string(1e9 / (time2 - time1)) + " (" + std::to_string(ImGui::GetIO().Framerate) + ")";
    label(s, 0, 0, 300, 100);
  });
  return app.run();
}
开发者ID:dormon,项目名称:FitGL,代码行数:56,代码来源:main.cpp

示例5: DrawElements

void VertexBuffer::DrawElements(GLenum mode, GLsizei count, GLenum type, int offset)
{
	ProgramObject *p = rc->GetCurProgram();
	if (p) p->updateMatrices();

	if (GLEW_ARB_vertex_buffer_object) {
		Bind();
		glDrawElements(mode, count, type, (void *)offset);
	}
	else {
		glDrawElements(mode, count, type, ptr->data + offset);
	}
}
开发者ID:alexgaiv,项目名称:lib3d,代码行数:13,代码来源:vertexbuffer.cpp

示例6:

	void GL3GraphicContextProvider::set_program_object(const ProgramObject &program)
	{
		OpenGL::set_active(this);
		if (glUseProgram == nullptr)
			return;

		if (program.is_null())
			glUseProgram(0);
		else
		{
			glUseProgram(program.get_handle());
		}
	}
开发者ID:keigen-shu,项目名称:ClanLib,代码行数:13,代码来源:gl3_graphic_context_provider.cpp

示例7: create_shader_program

ProgramObject HSV::create_shader_program(GraphicContext &gc)
{
	ProgramObject program = ProgramObject::load(gc, "Resources/vertex.glsl", "Resources/fragment.glsl");
	program.bind_attribute_location(0, "Position");
	program.bind_attribute_location(1, "TexCoord0");

	program.set_uniform_buffer_index("ProgramUniforms", 0);

	if (!program.link())
		throw Exception("Unable to link program");

	return program;
}
开发者ID:Zenol,项目名称:clanLib-3,代码行数:13,代码来源:hsv.cpp

示例8: Color3f

void CubeBlock::DrawWhiteBorders(GLRenderingContext *rc, bool whiteBorders)
{
	if (whiteBorders) {
		borderAmbient = Color3f(0.8f);
		borderDiffuse = Color3f(0.85f);
	}
	else {
		borderAmbient = Color3f(0.0f);
		borderDiffuse = Color3f(0.35f);
	}
	ProgramObject *p = rc->GetCurProgram();
	p->Uniform("BorderMaterial.ambient", 1, borderAmbient.data);
	p->Uniform("BorderMaterial.diffuse", 1, borderDiffuse.data);
}
开发者ID:alexgaiv,项目名称:cubex,代码行数:14,代码来源:cubeblock.cpp

示例9: draw_image

void App::draw_image(GraphicContext &gc, Texture &image, float xpos, float ypos, ProgramObject &program_object, Vec4f &draw_color_offset)
{
	program_object.set_uniform1i("SourceTexture", 0);
	program_object.set_uniform4f("color_offset", draw_color_offset);

	gc.set_texture(0, image);
	gc.set_program_object(program_object, cl_program_matrix_modelview_projection);

	draw_texture(gc, Rectf(xpos, ypos, Sizef(image.get_width(), image.get_height())), Colorf::white, Rectf(0.0f, 0.0f, 1.0f, 1.0f));

	gc.reset_program_object();
	gc.reset_texture(0);

}
开发者ID:,项目名称:,代码行数:14,代码来源:

示例10: ProgramObject

void GLRC_Text2DModule::Initialize(GLRenderingContext *rc)
{
	if (GLEW_ARB_shader_objects) {
		prog = new ProgramObject(rc);

		Shader vshader(GL_VERTEX_SHADER);
		Shader fshader(GL_FRAGMENT_SHADER);
		vshader.CompileSource(shaderSource[0]);
		fshader.CompileSource(shaderSource[1]);
		prog->AttachShader(vshader);
		prog->AttachShader(fshader);
		prog->Link();
		prog->Uniform("ColorMap", 0);
	}
	else prog = NULL;
}
开发者ID:alexgaiv,项目名称:cubex,代码行数:16,代码来源:text2d.cpp

示例11: impl

UniformBuffer::UniformBuffer(GraphicContext &gc, ProgramObject &program, const std::string &name, int num_blocks, BufferUsage usage)
    : impl(std::make_shared<UniformBuffer_Impl>())
{
    GraphicContextProvider *gc_provider = gc.get_provider();
    impl->provider = gc_provider->alloc_uniform_buffer();
    impl->provider->create(program.get_uniform_buffer_size(name) * num_blocks, usage);
}
开发者ID:doughdemon,项目名称:ClanLib,代码行数:7,代码来源:uniform_buffer.cpp

示例12: initSkinProgram

void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locations) {
    program.bind();
    locations.clusterMatrices = program.uniformLocation("clusterMatrices");
    locations.clusterIndices = program.attributeLocation("clusterIndices");
    locations.clusterWeights = program.attributeLocation("clusterWeights");
    locations.tangent = program.attributeLocation("tangent");
    program.setUniformValue("diffuseMap", 0);
    program.setUniformValue("normalMap", 1);
    program.release();
}
开发者ID:BogusCurry,项目名称:hifi,代码行数:10,代码来源:Model.cpp

示例13: createProgram

static ProgramObject* createProgram(const QString& name) {
    ProgramObject* program = new ProgramObject();
    program->addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/" + name + ".frag");
    program->link();
    
    program->bind();
    program->setUniformValue("originalTexture", 0);
    program->release();
    
    return program;
}
开发者ID:Bazm0,项目名称:hifi,代码行数:11,代码来源:GlowEffect.cpp

示例14: window

int App::start(const std::vector<std::string> &args)
{
	OpenGLWindowDescription description;
	description.set_title("UniformBlock Shader");
	//description.set_version(3, 1, false);
	description.set_size(Size(1024, 768), true);

	DisplayWindow window(description);
	InputDevice keyboard = window.get_ic().get_keyboard();
	GraphicContext gc = window.get_gc();

	Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	Slot slot_window_close = window.sig_window_close().connect(this, &App::window_close);

	// Load and link shaders
	ProgramObject shader = ProgramObject::load(gc, "Resources/vertex_shader.glsl", "Resources/fragment_shader.glsl");
	shader.bind_attribute_location(0, "Position");
	if (!shader.link())
		throw Exception("Unable to link shader program: Error:" + shader.get_info_log());

	int block_size = shader.get_uniform_block_size("TestBlock");
	const int num_blocks = 16;
	ProgramUniformBlock block(gc, block_size * num_blocks);

	std::vector<float> data_to_upload;
	data_to_upload.resize((num_blocks * block_size) / sizeof(float) );

	float test_colour = 1.0f;
	for (int cnt=0; cnt<num_blocks; cnt++)
	{

		int offset = cnt * block_size / sizeof(float) ;
		data_to_upload[offset + 0] = test_colour;
		data_to_upload[offset + 1] = 0.5f;
		data_to_upload[offset + 2] = 1.0f;
		test_colour -= 0.05f;
	}

	block.upload_data(0, &data_to_upload[0], block_size * num_blocks);

	quit = false;

	Font font(gc, "tahoma", 32);

	clan::ubyte64 startTime = System::get_time();



		//// Test code
		//GLuint uniform_index = -1;
		//const char *names[] = {"src_color"};

		//glGetUniformIndices(handle, 1, names, &uniform_index);
		//if (uniform_index >=0)
		//{
		//		GLint offset;
		//		GLint singleSize;
		//		GLint uniform_type;
		//		glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_TYPE, &uniform_type);
		//		glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_OFFSET, &offset);
		//		glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_SIZE, &singleSize);
		//		if ((uniform_type != GL_FLOAT_VEC3) || (offset !=0) || (singleSize != 1))
		//		{
		//			throw Exception("well it seems it does not work");
		//		}
		//}


	while (!quit)
	{
		gc.clear(Colorf(0.1f, 0.1f, 0.2f));
		OpenGL::check_error();


		for (int test_run_y=0; test_run_y < 16; test_run_y++)
		{
			shader.set_uniform_block("TestBlock", block, test_run_y*block_size);
			for (int test_run_x=0; test_run_x < 16; test_run_x++)
			{
				Vec2f positions[3];
				float size = 32.0f;
				positions[0].x = test_run_x * size;
				positions[0].y = test_run_y * size + size;
				positions[1].x = test_run_x * size + size;
				positions[1].y = test_run_y * size + size;
				positions[2].x = test_run_x * size + size;
				positions[2].y = test_run_y * size;

				PrimitivesArray prim_array(gc);
				prim_array.set_attributes(0, positions);
				gc.set_program_object(shader, cl_program_matrix_modelview_projection);
				gc.draw_primitives(cl_triangles, 3, prim_array);
				gc.reset_program_object();
			}
		}
		font.draw_text(gc, 32, 200, "Hello World");
		window.flip(1);

		KeepAlive::process();
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例15: getActivatedProgramWithTileData

    void ChunkRenderer::renderChunkGlobally(const Chunk& chunk, const RenderData& data){

        ProgramObject* programObject = getActivatedProgramWithTileData(
            _globalRenderingShaderProvider.get(),
            _globalProgramUniformHandler,
            chunk);
        if (programObject == nullptr) {
            return;
        }

        const Ellipsoid& ellipsoid = chunk.owner()->ellipsoid();

        bool performAnyBlending = false;
        
        for (int i = 0; i < LayeredTextures::NUM_TEXTURE_CATEGORIES; ++i) {
            LayeredTextures::TextureCategory category = (LayeredTextures::TextureCategory)i;
            if(_tileProviderManager->getTileProviderGroup(i).levelBlendingEnabled && _tileProviderManager->getTileProviderGroup(category).getActiveTileProviders().size() > 0){
                performAnyBlending = true; 
                break;
            }
        }
        if (performAnyBlending) {
            // Calculations are done in the reference frame of the globe. Hence, the camera
            // position needs to be transformed with the inverse model matrix
            glm::dmat4 inverseModelTransform = chunk.owner()->inverseModelTransform();
            glm::dvec3 cameraPosition =
                glm::dvec3(inverseModelTransform * glm::dvec4(data.camera.positionVec3(), 1));
            float distanceScaleFactor = chunk.owner()->lodScaleFactor * ellipsoid.minimumRadius();
            programObject->setUniform("cameraPosition", vec3(cameraPosition));
            programObject->setUniform("distanceScaleFactor", distanceScaleFactor);
            programObject->setUniform("chunkLevel", chunk.index().level);
        }
        
        // Calculate other uniform variables needed for rendering
        Geodetic2 swCorner = chunk.surfacePatch().getCorner(Quad::SOUTH_WEST);
        auto patchSize = chunk.surfacePatch().size();
        
        dmat4 modelTransform = chunk.owner()->modelTransform();
        dmat4 viewTransform = data.camera.combinedViewMatrix();
        mat4 modelViewTransform = mat4(viewTransform * modelTransform);
        mat4 modelViewProjectionTransform = data.camera.projectionMatrix() * modelViewTransform;

        // Upload the uniform variables
        programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform);
        programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2()));
        programObject->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2()));
        programObject->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared()));

        if (_tileProviderManager->getTileProviderGroup(
                LayeredTextures::NightTextures).getActiveTileProviders().size() > 0 ||
            _tileProviderManager->getTileProviderGroup(
                LayeredTextures::WaterMasks).getActiveTileProviders().size() > 0) {
            glm::vec3 directionToSunWorldSpace =
                glm::normalize(-data.modelTransform.translation);
            glm::vec3 directionToSunCameraSpace =
                (viewTransform * glm::dvec4(directionToSunWorldSpace, 0));
            data.modelTransform.translation;
            programObject->setUniform("modelViewTransform", modelViewTransform);
            programObject->setUniform("lightDirectionCameraSpace", -directionToSunCameraSpace);
        }

        // OpenGL rendering settings
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);
        glCullFace(GL_BACK);

        // render
        _grid->geometry().drawUsingActiveProgram();

        // disable shader
        programObject->deactivate();
    }
开发者ID:OpenSpace,项目名称:OpenSpace,代码行数:72,代码来源:chunkrenderer.cpp


注:本文中的ProgramObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。