void opengl_light_state::SetAmbient(GLfloat *val)
{
	Assert(Light_num >= 0 && Light_num < GL_max_lights);

	if ( fl_equal(Ambient[0], val[0]) &&
		fl_equal(Ambient[1], val[1]) &&
		fl_equal(Ambient[2], val[2]) &&
		fl_equal(Ambient[3], val[3]) ) {
		return;
	}

	Ambient[0] = val[0];
	Ambient[1] = val[1];
	Ambient[2] = val[2];
	Ambient[3] = val[3];
}
void opengl_light_state::SetDiffuse(GLfloat *val)
{
	Assert(Light_num >= 0 && Light_num < GL_max_lights);

	if ( fl_equal(Diffuse[0], val[0]) &&
		fl_equal(Diffuse[1], val[1]) &&
		fl_equal(Diffuse[2], val[2]) &&
		fl_equal(Diffuse[3], val[3]) ) {
		return;
	}

	Diffuse[0] = val[0];
	Diffuse[1] = val[1];
	Diffuse[2] = val[2];
	Diffuse[3] = val[3];

}
void opengl_light_state::SetSpecular(GLfloat *val)
{
	Assert(Light_num >= 0 && Light_num < GL_max_lights);

	if ( fl_equal(Specular[0], val[0]) &&
		fl_equal(Specular[1], val[1]) &&
		fl_equal(Specular[2], val[2]) &&
		fl_equal(Specular[3], val[3]) ) {
		return;
	}

	Specular[0] = val[0];
	Specular[1] = val[1];
	Specular[2] = val[2];
	Specular[3] = val[3];

}
void opengl_light_state::SetPosition(GLfloat *val)
{
	Assert(Light_num >= 0 && Light_num < GL_max_lights);

	if ( !InvalidPosition && 
		fl_equal(Position[0], val[0]) && 
		fl_equal(Position[1], val[1]) && 
		fl_equal(Position[2], val[2]) && 
		fl_equal(Position[3], val[3]) ) {
		return;
	}

	Position[0] = val[0];
	Position[1] = val[1];
	Position[2] = val[2];
	Position[3] = val[3];

	InvalidPosition = false;
}
Ejemplo n.º 5
0
void opengl::ShaderUniforms::setUniform1fv(const SCP_string &name, const int count, const float *val)
{
	Assertion(GL_state.IsCurrentProgram(_program->getShaderHandle()), "The program must be current before setting uniforms!");

	auto uniform_index = findUniform(name);
	bool resident = false;

	if (uniform_index != INVALID_SIZE) {
		Assert((size_t)uniform_index < _uniforms.size());

		uniform_bind *bind_info = &_uniforms[uniform_index];

		if (bind_info->type == uniform_bind::FLOAT && bind_info->count == count) {
			bool equal = true;

			// if the values are close enough, pass.
			for (int i = 0; i < count; ++i) {
				if (!fl_equal(val[i], _uniform_data_floats[bind_info->index + i])) {
					equal = false;
					break;
				}
			}

			if (equal) {
				return;
			}

			resident = true;
			for (int i = 0; i < count; ++i) {
				_uniform_data_floats[bind_info->index + i] = val[i];
			}
		}
	}

	if (!resident) {
		// uniform doesn't exist in our previous uniform block so queue this new value
		for (int i = 0; i < count; ++i) {
			_uniform_data_floats.push_back(val[i]);
		}

		uniform_bind new_bind;
		new_bind.count = count;
		new_bind.index = _uniform_data_floats.size() - count;
		//	new_bind.index = num_matrix_uniforms - count;
		new_bind.type = uniform_bind::FLOAT;
		new_bind.name = name;

		_uniforms.push_back(new_bind);

		_uniform_lookup[name] = _uniforms.size() - 1;
	}

	glUniform1fv(findUniformLocation(name.c_str()), count, (const GLfloat*)val);
}
void opengl_light_state::SetSpotCutoff(GLfloat val)
{
	Assert(Light_num >= 0 && Light_num < GL_max_lights);

	if ( fl_equal(SpotCutoff, val) ) {
		return;
	}

	SpotCutoff = val;

}
void opengl_light_state::SetSpotExponent(GLfloat val)
{
	Assert(Light_num >= 0 && Light_num < GL_max_lights);

	if ( fl_equal(SpotExponent, val) ) {
		return;
	}

	SpotExponent = val;

}
void opengl_light_state::SetQuadraticAttenuation(GLfloat val)
{
	Assert(Light_num >= 0 && Light_num < GL_max_lights);

	if ( fl_equal(QuadraticAttenuation, val) ) {
		return;
	}

	QuadraticAttenuation = val;

}
Ejemplo n.º 9
0
void opengl::ShaderUniforms::setUniformf(const SCP_string &name, const float val)
{
	Assertion(GL_state.IsCurrentProgram(_program->getShaderHandle()), "The program must be current before setting uniforms!");

	size_t uniform_index = findUniform(name);
	bool resident = false;

	if (uniform_index != (size_t)-1) {
		Assert((size_t)uniform_index < _uniforms.size());

		uniform_bind *bind_info = &_uniforms[uniform_index];

		if (bind_info->type == uniform_bind::FLOAT) {
			if (fl_equal(_uniform_data_floats[bind_info->index], val)) {
				return;
			}

			_uniform_data_floats[bind_info->index] = val;
			resident = true;
		}
	}

	if (!resident) {
		// uniform doesn't exist in our previous uniform block so queue this new value
		_uniform_data_floats.push_back(val);

		uniform_bind new_bind;

		new_bind.count = 1;
		new_bind.index = _uniform_data_floats.size() - 1;
		new_bind.type = uniform_bind::FLOAT;
		new_bind.name = name;

		_uniforms.push_back(new_bind);

		_uniform_lookup[name] = _uniforms.size() - 1;
	}

	glUniform1f(findUniformLocation(name.c_str()), val);
}
Ejemplo n.º 10
0
void opengl_uniform_state::setUniformf(const SCP_string &name, const float val)
{
	size_t uniform_index = findUniform(name);
	bool resident = false;

	if ( uniform_index != (size_t) -1) {
		Assert( (size_t)uniform_index < uniforms.size() );

		uniform_bind *bind_info = &uniforms[uniform_index];

		if ( bind_info->type == uniform_bind::FLOAT ) {
			if ( fl_equal(uniform_data_floats[bind_info->index], val) ) {
				return;
			}

			uniform_data_floats[bind_info->index] = val;
			resident = true;
		}
	} 

	if ( !resident ) {
		// uniform doesn't exist in our previous uniform block so queue this new value
		uniform_data_floats.push_back(val);

		uniform_bind new_bind;

		new_bind.count = 1;
		new_bind.index = uniform_data_floats.size() - 1;
		new_bind.type = uniform_bind::FLOAT;
		new_bind.name = name;

		uniforms.push_back(new_bind);

		uniform_lookup[name] = uniforms.size()-1;
	}

	glUniform1f(opengl_shader_get_uniform(name.c_str()), val);
}
Ejemplo n.º 11
0
static int fl_equal_ex_ts(const db_field_log *pfl1, const db_field_log *pfl2) {
    db_field_log fl1 = *pfl1;

    fl1.time = pfl2->time;
    return fl_equal(&fl1, pfl2);
}