コード例 #1
0
ファイル: graphics_gl2.cpp プロジェクト: gunchleoc/vdrift
bool GRAPHICS_GL2::ReloadShaders(
	const std::string & shaderpath,
	std::ostream & info_output,
	std::ostream & error_output)
{
	EnableShaders(shaderpath, info_output, error_output);

	return GetUsingShaders();
}
コード例 #2
0
void OpenGLEngine::Draw (std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer, std::shared_ptr<VisualEffect> visualEffect)
{
	std::shared_ptr<Program> program = visualEffect->GetProgram ();
	std::string programName = program->GetProgramName ();

	OGLProgram* oglProgram = dynamic_cast<OGLProgram*> (program.get());

	if (oglProgram)
	{
		GLuint programHandle = oglProgram->GetProgramHandle ();
		glUseProgram (programHandle);
	
		if (EnableShaders (visualEffect, programHandle))
		{
			std::shared_ptr<OGLVertexBuffer> oglVertexBuffer = nullptr;
			std::shared_ptr<OGLIndexBuffer> oglIndexBuffer = nullptr;
			OGLVertexArrayObject* vao = nullptr;

			m_MapCO.Get (std::make_pair (vertexBuffer.get(), indexBuffer.get ()), vao);
			if (vao)
			{
				vao->Enable ();
			}
			else
			{

				if (vertexBuffer)
				{
					oglVertexBuffer = std::static_pointer_cast<OGLVertexBuffer> (Bind (vertexBuffer));
				}

				if (indexBuffer)
				{
					oglIndexBuffer = std::static_pointer_cast<OGLIndexBuffer> (Bind(indexBuffer));
				}

				vao = static_cast<OGLVertexArrayObject*> (Bind (oglVertexBuffer, oglIndexBuffer));

			}

			DrawPrimitive (vertexBuffer.get (), indexBuffer.get ());

			vao->Disable ();

			DisableShaders (visualEffect, programHandle);
		}
		else
		{
			fprintf (stderr, "The draw method in OpenGLEngine failed, because the OGL Program was not correct.\n");
		}
	}
}
コード例 #3
0
ファイル: graphics_gl2.cpp プロジェクト: lwllovewf2010/vdrift
bool GraphicsGL2::ReloadShaders(std::ostream & info_output, std::ostream & error_output)
{
	EnableShaders(info_output, error_output);

	return GetUsingShaders();
}
コード例 #4
0
ファイル: graphics_gl2.cpp プロジェクト: lwllovewf2010/vdrift
bool GraphicsGL2::Init(
	const std::string & newshaderpath,
	unsigned resx, unsigned resy,
	unsigned bpp, unsigned depthbpp,
	bool fullscreen, unsigned antialiasing,
	bool enableshadows, int new_shadow_distance,
	int new_shadow_quality, int reflection_type,
	const std::string & static_reflectionmap_file,
	const std::string & static_ambientmap_file,
	int anisotropy, int texturesize,
	int lighting_quality, bool newbloom,
	bool newnormalmaps, bool dynamicsky,
	const std::string & renderconfig,
	std::ostream & info_output,
	std::ostream & error_output)
{
	shadows = enableshadows;
	shadow_distance = new_shadow_distance;
	shadow_quality = new_shadow_quality;
	lighting = lighting_quality;
	bloom = newbloom;
	normalmaps = newnormalmaps;
	renderconfigfile = renderconfig;
	shaderpath = newshaderpath;
	sky_dynamic = dynamicsky;

	if (reflection_type == 1)
		reflection_status = REFLECTION_STATIC;
	else if (reflection_type == 2)
		reflection_status = REFLECTION_DYNAMIC;

	ChangeDisplay(resx, resy, error_output);

	fsaa = 1;
	if (antialiasing > 1)
		fsaa = antialiasing;

	if (GLEW_EXT_texture_filter_anisotropic)
		glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);

	info_output << "Maximum anisotropy: " << max_anisotropy << std::endl;

	if (renderconfigfile == "noshaders.conf")
	{
		DisableShaders(error_output);
	}
	else if (!GLEW_ARB_multitexture)
	{
		info_output << "Your video card doesn't support multitexturing.  Disabling shaders." << std::endl;
		DisableShaders(error_output);
	}
	else if (!GLEW_ARB_texture_cube_map)
	{
		info_output << "Your video card doesn't support cube maps.  Disabling shaders." << std::endl;
		DisableShaders(error_output);
	}
	else if (!GLEW_ARB_texture_non_power_of_two)
	{
		info_output << "Your video card doesn't support non-power-of-two textures.  Disabling shaders." << std::endl;
		DisableShaders(error_output);
	}
	else
	{
		GLint maxattach;
		glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxattach);
		info_output << "Maximum color attachments: " << maxattach << std::endl;

		const GLint mrtreq = 1;
		GLint mrt = 0;
		glGetIntegerv(GL_MAX_DRAW_BUFFERS, &mrt);
		info_output << "Maximum draw buffers (" << mrtreq << " required): " << mrt << std::endl;

		#ifndef FBOEXT
		bool use_fbos = GLEW_ARB_framebuffer_object && mrt >= mrtreq && maxattach >= mrtreq;
		#else
		bool use_fbos = GLEW_EXT_framebuffer_object && mrt >= mrtreq && maxattach >= mrtreq;
		#endif

		if (renderconfigfile != "nofbos.conf" && !use_fbos)
		{
			info_output << "Your video card doesn't support framebuffer objects." << std::endl;
			info_output << "Fall back to nofbos.conf." << std::endl;
			renderconfigfile = "nofbos.conf";
		}

		if (GLEW_VERSION_2_0 && GLEW_ARB_shading_language_100 && GLEW_ARB_fragment_shader)
		{
			if ((reflection_status == REFLECTION_STATIC || reflection_status == REFLECTION_DYNAMIC) && !static_reflectionmap_file.empty())
			{
				TextureInfo t;
				t.cube = true;
				t.verticalcross = true;
				t.mipmap = true;
				t.anisotropy = anisotropy;
				t.maxsize = TextureInfo::Size(texturesize);
				static_reflection.Load(static_reflectionmap_file, t, error_output);
			}

			if (!static_ambientmap_file.empty())
			{
				TextureInfo t;
				t.cube = true;
				t.verticalcross = true;
				t.mipmap = false;
				t.anisotropy = anisotropy;
				t.maxsize = TextureInfo::Size(texturesize);
				static_ambient.Load(static_ambientmap_file, t, error_output);
			}

			EnableShaders(info_output, error_output);
		}
		else
		{
			info_output << "Your video card doesn't support shaders. Fall back to noshaders.conf." << std::endl;
			DisableShaders(error_output);
		}
	}

	info_output << "Renderer: " << shaderpath << "/" << renderconfigfile << std::endl;
	initialized = true;
	return true;
}
コード例 #5
0
ファイル: graphics_gl2.cpp プロジェクト: HaohaoLau/vdrift
bool GraphicsGL2::Init(
	const std::string & newshaderpath,
	unsigned resx, unsigned resy,
	unsigned bpp, unsigned depthbpp,
	bool fullscreen, unsigned antialiasing,
	bool enableshadows, int new_shadow_distance,
	int new_shadow_quality, int reflection_type,
	const std::string & static_reflectionmap_file,
	const std::string & static_ambientmap_file,
	int anisotropy, int texturesize,
	int lighting_quality, bool newbloom,
	bool newnormalmaps, bool dynamicsky,
	const std::string & renderconfig,
	std::ostream & info_output,
	std::ostream & error_output)
{
	assert(!renderconfig.empty() && "Render configuration name string empty.");

	if (!GLEW_VERSION_2_0)
	{
		error_output << "Graphics card or driver does not support required GL_VERSION_2_0." << std::endl;
		return false;
	}

	shadows = enableshadows;
	shadow_distance = new_shadow_distance;
	shadow_quality = new_shadow_quality;
	lighting = lighting_quality;
	bloom = newbloom;
	normalmaps = newnormalmaps;
	renderconfigfile = renderconfig;
	shaderpath = newshaderpath;
	sky_dynamic = dynamicsky;

	if (reflection_type == 1)
		reflection_status = REFLECTION_STATIC;
	else if (reflection_type == 2)
		reflection_status = REFLECTION_DYNAMIC;

	fsaa = (antialiasing > 1) ? antialiasing : 1;

	ChangeDisplay(resx, resy, error_output);

	if (GLEW_EXT_texture_filter_anisotropic)
		glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);
	info_output << "Maximum anisotropy: " << max_anisotropy << std::endl;

	GLint maxattach;
	glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxattach);
	info_output << "Maximum color attachments: " << maxattach << std::endl;

	const GLint mrtreq = 1;
	GLint mrt = 0;
	glGetIntegerv(GL_MAX_DRAW_BUFFERS, &mrt);
	info_output << "Maximum draw buffers (" << mrtreq << " required): " << mrt << std::endl;

	#ifndef FBOEXT
	bool use_fbos = GLEW_ARB_framebuffer_object && mrt >= mrtreq && maxattach >= mrtreq;
	#else
	bool use_fbos = GLEW_EXT_framebuffer_object && mrt >= mrtreq && maxattach >= mrtreq;
	#endif

	if (renderconfigfile != "basic.conf" && !use_fbos)
	{
		info_output << "Graphics card doesn't support framebuffer objects." << std::endl;

		shadows = false;
		sky_dynamic = false;
		renderconfigfile = "basic.conf";
		info_output << "Fall back to: " << renderconfigfile << std::endl;
	}

	if (!static_reflectionmap_file.empty() && reflection_status != REFLECTION_DISABLED)
	{
		TextureInfo t;
		t.cube = true;
		t.verticalcross = true;
		t.mipmap = true;
		t.anisotropy = anisotropy;
		t.maxsize = TextureInfo::Size(texturesize);
		static_reflection.Load(static_reflectionmap_file, t, error_output);
	}

	if (!static_ambientmap_file.empty())
	{
		TextureInfo t;
		t.cube = true;
		t.verticalcross = true;
		t.mipmap = false;
		t.anisotropy = anisotropy;
		t.maxsize = TextureInfo::Size(texturesize);
		static_ambient.Load(static_ambientmap_file, t, error_output);
	}

	if (!EnableShaders(info_output, error_output))
	{
		// try to fall back to basic.conf
		if (renderconfigfile != "basic.conf")
		{
			shadows = false;
			sky_dynamic = false;
			renderconfigfile = "basic.conf";
			info_output << "Fall back to: " << renderconfigfile << std::endl;

			if (!EnableShaders(info_output, error_output))
				return false;
		}
	}

	if (sky_dynamic)
	{
		sky.reset(new Sky(*this, error_output));
		texture_inputs["sky"] = sky.get();
	}

	// gl state setup
	glEnable(GL_LINE_SMOOTH);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glShadeModel(GL_SMOOTH);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glClearColor(0, 0, 0, 0);
	glClearDepth(1);
	glPolygonOffset(-1, -1);

	info_output << "Renderer: " << shaderpath << "/" << renderconfigfile << std::endl;
	initialized = true;

	return true;
}
コード例 #6
0
void OpenGLEngine::Draw (std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<VertexBuffer> instancedBuffer, std::shared_ptr<IndexBuffer> indexBuffer, std::shared_ptr<VisualEffect> visualEffect)
{
	std::shared_ptr<Program> program = visualEffect->GetProgram ();
	std::string programName = program->GetProgramName ();

	OGLProgram* oglProgram = dynamic_cast<OGLProgram*> (program.get());

	if (oglProgram)
	{
		GLuint programHandle = oglProgram->GetProgramHandle ();
		glUseProgram (programHandle);
	
		if (EnableShaders (visualEffect, programHandle))
		{
			std::shared_ptr<OGLVertexBuffer> oglVertexBuffer = nullptr;
			std::shared_ptr<OGLVertexBuffer> oglInstancedBuffer = nullptr;
			std::shared_ptr<OGLIndexBuffer> oglIndexBuffer = nullptr;
			OGLVertexArrayObject* vao = nullptr;

			m_MapCO.Get (std::make_pair (vertexBuffer.get(), indexBuffer.get ()), vao);
			if (vao)
			{
				vao->Enable ();
			}
			else
			{

				if (vertexBuffer)
				{
					oglVertexBuffer = std::static_pointer_cast<OGLVertexBuffer> (Bind (vertexBuffer));
				}

				if (indexBuffer)
				{
					oglIndexBuffer = std::static_pointer_cast<OGLIndexBuffer> (Bind(indexBuffer));
				}

				vao = static_cast<OGLVertexArrayObject*> (Bind (oglVertexBuffer, oglIndexBuffer));

				oglInstancedBuffer = std::static_pointer_cast<OGLVertexBuffer> (Bind (instancedBuffer));
				oglInstancedBuffer->Enable ();

				VertexAttributes vertexAttrib = vertexBuffer->GetVertexAttrib ();
				VertexAttributes instancedAttrib = instancedBuffer->GetVertexAttrib ();

				int vertexBufferNumAttrib = vertexAttrib.GetNumAttrib ();
				int instancedBufferNumAttrib = instancedAttrib.GetNumAttrib ();

				for (int i = vertexBufferNumAttrib; i < vertexBufferNumAttrib + instancedBufferNumAttrib; i++)
				{
					ContainerType type = instancedAttrib.GetContainerType (i - vertexBufferNumAttrib);
					int offset = instancedAttrib.GetOffset(i - vertexBufferNumAttrib);
		
					int numElements = DataAttributes::GetNumElement (type);	
					GLenum channelType = oglInstancedBuffer->m_ChannelType[DataAttributes::GetElementType (type)];
					size_t vertSize = instancedAttrib.GetVertexSize ();

					glEnableVertexAttribArray (i);
		
					glVertexAttribPointer (i, numElements, channelType, GL_FALSE, vertSize, (void*)offset);

					glVertexAttribDivisor (i, 1);
				}
				
			}

			DrawPrimitive (vertexBuffer.get (), instancedBuffer.get (), indexBuffer.get ());

			vao->Disable ();

			DisableShaders (visualEffect, programHandle);
		}
		else
		{
			fprintf (stderr, "The draw method in OpenGLEngine failed, because the OGL Program was not correct.\n");
		}
	}
}
コード例 #7
0
ファイル: graphics_gl2.cpp プロジェクト: gunchleoc/vdrift
bool GRAPHICS_GL2::Init(
	const std::string & shaderpath,
	unsigned int resx, unsigned int resy, unsigned int bpp,
	unsigned int depthbpp, bool fullscreen, bool shaders,
	unsigned int antialiasing, bool enableshadows, int new_shadow_distance,
	int new_shadow_quality, int reflection_type,
	const std::string & static_reflectionmap_file,
	const std::string & static_ambientmap_file,
	int anisotropy, int texturesize,
	int lighting_quality, bool newbloom, bool newnormalmaps,
	const std::string & renderconfig,
	std::ostream & info_output, std::ostream & error_output)
{
	shadows = enableshadows;
	shadow_distance = new_shadow_distance;
	shadow_quality = new_shadow_quality;
	lighting = lighting_quality;
	bloom = newbloom;
	normalmaps = newnormalmaps;
	renderconfigfile = renderconfig;

	if (reflection_type == 1)
		reflection_status = REFLECTION_STATIC;
	else if (reflection_type == 2)
		reflection_status = REFLECTION_DYNAMIC;

	ChangeDisplay(resx, resy, error_output);

	fsaa = 1;
	if (antialiasing > 1)
		fsaa = antialiasing;

	if (!GLEW_ARB_multitexture)
	{
		info_output << "Your video card doesn't support multitexturing.  Disabling shaders." << std::endl;
		DisableShaders(shaderpath, error_output);
	}
	else if (!GLEW_ARB_texture_cube_map)
	{
		info_output << "Your video card doesn't support cube maps.  Disabling shaders." << std::endl;
		DisableShaders(shaderpath, error_output);
	}
	else if (!GLEW_ARB_framebuffer_object)
	{
		info_output << "Your video card doesn't support framebuffer objects.  Disabling shaders." << std::endl;
		DisableShaders(shaderpath, error_output);
	}
	else if (!GLEW_ARB_draw_buffers)
	{
		info_output << "Your video card doesn't support multiple draw buffers.  Disabling shaders." << std::endl;
		DisableShaders(shaderpath, error_output);
	}
	else if (!GLEW_ARB_texture_non_power_of_two)
	{
		info_output << "Your video card doesn't support non-power-of-two textures.  Disabling shaders." << std::endl;
		DisableShaders(shaderpath, error_output);
	}
	else if (!GLEW_ARB_texture_float)
	{
		info_output << "Your video card doesn't support floating point textures.  Disabling shaders." << std::endl;
		DisableShaders(shaderpath, error_output);
	}
	else if (!GLEW_ARB_half_float_pixel)
	{
		info_output << "Your video card doesn't support 16-bit floats.  Disabling shaders." << std::endl;
		DisableShaders(shaderpath, error_output);
	}
	else if (!GLEW_ARB_shader_texture_lod && !GLEW_VERSION_2_1) // texture2DLod in logluminance shader
	{
		info_output << "Your video card doesn't support texture2DLod.  Disabling shaders." << std::endl;
		DisableShaders(shaderpath, error_output);
	}
	else
	{
		GLint maxattach;
		glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxattach);
		info_output << "Maximum color attachments: " << maxattach << std::endl;

		const GLint reqmrt = 1;

		GLint mrt;
		glGetIntegerv(GL_MAX_DRAW_BUFFERS, &mrt);
		info_output << "Maximum draw buffers (" << reqmrt << " required): " << mrt << std::endl;

		if (GLEW_ARB_shading_language_100 && GLEW_VERSION_2_0 && shaders && GLEW_ARB_fragment_shader && mrt >= reqmrt && maxattach >= reqmrt)
		{
			EnableShaders(shaderpath, info_output, error_output);
		}
		else
		{
			info_output << "Disabling shaders" << std::endl;
			DisableShaders(shaderpath, error_output);
		}
	}

	//load static reflection map for dynamic reflections too, since we may need it
	if ((reflection_status == REFLECTION_STATIC || reflection_status == REFLECTION_DYNAMIC) && !static_reflectionmap_file.empty())
	{
		TEXTUREINFO t;
		t.cube = true;
		t.verticalcross = true;
		t.mipmap = true;
		t.anisotropy = anisotropy;
		t.maxsize = TEXTUREINFO::Size(texturesize);
		static_reflection.Load(static_reflectionmap_file, t, error_output);
	}

	if (!static_ambientmap_file.empty())
	{
		TEXTUREINFO t;
		t.cube = true;
		t.verticalcross = true;
		t.mipmap = false;
		t.anisotropy = anisotropy;
		t.maxsize = TEXTUREINFO::Size(texturesize);
		static_ambient.Load(static_ambientmap_file, t, error_output);
	}

	if (GLEW_EXT_texture_filter_anisotropic)
		glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);

	info_output << "Maximum anisotropy: " << max_anisotropy << std::endl;

	GLUTIL::CheckForOpenGLErrors("Shader loading", error_output);

	initialized = true;

	return true;
}
コード例 #8
0
ファイル: graphics_gl2.cpp プロジェクト: Alexander-Eck/vdrift
bool GraphicsGL2::Init(
	const std::string & newshaderpath,
	unsigned resx, unsigned resy, unsigned depthbpp,
	bool fullscreen, unsigned antialiasing,
	bool enableshadows, int new_shadow_distance,
	int new_shadow_quality, int reflection_type,
	const std::string & static_reflectionmap_file,
	const std::string & static_ambientmap_file,
	int anisotropy, int texturesize,
	int lighting_quality, bool newbloom,
	bool newnormalmaps, bool dynamicsky,
	const std::string & renderconfig,
	std::ostream & info_output,
	std::ostream & error_output)
{
	assert(!renderconfig.empty() && "Render configuration name string empty.");

	const GLubyte * version = glGetString(GL_VERSION);
	if (version[0] < '2')
	{
		error_output << "Graphics card or driver does not support required GL Version: 2.0" << std::endl;
		return false;
	}
	if (version[0] > '2')
	{
		int major_version = 0;
		int minor_version = 0;
		glGetIntegerv(GL_MAJOR_VERSION, &major_version);
		glGetIntegerv(GL_MINOR_VERSION, &minor_version);
		glsl_330 = (major_version > 3 || (major_version == 3 && minor_version >= 3));
	}

	#ifdef _WIN32
	// workaround for broken vao implementation Intel/Windows
	{
		const std::string vendor = (const char*)glGetString(GL_VENDOR);
		if (vendor == "Intel")
			vertex_buffer.BindElementBufferExplicitly();
	}
	#endif

	shadows = enableshadows;
	shadow_distance = new_shadow_distance;
	shadow_quality = new_shadow_quality;
	lighting = lighting_quality;
	bloom = newbloom;
	normalmaps = newnormalmaps;
	renderconfigfile = renderconfig;
	shaderpath = newshaderpath;
	sky_dynamic = dynamicsky;

	if (reflection_type == 1)
		reflection_status = REFLECTION_STATIC;
	else if (reflection_type == 2)
		reflection_status = REFLECTION_DYNAMIC;

	fsaa = (antialiasing > 1) ? antialiasing : 1;

	ChangeDisplay(resx, resy, error_output);

	if (GLC_EXT_texture_filter_anisotropic)
		glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);
	info_output << "Maximum anisotropy: " << max_anisotropy << std::endl;

	GLint maxattach;
	glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxattach);
	info_output << "Maximum color attachments: " << maxattach << std::endl;

	const GLint mrtreq = 1;
	GLint mrt = 0;
	glGetIntegerv(GL_MAX_DRAW_BUFFERS, &mrt);
	info_output << "Maximum draw buffers (" << mrtreq << " required): " << mrt << std::endl;

	bool use_fbos = GLC_ARB_framebuffer_object && mrt >= mrtreq && maxattach >= mrtreq;
	if (renderconfigfile != "basic.conf" && !use_fbos)
	{
		info_output << "Graphics card doesn't support framebuffer objects." << std::endl;

		shadows = false;
		sky_dynamic = false;
		renderconfigfile = "basic.conf";
		info_output << "Fall back to: " << renderconfigfile << std::endl;
	}

	if (!static_reflectionmap_file.empty() && reflection_status != REFLECTION_DISABLED)
	{
		TextureInfo t;
		t.cube = true;
		t.verticalcross = true;
		t.mipmap = true;
		t.anisotropy = anisotropy;
		t.maxsize = TextureInfo::Size(texturesize);
		static_reflection.Load(static_reflectionmap_file, t, error_output);
	}

	if (!static_ambientmap_file.empty())
	{
		TextureInfo t;
		t.cube = true;
		t.verticalcross = true;
		t.mipmap = false;
		t.anisotropy = anisotropy;
		t.maxsize = TextureInfo::Size(texturesize);
		static_ambient.Load(static_ambientmap_file, t, error_output);
	}

	if (!EnableShaders(info_output, error_output))
	{
		// try to fall back to basic.conf
		if (renderconfigfile != "basic.conf")
		{
			shadows = false;
			sky_dynamic = false;
			renderconfigfile = "basic.conf";
			info_output << "Fall back to: " << renderconfigfile << std::endl;

			if (!EnableShaders(info_output, error_output))
				return false;
		}
	}

	if (sky_dynamic)
	{
		sky.reset(new Sky(*this, error_output));
		texture_inputs["sky"] = sky.get();
	}

	// gl state setup
	glPolygonOffset(-1, -1);

	info_output << "Renderer: " << shaderpath << "/" << renderconfigfile << std::endl;
	initialized = true;

	return true;
}