Beispiel #1
0
void end(void)
{
	SGE_ASSERT(details::g_window != NULL);
	SGE_ASSERT(details::g_gl_context != NULL);

	ImGui::Render();

	SDL_GL_MakeCurrent(details::g_window, details::g_gl_context);

	glViewport(0, 0, details::g_window_rect[2], details::g_window_rect[3]);
	glClear(GL_COLOR_BUFFER_BIT);

	s_program.Use();

	commit_uniforms();

	draw_test();

	ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
	ImGui::SetCurrentContext(NULL);

	SDL_GL_SwapWindow(details::g_window);
}
Beispiel #2
0
void Model::Render (GLuint pass, const gl::Program &program)
{
	GLuint result = GL_TRUE;
	GLuint passtype;

  if (!r->culling.IsVisible
			(bsphere.center, bsphere.radius))
		return;

	passtype = pass & Geometry::Pass::Mask;

	bool shadowpass = (passtype == Geometry::Pass::ShadowMap)
		 || (passtype == Geometry::Pass::ShadowMapTriangleTess)
		 || (passtype == Geometry::Pass::ShadowMapQuadTess);

	std::map<GLuint, gl::Query>::iterator query;
	switch (passtype)
	{
	case Geometry::Pass::GBuffer:
	case Geometry::Pass::GBufferTransparency:
		query = queries.find (pass);
		if (query == queries.end ())
		{
			auto ret = queries.insert (std::pair<GLuint, gl::Query>
																 (pass, gl::Query ()));
			if (ret.second == false)
				 throw std::runtime_error ("Cannot insert element to map.");
			query = ret.first;
		}

		if (query->second.IsValid ())
		{
			do
			{
				query->second.Get (GL_QUERY_RESULT_AVAILABLE, &result);
			} while (result == GL_FALSE);
			if (result == GL_TRUE)
			{
				query->second.Get (GL_QUERY_RESULT, &result);
			}
			else
			{
				(*logstream) << "Query result not yet available" << std::endl;
			}
		}

		query->second.Begin (GL_ANY_SAMPLES_PASSED);
		break;
	case Geometry::Pass::GBufferSRAA:
		GLuint p;
		p = (pass & (~Geometry::Pass::Mask)) | Geometry::Pass::GBuffer;
		query = queries.find (pass);
		if (query != queries.end ())
		{
			if (query->second.IsValid ())
			{
				query->second.Get (GL_QUERY_RESULT_AVAILABLE, &result);
				if (result == GL_TRUE)
				{
					query->second.Get (GL_QUERY_RESULT, &result);
				}
				else result = GL_TRUE;
			}
		}
		break;
	}

	if (result == GL_TRUE)
	{
		switch (passtype)
		{
		case Geometry::Pass::GBufferTriangleTess:
			for (Mesh &mesh : patches)
			{
				mesh.Render (program, false, false);
			}
			break;
		case Geometry::Pass::GBufferQuadTess:
			for (Mesh &mesh : patches)
			{
				mesh.Render (program, false, true);
			}
			break;
		case Geometry::Pass::ShadowMapTriangleTess:
			for (Mesh &mesh : patches)
			{
				if (mesh.CastsShadow ())
					 mesh.Render (program, false, false);
			}
			break;
		case Geometry::Pass::ShadowMapQuadTess:
			for (Mesh &mesh : patches)
			{
				if (mesh.CastsShadow ())
					 mesh.Render (program, false, true);
			}
			break;
		case Geometry::Pass::GBufferTransparency:
			for (Mesh &mesh : transparent)
			{
				mesh.Render (program, false);
			}
			break;
		case Geometry::Pass::ShadowMap:
			for (Mesh &mesh : transparent)
			{
				if (mesh.CastsShadow ())
					 mesh.Render (program, true);
			}
		case Geometry::Pass::GBuffer:
			for (Mesh &mesh : meshes)
			{
				mesh.Render (program, false);
			}
			break;
		case Geometry::Pass::GBufferSRAA:
			for (Mesh &mesh : meshes)
			{
				mesh.Render (program, true);
			}
			break;
		}
	}
	else if (passtype != Geometry::Pass::GBufferSRAA)
	{
		if (passtype != Geometry::Pass::GBufferTransparency)
		{
			gl::ColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
			gl::DepthMask (GL_FALSE);
		}
		r->geometry.bboxprogram.Use ();
		bbox.array.Bind ();
		bbox.indices.Bind (GL_ELEMENT_ARRAY_BUFFER);
		gl::DrawElements (GL_TRIANGLES, 36,
											GL_UNSIGNED_BYTE, NULL);
		program.Use ();
		if (passtype != Geometry::Pass::GBufferTransparency)
		{
			gl::DepthMask (GL_TRUE);
			gl::ColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
		}
		culled++;
	}
	switch (passtype)
	{
	case Geometry::Pass::GBuffer:
	case Geometry::Pass::GBufferTransparency:
		 gl::Query::End (GL_ANY_SAMPLES_PASSED);
		 break;
	}
}