Esempio n. 1
0
    void init()
    {
        render_begin();

        // enable_gl_synchronuous_debug()
        std::string shader_path = INSTALL_PREFIX "/share/wayfire/shaders";
        program.id = create_program(
            shader_path + "/vertex.glsl", shader_path + "/frag.glsl");

        program.mvpID      = GL_CALL(glGetUniformLocation(program.id, "MVP"));
        program.colorID    = GL_CALL(glGetUniformLocation(program.id, "color"));
        program.position   = GL_CALL(glGetAttribLocation(program.id, "position"));
        program.uvPosition = GL_CALL(glGetAttribLocation(program.id, "uvPosition"));

        render_end();
    }
Esempio n. 2
0
static void render_display(struct obs_display *display)
{
	size_t i;
	render_begin(display);

	for (i = 0; i < MAX_CHANNELS; i++) {
		struct obs_source **p_source;

		p_source = (display) ? display->channels+i :
		                       obs->data.channels+i;

		if (*p_source) {
			if ((*p_source)->removed) {
				obs_source_release(*p_source);
				*p_source = NULL;
			} else {
				obs_source_video_render(*p_source);
			}
		}
	}

	render_end(display);
}
Esempio n. 3
0
void render(void)
{
	render_begin();

	const PfxVector3 colorWhite(1.0f);
	const PfxVector3 colorGray(0.7f);

	for(int i=0;i<physics_get_num_rigidbodies();i++) {
		const PfxRigidState &state = physics_get_state(i);
		const PfxCollidable &coll = physics_get_collidable(i);

		PfxVector3 color = state.isAsleep()?colorGray:colorWhite;

		PfxTransform3 rbT(state.getOrientation(), state.getPosition());

		PfxShapeIterator itrShape(coll);
		for(PfxUInt32 j=0;j<coll.getNumShapes();j++,++itrShape) {
			const PfxShape &shape = *itrShape;
			PfxTransform3 offsetT = shape.getOffsetTransform();
			PfxTransform3 worldT = rbT * offsetT;

			switch(shape.getType()) {
				case kPfxShapeSphere:
				render_sphere(
					worldT,
					color,
					PfxFloatInVec(shape.getSphere().m_radius));
				break;

				case kPfxShapeBox:
				render_box(
					worldT,
					color,
					shape.getBox().m_half);
				break;

				case kPfxShapeCapsule:
				render_capsule(
					worldT,
					color,
					PfxFloatInVec(shape.getCapsule().m_radius),
					PfxFloatInVec(shape.getCapsule().m_halfLen));
				break;

				case kPfxShapeCylinder:
				render_cylinder(
					worldT,
					color,
					PfxFloatInVec(shape.getCylinder().m_radius),
					PfxFloatInVec(shape.getCylinder().m_halfLen));
				break;

				case kPfxShapeConvexMesh:
				render_mesh(
					worldT,
					color,
					convexMeshId);
				break;

				case kPfxShapeLargeTriMesh:
				render_mesh(
					worldT,
					color,
					landscapeMeshId);
				break;

				default:
				break;
			}
		}
	}

	render_debug_begin();
	
	#ifdef ENABLE_DEBUG_DRAW_CONTACT
	for(int i=0;i<physics_get_num_contacts();i++) {
		const PfxContactManifold &contact = physics_get_contact(i);
		const PfxRigidState &stateA = physics_get_state(contact.getRigidBodyIdA());
		const PfxRigidState &stateB = physics_get_state(contact.getRigidBodyIdB());

		for(int j=0;j<contact.getNumContacts();j++) {
			const PfxContactPoint &cp = contact.getContactPoint(j);
			PfxVector3 pA = stateA.getPosition()+rotate(stateA.getOrientation(),pfxReadVector3(cp.m_localPointA));

			const float w = 0.05f;

			render_debug_line(pA+PfxVector3(-w,0.0f,0.0f),pA+PfxVector3(w,0.0f,0.0f),PfxVector3(0,0,1));
			render_debug_line(pA+PfxVector3(0.0f,-w,0.0f),pA+PfxVector3(0.0f,w,0.0f),PfxVector3(0,0,1));
			render_debug_line(pA+PfxVector3(0.0f,0.0f,-w),pA+PfxVector3(0.0f,0.0f,w),PfxVector3(0,0,1));
		}
	}
	#endif
	
	#ifdef ENABLE_DEBUG_DRAW_AABB
	for(int i=0;i<physics_get_num_rigidbodies();i++) {
		const PfxRigidState &state = physics_get_state(i);
		const PfxCollidable &coll = physics_get_collidable(i);

		PfxVector3 center = state.getPosition() + coll.getCenter();
		PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
		
		render_debug_box(center,half,PfxVector3(1,0,0));
	}
	#endif

	#ifdef ENABLE_DEBUG_DRAW_ISLAND
	const PfxIsland *island = physics_get_islands();
	if(island) {
		for(PfxUInt32 i=0;i<pfxGetNumIslands(island);i++) {
			PfxIslandUnit *islandUnit = pfxGetFirstUnitInIsland(island,i);
			PfxVector3 aabbMin(SCE_PFX_FLT_MAX);
			PfxVector3 aabbMax(-SCE_PFX_FLT_MAX);
			for(;islandUnit!=NULL;islandUnit=pfxGetNextUnitInIsland(islandUnit)) {
				const PfxRigidState &state = physics_get_state(pfxGetUnitId(islandUnit));
				const PfxCollidable &coll = physics_get_collidable(pfxGetUnitId(islandUnit));
				PfxVector3 center = state.getPosition() + coll.getCenter();
				PfxVector3 half = absPerElem(PfxMatrix3(state.getOrientation())) * coll.getHalf();
				aabbMin = minPerElem(aabbMin,center-half);
				aabbMax = maxPerElem(aabbMax,center+half);
			}
			render_debug_box((aabbMax+aabbMin)*0.5f,(aabbMax-aabbMin)*0.5f,PfxVector3(0,1,0));
		}
	}
	#endif
	
	for(int i=0;i<physics_get_num_rays();i++) {
		const PfxRayInput& rayInput = physics_get_rayinput(i);
		const PfxRayOutput& rayOutput = physics_get_rayoutput(i);
		if(rayOutput.m_contactFlag) {
			render_debug_line(
				rayInput.m_startPosition,
				rayOutput.m_contactPoint,
				PfxVector3(1.0f,0.0f,1.0f));
			render_debug_line(
				rayOutput.m_contactPoint,
				rayOutput.m_contactPoint+rayOutput.m_contactNormal,
				PfxVector3(1.0f,0.0f,1.0f));
		}
		else {
			render_debug_line(rayInput.m_startPosition,
				rayInput.m_startPosition+rayInput.m_direction,
				PfxVector3(0.5f,0.0f,0.5f));
		}
	}

	extern bool doAreaRaycast;
	extern PfxVector3 areaCenter;
	extern PfxVector3 areaExtent;

	if(doAreaRaycast) {
		render_debug_box(areaCenter,areaExtent,PfxVector3(0,0,1));
	}

	render_debug_end();

	render_end();
}
Esempio n. 4
0
void render(void)
{
	render_begin();
	
	for(int i=0;i<physics_get_num_rigidbodies();i++) {
		const PfxRigidState &state = physics_get_state(i);
		const PfxCollidable &coll = physics_get_collidable(i);

		PfxTransform3 rbT(state.getOrientation(), state.getPosition());

		PfxShapeIterator itrShape(coll);
		for(int j=0;j<coll.getNumShapes();j++,++itrShape) {
			const PfxShape &shape = *itrShape;
			PfxTransform3 offsetT = shape.getOffsetTransform();
			PfxTransform3 worldT = rbT * offsetT;

			switch(shape.getType()) {
				case kPfxShapeSphere:
				render_sphere(
					worldT,
					PfxVector3(1,1,1),
					PfxFloatInVec(shape.getSphere().m_radius));
				break;

				case kPfxShapeBox:
				render_box(
					worldT,
					PfxVector3(1,1,1),
					shape.getBox().m_half);
				break;

				case kPfxShapeCapsule:
				render_capsule(
					worldT,
					PfxVector3(1,1,1),
					PfxFloatInVec(shape.getCapsule().m_radius),
					PfxFloatInVec(shape.getCapsule().m_halfLen));
				break;

				case kPfxShapeCylinder:
				render_cylinder(
					worldT,
					PfxVector3(1,1,1),
					PfxFloatInVec(shape.getCylinder().m_radius),
					PfxFloatInVec(shape.getCylinder().m_halfLen));
				break;

				case kPfxShapeConvexMesh:
				render_mesh(
					worldT,
					PfxVector3(1,1,1),
					convexMeshId);
				break;

				case kPfxShapeLargeTriMesh:
				render_mesh(
					worldT,
					PfxVector3(1,1,1),
					landscapeMeshId);
				break;

				default:
				break;
			}
		}
	}

	render_end();
}
Esempio n. 5
0
 void render_begin(const wf_framebuffer_base& fb)
 {
     render_begin(fb.viewport_width, fb.viewport_height, fb.fb);
 }
