예제 #1
0
파일: ViewObject.cpp 프로젝트: mariuz/haiku
/*	FUNCTION:		ViewObject :: DragDrop
	ARGUMENTS:		none
	RETURN:			n/a
	DESCRIPTION:	Hook function called when user drops files in application window.
					Essentially, determine if file is image or video.	
*/
void ViewObject :: DragDrop(entry_ref *ref, float mouse_x, float mouse_y)
{
	//	Image file?
	BPath path(ref);
	BBitmap *bitmap = BTranslationUtils::GetBitmap(path.Path(), NULL);
	if (bitmap)
	{
		MediaSource *media = new MediaSource(this);
		GLCreateTexture(media, bitmap);
		if (!SurfaceUpdate(media, mouse_x, mouse_y))
			delete media;
		delete bitmap;
		return;
	}
	
	//	Video file
	Video *video = new Video(ref);
	if (video->GetStatus() == B_OK)
	{
		MediaSource *media = new MediaSource(this);
		GLCreateTexture(media, video->GetBitmap());
		media->SetVideo(video);
		if (SurfaceUpdate(media, mouse_x, mouse_y))
			video->Start();
		else
			delete media;
		return;
	}
	else
		delete video;
	
	printf("Unsupported file\n");
}
예제 #2
0
bool InitScene()
{
	SetWindowText(hwnd, TITLE);
	Quadron::qGLExtensions::QueryFeatures();

	isGL4_4 = (Quadron::qGLExtensions::GLVersion >= Quadron::qGLExtensions::GL_4_4);

	// setup opengl
	glClearColor(0.0f, 0.125f, 0.3f, 1.0f);
	glClearDepth(1.0);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

	if( !GLCreateMeshFromQM("../media/meshes/teapot.qm", &mesh) )
	{
		MYERROR("Could not load mesh");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/blinnphong.vert", 0, "../media/shadersGL/blinnphong.frag", &effect1) )
	{
		MYERROR("Could not load 'blinnphong' effect");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/uniformbuffer.vert", 0, "../media/shadersGL/uniformbuffer.frag", &effect2) )
	{
		MYERROR("Could not load 'uniformbuffer' effect");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/basic2D.vert", 0, "../media/shadersGL/basic2D.frag", &basic2D) )
	{
		MYERROR("Could not load 'basic2D' shader");
		return false;
	}

	// create framebuffer
	framebuffer = new OpenGLFramebuffer(screenwidth, screenheight);

	framebuffer->AttachTexture(GL_COLOR_ATTACHMENT0, GLFMT_A8B8G8R8, GL_NEAREST);
	framebuffer->AttachRenderbuffer(GL_DEPTH_STENCIL_ATTACHMENT, GLFMT_D24S8);

	if( !framebuffer->Validate() )
	{
		MYERROR("Framebuffer validation failed");
		return false;
	}

	// create uniform buffer
	effect2->SetUniformBlockBinding("VertexUniformData", 0);
	effect2->SetUniformBlockBinding("FragmentUniformData", 1);

	// simple uniform buffer
	glGenBuffers(1, &uniformbuffer1);
	glBindBuffer(GL_UNIFORM_BUFFER, uniformbuffer1);

	glBufferData(GL_UNIFORM_BUFFER, sizeof(EffectUniformBlock), NULL, GL_DYNAMIC_DRAW);
	glBindBuffer(GL_UNIFORM_BUFFER, 0);

	// uniform ringbuffer
	glGenBuffers(1, &uniformbuffer2);
	glBindBuffer(GL_UNIFORM_BUFFER, uniformbuffer2);

	glBufferData(GL_UNIFORM_BUFFER, UNIFORM_COPIES * sizeof(EffectUniformBlock), NULL, GL_DYNAMIC_DRAW);
	glBindBuffer(GL_UNIFORM_BUFFER, 0);

	if( isGL4_4 ) {
		// uniform storage buffer
		glGenBuffers(1, &uniformbuffer3);
		glBindBuffer(GL_UNIFORM_BUFFER, uniformbuffer3);

		glBufferStorage(GL_UNIFORM_BUFFER, UNIFORM_COPIES * sizeof(EffectUniformBlock), NULL, GL_DYNAMIC_STORAGE_BIT|GL_MAP_WRITE_BIT|GL_MAP_PERSISTENT_BIT|GL_MAP_COHERENT_BIT);
		glBindBuffer(GL_UNIFORM_BUFFER, 0);
	}

	memset(&uniformDTO, 0, sizeof(uniformDTO));

	// render text
	GLCreateTexture(512, 512, 1, GLFMT_A8B8G8R8, &text1);

	if( isGL4_4 ) {
		glBindBuffer(GL_UNIFORM_BUFFER, uniformbuffer3);
		persistentdata = (EffectUniformBlock*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, UNIFORM_COPIES * sizeof(EffectUniformBlock), GL_MAP_WRITE_BIT|GL_MAP_PERSISTENT_BIT|GL_MAP_COHERENT_BIT);
		glBindBuffer(GL_UNIFORM_BUFFER, 0);

		assert(persistentdata != 0);

		GLRenderText(
			"1 - glUniformXX\n2 - UBO with glBufferSubData\n3 - UBO with glMapBufferRange\n4 - UBO with glFenceSync\n5 - UBO with persistent mapping",
			text1, 512, 512);
	} else {
		GLRenderText(
			"1 - glUniformXX\n2 - UBO with glBufferSubData\n3 - UBO with glMapBufferRange\n4 - UBO with glFenceSync",
			text1, 512, 512);
	}

	screenquad = new OpenGLScreenQuad();

	// setup cameras
	basiccamera.SetAspect((float)screenwidth / screenheight);
	basiccamera.SetFov(GLDegreesToRadians(80));
	basiccamera.SetClipPlanes(0.1f, 30.0f);
	basiccamera.SetDistance(10.0f);

	return true;
}
예제 #3
0
bool InitScene()
{
	SetWindowText(hwnd, TITLE);
	Quadron::qGLExtensions::QueryFeatures();

	//CalculateSphereTetrahedron(4, 0.5f);

	// setup opengl
	glClearColor(0, 0, 0, 1);
	glClearDepth(1.0);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);

	// create render targets for reference
	rendertargets[0] = new OpenGLFramebuffer(screenwidth, screenheight);
	rendertargets[1] = new OpenGLFramebuffer(screenwidth, screenheight);

	rendertargets[0]->AttachTexture(GL_COLOR_ATTACHMENT0, GLFMT_A32B32G32R32F, GL_NEAREST);
	rendertargets[1]->AttachTexture(GL_COLOR_ATTACHMENT0, GLFMT_A32B32G32R32F, GL_NEAREST);

	GL_ASSERT(rendertargets[0]->Validate());
	GL_ASSERT(rendertargets[1]->Validate());

	GLint value = 0;
	float white[] = { 1, 1, 1, 1 };

	gbuffer = new OpenGLFramebuffer(screenwidth, screenheight);

	gbuffer->AttachTexture(GL_COLOR_ATTACHMENT0, GLFMT_A8B8G8R8_sRGB, GL_NEAREST);	// color
	gbuffer->AttachTexture(GL_COLOR_ATTACHMENT1, GLFMT_A16B16G16R16F, GL_NEAREST);	// normals
	gbuffer->AttachTexture(GL_COLOR_ATTACHMENT2, GLFMT_R32F, GL_NEAREST);			// depth
	gbuffer->AttachTexture(GL_COLOR_ATTACHMENT3, GLFMT_G16R16F, GL_NEAREST);		// velocity

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
	glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, white);

	gbuffer->AttachRenderbuffer(GL_DEPTH_STENCIL_ATTACHMENT, GLFMT_D24S8);
	GL_ASSERT(gbuffer->Validate());

	glBindFramebuffer(GL_FRAMEBUFFER, gbuffer->GetFramebuffer());
	{
		glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &value);
		GL_ASSERT(value == GL_SRGB);

		glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &value);
		GL_ASSERT(value == GL_LINEAR);

		glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &value);
		GL_ASSERT(value == GL_LINEAR);
	}
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// load shaders
	if( !GLCreateEffectFromFile("../media/shadersGL/AOpathtracer.vert", 0, "../media/shadersGL/AOpathtracer.frag", &pathtracer) )
	{
		MYERROR("Could not load 'path tracer' shader");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/AOpathtracer.vert", 0, "../media/shadersGL/AOpathtracer.frag", &refgbuffereffect, "#define RENDER_GBUFFER\n") )
	{
		MYERROR("Could not load 'gbuffer' shader");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/basic2D.vert", 0, "../media/shadersGL/gtao.frag", &refgtaoeffect, "#define NUM_DIRECTIONS 32\n#define NUM_STEPS 16\n") )
	{
		MYERROR("Could not load 'GTAO' shader");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/basic2D.vert", 0, "../media/shadersGL/gtaocombine.frag", &combineeffect) )
	{
		MYERROR("Could not load 'combine' shader");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/basic2D.vert", 0, "../media/shadersGL/basic2D.frag", &presenteffect) )
	{
		MYERROR("Could not load 'basic2D' shader");
		return false;
	}

	float id[16];
	GLMatrixIdentity(id);

	presenteffect->SetMatrix("matTexture", id);
	refgtaoeffect->SetMatrix("matTexture", id);

	combineeffect->SetInt("sampler0", 0);
	combineeffect->SetInt("sampler1", 1);

	refgtaoeffect->SetInt("gbufferDepth", 0);
	refgtaoeffect->SetInt("gbufferNormals", 1);
	refgtaoeffect->SetInt("noise", 2);

	screenquad = new OpenGLScreenQuad();

	// render text
	GLCreateTexture(512, 512, 1, GLFMT_A8B8G8R8, &text1);

	GLRenderText(
		"Use the mouse to rotate camera\n\nP - Toggle path tracer\nH - Toggle help text",
		text1, 512, 512);

	// setup camera
	orbitcamera.SetAspect((float)screenwidth / (float)screenheight);
	orbitcamera.SetFov(GL_PI / 4.0f);
	orbitcamera.SetPosition(0, 1.633f, 0);
	orbitcamera.SetOrientation(GLDegreesToRadians(135), GLDegreesToRadians(30), 0);
	orbitcamera.SetDistance(6);
	orbitcamera.SetClipPlanes(0.1f, 20);

	return true;
}
예제 #4
0
bool InitScene()
{
	SurfaceVertex*	svdata = 0;
	float			(*vdata)[4] = 0;
	GLushort*		idata = 0;
	GLuint*			idata32 = 0;

	OpenGLVertexElement decl[] =
	{
		{ 0, 0, GLDECLTYPE_FLOAT4, GLDECLUSAGE_POSITION, 0 },
		{ 0xff, 0, 0, 0, 0 }
	};

	OpenGLVertexElement decl2[] =
	{
		{ 0, 0, GLDECLTYPE_FLOAT4, GLDECLUSAGE_POSITION, 0 },
		{ 0, 16, GLDECLTYPE_FLOAT4, GLDECLUSAGE_NORMAL, 0 },
		{ 0xff, 0, 0, 0, 0 }
	};

	SetWindowText(hwnd, TITLE);
	Quadron::qGLExtensions::QueryFeatures(hdc);

	// calculate viewport sizes
	long maxw = screenwidth - 350; // assume 320x240 first
	long maxh = screenheight - 130 - 10; // text is fix
	
	splinevpsize = GLMin<long>(maxw, maxh);
	splinevpsize -= (splinevpsize % 10);

	surfvpwidth = screenwidth - splinevpsize - 30;
	surfvpheight = (surfvpwidth * 3) / 4;

	if( !Quadron::qGLExtensions::ARB_geometry_shader4 )
		return false;

	hascompute = Quadron::qGLExtensions::ARB_compute_shader;

#ifdef _DEBUG
	if( Quadron::qGLExtensions::ARB_debug_output )
	{
		glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE);
		glDebugMessageCallback(ReportGLError, 0);
	}
#endif

	glClearColor(0.0f, 0.125f, 0.3f, 1.0f);
	glClearDepth(1.0);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);

	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);

	// create grid & control poly
	if( !GLCreateMesh(44 + numcontrolvertices, numcontrolindices, GLMESH_DYNAMIC, decl, &supportlines) )
	{
		MYERROR("Could not create mesh");
		return false;
	}

	supportlines->LockVertexBuffer(0, 0, GLLOCK_DISCARD, (void**)&vdata);
	supportlines->LockIndexBuffer(0, 0, GLLOCK_DISCARD, (void**)&idata);

	// grid points
	for( GLuint i = 0; i < 22; i += 2 )
	{
		vdata[i][0] = vdata[i + 1][0] = (float)(i / 2);
		vdata[i][2] = vdata[i + 1][2] = 0;
		vdata[i][3] = vdata[i + 1][3] = 1;

		vdata[i][1] = 0;
		vdata[i + 1][1] = 10;

		vdata[i + 22][1] = vdata[i + 23][1] = (float)(i / 2);
		vdata[i + 22][2] = vdata[i + 23][2] = 0;
		vdata[i + 22][3] = vdata[i + 23][3] = 1;

		vdata[i + 22][0] = 0;
		vdata[i + 23][0] = 10;
	}

	// curve indices
	for( GLuint i = 0; i < numcontrolindices; i += 2 )
	{
		idata[i] = 44 + i / 2;
		idata[i + 1] = 44 + i / 2 + 1;
	}

	supportlines->UnlockIndexBuffer();
	supportlines->UnlockVertexBuffer();

	OpenGLAttributeRange table[] =
	{
		{ GLPT_LINELIST, 0, 0, 0, 0, 44 },
		{ GLPT_LINELIST, 1, 0, numcontrolindices, 44, numcontrolvertices }
	};

	supportlines->SetAttributeTable(table, 2);

	// create spline mesh
	if( !GLCreateMesh(maxsplinevertices, maxsplineindices, GLMESH_32BIT, decl, &curve) )
	{
		MYERROR("Could not create curve");
		return false;
	}

	OpenGLAttributeRange* subset0 = curve->GetAttributeTable();

	subset0->PrimitiveType = GLPT_LINELIST;
	subset0->IndexCount = 0;

	// create surface
	if( !GLCreateMesh(maxsurfacevertices, maxsurfaceindices, GLMESH_32BIT, decl2, &surface) )
	{
		MYERROR("Could not create surface");
		return false;
	}

	// load effects
	if( !GLCreateEffectFromFile("../media/shadersGL/color.vert", "../media/shadersGL/renderpoints.geom", "../media/shadersGL/color.frag", &renderpoints) )
	{
		MYERROR("Could not load point renderer shader");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/color.vert", "../media/shadersGL/renderlines.geom", "../media/shadersGL/color.frag", &renderlines) )
	{
		MYERROR("Could not load line renderer shader");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/rendersurface.vert", 0, "../media/shadersGL/rendersurface.frag", &rendersurface) )
	{
		MYERROR("Could not load surface renderer shader");
		return false;
	}

	if( !GLCreateEffectFromFile("../media/shadersGL/basic2D.vert", 0, "../media/shadersGL/basic2D.frag", &basic2D) )
	{
		MYERROR("Could not load basic 2D shader");
		return false;
	}

	if( hascompute )
	{
		if( !GLCreateComputeProgramFromFile("../media/shadersGL/tessellatecurve.comp", &tessellatecurve) )
		{
			MYERROR("Could not load compute shader");
			return false;
		}

		if( !GLCreateComputeProgramFromFile("../media/shadersGL/tessellatesurface.comp", &tessellatesurface) )
		{
			MYERROR("Could not load compute shader");
			return false;
		}
	}

	screenquad = new OpenGLScreenQuad();

	// tessellate for the first time
	ChangeCurve(0);
	Tessellate();

	// text
	GLCreateTexture(800, 130, 1, GLFMT_A8R8G8B8, &text1);
	UpdateText();

	float angles[2] = { M_PI / 2, 0.5f };
	cameraangle = angles;

	return true;
}