Esempio n. 1
0
	void ShaderProgram::release ()
	{
		if (shaders_supported())
		{
			glUseProgram(0);
		}
	}
Esempio n. 2
0
	void ShaderProgram::bind_frag_data_location(int color_num, const char* name)
	{
		if (shaders_supported())
		{
			glBindFragDataLocation(id_, color_num, name);
		}
	}
Esempio n. 3
0
static void
gl_init(WaveformView* view)
{
	if(gl_initialised) return;

	START_DRAW {

		if(wf_get_instance()->pref_use_shaders && !shaders_supported()){
			printf("gl shaders not supported. expect reduced functionality.\n");
			//printf("Warning: this program expects OpenGL 2.0\n");
			wf_canvas_use_program(view->priv->canvas, 0);
			view->priv->canvas->use_shaders = false;
		}
		printf("GL_RENDERER = %s\n", (const char*)glGetString(GL_RENDERER));

		GLboolean npotTexturesAvailable = GL_FALSE;
		if(GL_ARB_texture_non_power_of_two){
			if(wf_debug) printf("non_power_of_two textures are available.\n");
			npotTexturesAvailable = GL_TRUE;
		}else{
			fprintf(stderr, "GL_ARB_texture_non_power_of_two extension is not available!\n" );
			fprintf(stderr, "Framebuffer effects will be lower resolution (lower quality).\n\n" );
		}

	} END_DRAW

	gl_initialised = true;
}
Esempio n. 4
0
	void ShaderProgram::destroy ()
	{
		if (shaders_supported())
		{
			glDeleteProgram(id_);
			id_ = 0;
		}
	}
Esempio n. 5
0
	void ShaderProgram::setLocalParamUInt(int i, unsigned int value)
	{
		if (shaders_supported())
		{
			const char *loc_strings[] = {"loci0", "loci1", "loci2", "loci3",
				"loci4", "loci5", "loci6", "loci7",
				"loci8", "loci9", "loci10", "loci11",
				"loci12", "loci13", "loci14", "loci15"};

			if (loc_ui[i] == -1)
			{
				loc_ui[i] = glGetUniformLocation(id_, loc_strings[i]);
				if (loc_ui[i] == -1)
					loc_ui[i]--;
			}
			if (loc_ui[i] >= 0)
				glUniform1ui(loc_ui[i], value);
		}
	}
Esempio n. 6
0
	void ShaderProgram::setLocalParamMatrix(int i, float* matrix4)
	{
		if (shaders_supported())
		{
			const char *loc_strings[] = {"matrix0", "matrix1", "matrix2", "matrix3",
				"matrix4", "matrix5", "matrix6", "matrix7",
				"matrix8", "matrix9", "matrix10", "matrix11",
				"matrix12", "matrix13", "matrix14", "matrix15"};

			if (loc_mat4[i] == -1)
			{
				loc_mat4[i] = glGetUniformLocation(id_, loc_strings[i]);
				if (loc_mat4[i] == -1)
					loc_mat4[i]--;
			}
			if (loc_mat4[i] >= 0)
				glUniformMatrix4fv(loc_mat4[i], 1, false, matrix4);
		}
	}
Esempio n. 7
0
	void ShaderProgram::setLocalParam(int i, double x, double y, double z, double w)
	{
		if (shaders_supported())
		{
			const char *loc_strings[] = {"loc0", "loc1", "loc2", "loc3",
				"loc4", "loc5", "loc6", "loc7",
				"loc8", "loc9", "loc10", "loc11",
				"loc12", "loc13", "loc14", "loc15"};

			if (loc_vec4[i] == -1)
			{
				loc_vec4[i] = glGetUniformLocation(id_, loc_strings[i]);
				if (loc_vec4[i] == -1)
					loc_vec4[i]--;
			}
			if (loc_vec4[i] >=0)
				glUniform4f(loc_vec4[i], float(x), float(y), float(z), float(w));
		}
	}
Esempio n. 8
0
	void ShaderProgram::bind ()
	{
		if (shaders_supported())
			glUseProgram(id_);
	}
Esempio n. 9
0
	bool
		ShaderProgram::create()
	{
		if (shaders_supported())
		{
			// create the GLSL program and attach the shader
			id_ = glCreateProgram();
			if (id_ == 0) return true;
			valid_ = true;

			GLuint v_shader, f_shader;
			v_shader = glCreateShader(GL_VERTEX_SHADER);

			f_shader = glCreateShader(GL_FRAGMENT_SHADER);

			if (v_shader == 0 || f_shader == 0) return true;

			// set the source code and compile the shader // vertex
			const char *v_source[1], *f_source[1];
			v_source[0] = vert_shader_.c_str();
			GLint lengths[1];
			lengths[0] = (int)std::strlen(v_source[0]);
			glShaderSource(v_shader, 1, v_source, lengths);
			glCompileShader(v_shader);

			// check the compilation of the shader
			GLint shader_status[1];
			char shader_log[1000];
			GLint shader_length[1];
			bool attach_vert = strcmp(*v_source,"") != 0;
			glGetShaderiv(v_shader, GL_COMPILE_STATUS, shader_status);
			if (shader_status[0] == GL_FALSE) {
				glGetShaderInfoLog(v_shader, sizeof(shader_log), shader_length, shader_log);
				std::cerr << "Error compiling vertex shader: " << shader_log << std::endl;
				attach_vert = false;
			}

			// set the source code and compile the shader // fragment
			f_source[0] = frag_shader_.c_str();
			lengths[0] = (int)std::strlen(f_source[0]);
			glShaderSource(f_shader, 1, f_source, lengths);
			glCompileShader(f_shader);

			// check the compilation of the shader
			bool attach_frag = true;
			glGetShaderiv(f_shader, GL_COMPILE_STATUS, shader_status);
			if (shader_status[0] == GL_FALSE) {
				glGetShaderInfoLog(f_shader, sizeof(shader_log), shader_length, shader_log);
				std::cerr << "Error compiling fragment shader: " << shader_log << std::endl;
				attach_frag = false;
			}

			if (attach_vert)
				glAttachShader(id_, v_shader);
			if (attach_frag)
				glAttachShader(id_, f_shader);

			//link time
			glLinkProgram(id_);
			glGetProgramiv(id_, GL_LINK_STATUS, shader_status);
			if (shader_status[0] == GL_FALSE) {
				glGetProgramInfoLog(id_, sizeof(shader_log), shader_length, shader_log);
				std::cerr << "Error linking shaders: " << shader_log << std::endl;
				return true;
			}

			glUseProgram(id_);

			//glBindFragDataLocation(id_, 0, "FragColor");

			const char *loc_strings[] = {
				"tex0", "tex1", "tex2", "tex3",
				"tex4", "tex5", "tex6", "tex7",
				"tex8", "tex9", "tex10", "tex11",
				"tex12", "tex13", "tex14", "tex15"};

			int location;
			for (size_t i=0; i<MAX_SHADER_UNIFORMS; ++i)
			{
				glActiveTexture(GL_TEXTURE0 + i);
				location = glGetUniformLocation(id_, loc_strings[i]);
				if (location != -1)
					glUniform1i(location, i);
			}

			glValidateProgram(id_);
			glGetProgramiv(id_, GL_VALIDATE_STATUS, shader_status);
			if (shader_status[0] == GL_FALSE) {
				glGetProgramInfoLog(id_, sizeof(shader_log), shader_length, shader_log);
				std::cerr << "Invalid shader program: " << shader_log << std::endl;
				return true;
			}

			return false;
		}
		return true;
	}