Esempio n. 6
0
 void render_begin()
 {
     /* No real reason for 10, 10, 0 but it doesn't matter */
     render_begin(10, 10, 0);
 }
Esempio n. 7
0
 void fini()
 {
     render_begin();
     GL_CALL(glDeleteProgram(program.id));
     render_end();
 }
int AppleseedRenderer::Render(
    TimeValue               time,
    Bitmap*                 bitmap,
    FrameRendParams&        frame_rend_params,
    HWND                    hwnd,
    RendProgressCallback*   progress_cb,
    ViewParams*             view_params)
{
    SuspendAll suspend(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

    m_time = time;

    if (view_params)
        m_view_params = *view_params;

    if (m_view_node)
        get_view_params_from_view_node(m_view_params, m_view_node, time);

    // Retrieve and tweak renderer settings.
    RendererSettings renderer_settings = m_settings;
    if (m_rend_params.inMtlEdit)
    {
        renderer_settings.m_pixel_samples = m_rend_params.mtlEditAA ? 32 : 4;
        renderer_settings.m_passes = 1;
        renderer_settings.m_gi = true;
        renderer_settings.m_background_emits_light = false;
    }

    // Collect the entities we're interested in.
    if (progress_cb)
        progress_cb->SetTitle(_T("Collecting Entities..."));
    m_entities.clear();
    MaxSceneEntityCollector collector(m_entities);
    collector.collect(m_scene);

    // Call RenderBegin() on all object instances.
    render_begin(m_entities.m_objects, m_time);

    // Build the project.
    if (progress_cb)
        progress_cb->SetTitle(_T("Building Project..."));
    asf::auto_release_ptr<asr::Project> project(
        build_project(
            m_entities,
            m_default_lights,
            m_view_params,
            m_rend_params,
            frame_rend_params,
            renderer_settings,
            bitmap,
            time));

    if (m_rend_params.inMtlEdit)
    {
        // Write the project to disk, useful to debug material previews.
        // asr::ProjectFileWriter::write(project.ref(), "MaterialEditor.appleseed");

        // Render the project.
        if (progress_cb)
            progress_cb->SetTitle(_T("Rendering..."));
        render(project.ref(), m_settings, bitmap, progress_cb);
    }
    else
    {
        // Write the project to disk.
        if (m_settings.m_output_mode == RendererSettings::OutputMode::SaveProjectOnly ||
            m_settings.m_output_mode == RendererSettings::OutputMode::SaveProjectAndRender)
        {
            if (progress_cb)
                progress_cb->SetTitle(_T("Writing Project To Disk..."));
            asr::ProjectFileWriter::write(
                project.ref(),
                wide_to_utf8(m_settings.m_project_file_path).c_str());
        }

        // Render the project.
        if (m_settings.m_output_mode == RendererSettings::OutputMode::RenderOnly ||
            m_settings.m_output_mode == RendererSettings::OutputMode::SaveProjectAndRender)
        {
            if (progress_cb)
                progress_cb->SetTitle(_T("Rendering..."));
            if (m_settings.m_low_priority_mode)
            {
                asf::ProcessPriorityContext background_context(
                    asf::ProcessPriority::ProcessPriorityLow,
                    &asr::global_logger());
                render(project.ref(), m_settings, bitmap, progress_cb);
            }
            else
            {
                render(project.ref(), m_settings, bitmap, progress_cb);
            }
        }
    }

    if (progress_cb)
        progress_cb->SetTitle(_T("Done."));

    // Success.
    return 1;
}