// given a valid XSTR() tag piece of text, extract the string portion, return it in out, nonzero on success
int lcl_ext_get_text(const SCP_string &xstr, SCP_string &out)
{
	size_t open_quote_pos, close_quote_pos;

	// this is some crazy wack-ass code.
	// look for the open quote
	open_quote_pos = xstr.find('\"');
	if (open_quote_pos == SCP_string::npos) {
		error_display(0, "Error parsing XSTR() tag %s\n", xstr.c_str());
		return 0;
	}

	// look for the close quote
	close_quote_pos = xstr.find('\"', open_quote_pos+1);
	if (close_quote_pos == SCP_string::npos) {
		error_display(0, "Error parsing XSTR() tag %s\n", xstr.c_str());
		return 0;
	}

	// now that we know the boundaries of the actual string in the XSTR() tag, copy it
	out.assign(xstr, open_quote_pos + 1, close_quote_pos - open_quote_pos - 1);

	// success
	return 1;
}
// ============================== IMPLEMENTATIONS =============================
void dc_do_command(SCP_string *cmd_str)
{
	/**
	 * Grab the first word from the cmd_str
	 *  If it is not a literal, ignore it "Invalid keyword: %s"
	 *  Search for the command...
	 *      Compare the word against valid commands
	 *      If command not found, ignore it "Invalid or unknown command: %s"\
	 *  Process the command...
	 *      Call the function to process the command (the rest of the command line is in the parser)
	 *          Function takes care of long_help and status depending on the mode.
	 */
	int i;
	SCP_string command;
	extern debug_command* dc_commands[];	// z64: I don't like this extern here, at all. Nope nope nope.

	if (cmd_str->empty()) {
		return;
	}

	dc_parse_init(*cmd_str);

	dc_stuff_string_white(command);		// Grab the first token, presumably this is a command

	for (i = 0; i < dc_commands_size; ++i) {

		if (stricmp(dc_commands[i]->name, command.c_str()) == 0) {
			break;
		} // Else, continue
	}

	if (i == dc_commands_size) {
		dc_printf("Command not found: '%s'\n", command.c_str());
		return;
	} // Else, we found our command

	try {
		dc_commands[i]->func();	// Run the command!
	
	} catch (errParseString err) {
		dc_printf("Require string(s) not found: \n");
		for (uint j = 0; j < err.expected_tokens.size(); ++j) {
			dc_printf("%i: %s\n", j, err.expected_tokens[j].c_str());
		}

		dc_printf("Found '%s' instead\n", err.found_token.c_str());
	
	} catch (errParse err) {
		dc_printf("Invalid argument. Expected %s, found '%s'\n", token_str[err.expected_type], err.found_token.c_str());

	}

	// dc_maybe_stuff_string is vulnerable to overflow. Once the errParseOverflow throw class (or w/e) gets
	// implemented, this last command should be put into its own try{} catch{} block.
	if (dc_maybe_stuff_string(command)) {
		dc_printf( "Ignoring the unused command line tail '%s'\n", command.c_str() );
	}
}
int parseAnimation(bool critical) {
	SCP_string name;
	stuff_string(name, F_FILESPEC);

	auto handle = bm_load_animation(name.c_str());

	if (handle < 0) {
		int level = critical ? 1 : 0;
		error_display(level, "Failed to load effect %s!", name.c_str());
	}

	return handle;
}
HKEY get_registry_keyname(char* out_keyname, const char* section)
{
	// Every compiler from Visual Studio 2008 onward should have support for UAC
#if _MSC_VER >= 1400
	if (userSIDValid)
	{
		if (needsWOW64())
		{
			if (section) {
				sprintf(out_keyname, "%s_Classes\\VirtualStore\\Machine\\Software\\Wow6432Node\\%s\\%s\\%s", userSID.c_str(), szCompanyName, szAppName, section);
			}
			else {
				sprintf(out_keyname, "%s_Classes\\VirtualStore\\Machine\\Software\\Wow6432Node\\%s\\%s", userSID.c_str(), szCompanyName, szAppName);
			}
		}
		else
		{
			if (section) {
				sprintf(out_keyname, "%s_Classes\\VirtualStore\\Machine\\Software\\%s\\%s\\%s", userSID.c_str(), szCompanyName, szAppName, section);
			}
			else {
				sprintf(out_keyname, "%s_Classes\\VirtualStore\\Machine\\Software\\%s\\%s", userSID.c_str(), szCompanyName, szAppName);
			}
		}

		return HKEY_USERS;
	}
	else
	{
		// This will probably fail
		if (section) {
			sprintf(out_keyname, "Software\\%s\\%s\\%s", szCompanyName, szAppName, section);
		}
		else {
			sprintf(out_keyname, "Software\\%s\\%s", szCompanyName, szAppName);
		}

		return HKEY_LOCAL_MACHINE;
	}
#else
	if (section) {
		sprintf(out_keyname, "Software\\%s\\%s\\%s", szCompanyName, szAppName, section);
	}
	else {
		sprintf(out_keyname, "Software\\%s\\%s", szCompanyName, szAppName);
	}

	return HKEY_LOCAL_MACHINE;
#endif
}
bool RocketRenderingInterface::LoadTexture(TextureHandle& texture_handle, Vector2i& texture_dimensions,
                                           const String& source)
{
	GR_DEBUG_SCOPE("libRocket::LoadTexture");
	SCP_string filename;
	int dir_type;
	if (!RocketFileInterface::getCFilePath(source, filename, dir_type)) {
		return false;
	}

	auto period_pos = filename.rfind('.');
	if (period_pos != SCP_string::npos) {
		filename = filename.substr(0, period_pos);
	}

	auto id = bm_load_either(filename.c_str(), nullptr, nullptr, nullptr, false, dir_type);
	if (id < 0) {
		return false;
	}

	int w, h;
	bm_get_info(id, &w, &h);

	texture_dimensions.x = w;
	texture_dimensions.y = h;

	auto* tex   = new Texture();
	tex->handle = id;

	texture_handle = get_texture_handle(tex);

	return true;
}
Beispiel #6
0
void dc_draw(bool show_prompt = FALSE)
{
	gr_clear();
	font::set_font(dc_font);
	gr_set_color_fast( &Color_bright );
	int w;
	gr_get_string_size(&w, nullptr, dc_title.c_str());

	gr_string((gr_screen.clip_width - w) / 2, 3, dc_title.c_str(), GR_RESIZE_NONE );

	gr_set_color_fast( &Color_normal );

	dc_draw_window(show_prompt);

	gr_flip();
}
ParticleEffectIndex parseEffectElement(EffectType forcedType, const SCP_string& name) {
	if (!optional_string("$New Effect")) {
		SCP_string newName;
		stuff_string(newName, F_NAME);

		auto index = ParticleManager::get()->getEffectByName(newName);

		if (index < 0) {
			error_display(0, "Unknown particle effect name '%s' encountered!", newName.c_str());
		}
		if (forcedType != EffectType::Invalid) {
			// Validate the effect type
			auto effect = ParticleManager::get()->getEffect(index);

			if (effect->getType() != forcedType) {
				error_display(0, "Particle effect '%s' has the wrong effect type! Expected %s but was %s!",
							  getEffectTypeName(forcedType), getEffectTypeName(effect->getType()));
			}
		}

		return index;
	}

	if (forcedType == EffectType::Invalid) {
		forcedType = parseEffectType();
	}

	auto effect = constructEffect(name, forcedType);

	return ParticleManager::get()->addEffect(effect);
}
// debug console function called to determine which player to kick
void multi_dcf_kick()
{
	int player_num,idx;
	SCP_string arg;

	// get the callsign of the player to kick
	dc_stuff_string(arg);

	player_num = -1;
	for(idx=0;idx<MAX_PLAYERS;idx++){
		if(MULTI_CONNECTED(Net_players[idx]) && (stricmp(Net_players[idx].m_player->callsign, arg.c_str()) == 0)) {
			player_num = idx;
			break;
		}
	}

	// if we didn't find the player, notify of the results
	if(player_num == -1){
		dc_printf("Could not find player %s to kick!", arg.c_str());
	} 
	// if we found the guy, then try and kick him
	else {
		multi_kick_player(player_num);
	}
}
ParticleEffectIndex parseEffect(const SCP_string& objectName) {
	SCP_string name;
	stuff_string(name, F_NAME);

	auto idx = ParticleManager::get()->getEffectByName(name);

	if (idx < 0) {
		if (objectName.empty()) {
			error_display(0, "Unknown particle effect name '%s' encountered!", name.c_str());
		} else {
			error_display(0, "Unknown particle effect name '%s' encountered while parsing '%s'!", name.c_str(),
						  objectName.c_str());
		}
	}

	return idx;
}
Beispiel #10
0
		void AssertMessage(const char * text, const char * filename, int linenum, const char * format, ...)
		{
			// We only want to display the file name
			filename = clean_filename(filename);

			SCP_stringstream msgStream;
			msgStream << "Assert: \"" << text << "\"\n";
			msgStream << "File: " << filename << "\n";
			msgStream << "Line: " << linenum << "\n";
			
			if (format != nullptr)
			{
				SCP_string buffer;
				va_list args;

				va_start(args, format);
				vsprintf(buffer, format, args);
				va_end(args);

				msgStream << buffer << "\n";
				mprintf(("ASSERTION: \"%s\" at %s:%d\n %s\n", text, filename, linenum, buffer.c_str()));
			}
			else
			{
				// No additional message
				mprintf(("ASSERTION: \"%s\" at %s:%d\n", text, filename, linenum));
			}

			if (running_unittests) {
				throw AssertException(msgStream.str());
			}

			msgStream << "\n";
			msgStream << dump_stacktrace();

			SCP_string messageText = msgStream.str();
			set_clipboard_text(messageText.c_str());

			messageText = truncateLines(msgStream, Messagebox_lines);
			messageText += "\n[ This info is in the clipboard so you can paste it somewhere now ]\n";
			messageText += "\n\nUse Debug to break into Debugger, Exit will close the application.\n";

			Error(messageText.c_str());
		}
void gamesnd_parse_entry(game_snd *gs, bool no_create, SCP_vector<game_snd> *lookupVector)
{
	SCP_string name;

	stuff_string(name, F_NAME, "\t \n");

	if (!no_create)
	{
		if (lookupVector != NULL)
		{
			if (gamesnd_lookup_name(name.c_str(), *lookupVector) >= 0)
			{
				Warning(LOCATION, "Duplicate sound name \"%s\" found!", name.c_str());
			}
		}

		gs->name = name;
	}
	else
	{
		int vectorIndex = gamesnd_lookup_name(name.c_str(), *lookupVector);

		if (vectorIndex < 0)
		{
			Warning(LOCATION, "No existing sound entry with name \"%s\" found!", name.c_str());
			no_create = false;
			gs->name = name;
		}
		else
		{
			gs = &lookupVector->at(vectorIndex);
		}
	}

	if (optional_string("+Filename:"))
	{
		parse_gamesnd_new(gs, no_create);
	}
	else
	{
		parse_gamesnd_old(gs);
	}
}
void opengl::ShaderUniforms::setUniformMatrix4fv(const SCP_string &name, const int count, const matrix4 *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::MATRIX4 && bind_info->count == count) {
			bool equal = true;

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

			if (equal) {
				return;
			}

			resident = true;
			for (int i = 0; i < count; ++i) {
				_uniform_data_matrix4[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_matrix4.push_back(val[i]);
		}

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

		_uniforms.push_back(new_bind);

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

	glUniformMatrix4fv(findUniformLocation(name.c_str()), count, GL_FALSE, (const GLfloat*)val);
}
GLint opengl::ShaderUniforms::findUniformLocation(const SCP_string& name) {
	auto iter = _uniform_locations.find(name);

	if (iter == _uniform_locations.end()) {
		// Lazily initialize the uniform locations when required. This avoids keeping a list of all uniforms in the code
		auto location = glGetUniformLocation(_program->getShaderHandle(), name.c_str());

		if (location == -1)
		{
			// This can happen if the uniform has been optimized out by the driver
			mprintf(("WARNING: Failed to find uniform '%s'.\n", name.c_str()));
		}

		_uniform_locations.insert(std::make_pair(name, location));
		return location;
	}
	else {
		return iter->second;
	}
}
void opengl_uniform_state::setUniformMatrix4fv(const SCP_string &name, const int count, const matrix4 *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::MATRIX4 && bind_info->count == count ) {
			bool equal = true;

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

			if ( equal ) {
				return;
			}

			resident = true;
			for ( int i = 0; i < count; ++i ) {
				uniform_data_matrix4[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_matrix4.push_back(val[i]);
		}

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

		uniforms.push_back(new_bind);

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

	glUniformMatrix4fv(opengl_shader_get_uniform(name.c_str()), count, GL_FALSE, (const GLfloat*)val);
}
Beispiel #15
0
		void Warning(const char* filename, int line, const char* format, ...)
		{
#ifndef NDEBUG
			SCP_string msg;
			va_list args;

			va_start(args, format);
			vsprintf(msg, format, args);
			va_end(args);

			ReleaseWarning(filename, line, "%s", msg.c_str());
#endif
		}
void dc_draw(bool show_prompt = FALSE)
{
	gr_clear();
	gr_set_font(dc_font);
	gr_set_color_fast( &Color_bright );
	gr_string( 0x8000, 3, dc_title.c_str(), GR_RESIZE_NONE );

	gr_set_color_fast( &Color_normal );

	dc_draw_window(show_prompt);

	gr_flip();
}
void outwnd_printf2(const char *format, ...)
{
	SCP_string temp;
	va_list args;

	if (format == NULL)
		return;

	va_start(args, format);
	vsprintf(temp, format, args);
	va_end(args);

	outwnd_print("General", temp.c_str());
}
void dc_draw_cursor( SCP_string &cmd_string, int x, int y )
{
	int t;
	int w, h;	// gr_string width and height

	t = timer_get_fixed_seconds() / (F1_0/3);
	if ( t & 1 ) {
		gr_get_string_size( &w, &h, cmd_string.c_str() );

		w %= (DCOLS * Current_font->w);
		//gr_string( w, debug_y*16, "_" );
		gr_rect((x + (w + 1)), (y + (h + 1)), 2, Current_font->h, GR_RESIZE_NONE);
	}
}
// create a capture buffer with the specified format
// exit:	0	->		buffer created successfully
//			!0	->		error creating the buffer
int dscap_create_buffer(int freq, int bits_per_sample, int nchannels, int nseconds)
{
	ALenum al_format = AL_FORMAT_MONO8;
	ALsizei buf_size = freq * nseconds;

	if ( !dscap_inited ) {
		dscap_init();
	}

	//Just in case we couldn't init for whatever reason
	if ( !dscap_inited ) { //-V581
		return -1;
	}

	Assert( (nchannels == 1) || (nchannels == 2) );
	Assert( (bits_per_sample == 8) || (bits_per_sample == 16) );

	if (nchannels == 1) {
		if (bits_per_sample == 8)  {
			al_format = AL_FORMAT_MONO8;
		} else if (bits_per_sample == 16) {
			al_format = AL_FORMAT_MONO16;
		}
	} else if (nchannels == 2) {
		if (bits_per_sample == 8) {
			al_format = AL_FORMAT_STEREO8;
		} else if (bits_per_sample == 16) {
			al_format = AL_FORMAT_STEREO16;
		}
	}

	const ALCchar *dev_name = (const ALCchar*) capture_dev_name.c_str();
	ds_capture_device = alcCaptureOpenDevice(dev_name, freq, al_format, buf_size);

	if (ds_capture_device == NULL) {
		return -1;
	}

	if ( alcGetError(ds_capture_device) != ALC_NO_ERROR ) {
		return -1;
	}

	ALCaptureInfo.format = al_format;
	ALCaptureInfo.bits_per_sample = bits_per_sample;
	ALCaptureInfo.n_channels = nchannels;
	ALCaptureInfo.samples_per_second = freq;
	ALCaptureInfo.block_align = (nchannels * bits_per_sample) / 8;

	return 0;
}
void outwnd_printf(const char *id, const char *format, ...)
{
	SCP_string temp;
	va_list args;

	if ( (id == NULL) || (format == NULL) )
		return;

	va_start(args, format);
	vsprintf(temp, format, args);
	va_end(args);

	outwnd_print(id, temp.c_str());
}
Beispiel #21
0
void dc_draw_cursor( SCP_string &cmd_string, int x, int y )
{
	int t;
	int w, h;	// gr_string width and height

	t = timer_get_fixed_seconds() / (F1_0/3);
	if ( t & 1 ) {
		gr_get_string_size( &w, &h, cmd_string.c_str() );

		w %= (DCOLS * col_width);
		//gr_string( w, debug_y*16, "_" );
		gr_rect(gr_screen.center_offset_x + (x + (w + 1)), gr_screen.center_offset_y + (y + (h + 1)), 2,
			fl2i(font::get_current_font()->getHeight()), GR_RESIZE_NONE);
	}
}
Beispiel #22
0
		void WarningEx(const char* filename, int line, const char* format, ...)
		{
#ifndef NDEBUG
			if (Cmdline_extra_warn) {
				SCP_string msg;
				va_list args;

				va_start(args, format);
				vsprintf(msg, format, args);
				va_end(args);

				Warning(filename, line, "%s", msg.c_str());
			}
#endif
		}
/*
 * validate that a pilot/player was created with the same language FSO is currently using
 *
 * @param pilots callsign
 * @note not longer needed if intel entry "primary keys" change to a non-translated value
 */
bool valid_pilot_lang(char *callsign)
{
	char pilot_lang[LCL_LANG_NAME_LEN+1], current_lang[LCL_LANG_NAME_LEN+1];
	SCP_string filename = callsign;

	filename += ".plr";
	lcl_get_language_name(current_lang);

	if (Pilot.verify(filename.c_str(), NULL, pilot_lang)) {
		if (!strcmp(current_lang, pilot_lang)) {
			return true;
		}
	}
	return false;
}
// printf function itself called by the ml_printf macro
void ml_printf(const char *format, ...)
{
	SCP_string temp;
	va_list args;

	if (format == NULL) {
		return;
	}
	
	// format the text
	va_start(args, format);
	vsprintf(temp, format, args);
	va_end(args);

	// log the string including the time
	log_string(LOGFILE_MULTI_LOG, temp.c_str(), 1);
}
ParticleEffectIndex ParticleManager::getEffectByName(const SCP_string& name) {
	if (name.empty()) {
		// Don't allow empty names, it's a special case for effects that should not be referenced.
		return -1;
	}

	auto foundIterator = find_if(m_effects.begin(), m_effects.end(),
								 [&name](const std::shared_ptr<ParticleEffect>& ptr) {
									 return !stricmp(ptr->getName().c_str(), name.c_str());
								 });

	if (foundIterator == m_effects.end()) {
		return -1;
	}

	return distance(m_effects.begin(), foundIterator);
}
void opengl::ShaderUniforms::setUniformMatrix4f(const SCP_string &name, const matrix4 &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::MATRIX4 && bind_info->count == 1) {
			if (vm_matrix_equal(_uniform_data_matrix4[bind_info->index], val)) {
				return;
			}

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

	if (!resident) {
		// uniform doesn't exist in our previous uniform block so queue this new value
		//matrix_uniform_data[num_matrix_uniforms] = val;
		//memcpy(&(matrix_uniform_data[num_matrix_uniforms]), &val, sizeof(matrix4));
		_uniform_data_matrix4.push_back(val);
		//	num_matrix_uniforms += 1;

		uniform_bind new_bind;
		new_bind.count = 1;
		new_bind.index = _uniform_data_matrix4.size() - 1;
		//	new_bind.index = num_matrix_uniforms - 1;
		new_bind.type = uniform_bind::MATRIX4;
		new_bind.name = name;

		_uniforms.push_back(new_bind);

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

	glUniformMatrix4fv(findUniformLocation(name.c_str()), 1, GL_FALSE, (const GLfloat*)&val);
}
void opengl_uniform_state::setUniformMatrix4f(const SCP_string &name, const matrix4 &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::MATRIX4 && bind_info->count == 1 ) {
			if ( vm_matrix_equal(uniform_data_matrix4[bind_info->index], val) ) {
				return;
			}

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

	if ( !resident ) {
		// uniform doesn't exist in our previous uniform block so queue this new value
		//matrix_uniform_data[num_matrix_uniforms] = val;
		//memcpy(&(matrix_uniform_data[num_matrix_uniforms]), &val, sizeof(matrix4));
		uniform_data_matrix4.push_back(val);
		//	num_matrix_uniforms += 1;

		uniform_bind new_bind;
		new_bind.count = 1;
		new_bind.index = uniform_data_matrix4.size() - 1;
		//	new_bind.index = num_matrix_uniforms - 1;
		new_bind.type = uniform_bind::MATRIX4;
		new_bind.name = name;

		uniforms.push_back(new_bind);

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

	glUniformMatrix4fv(opengl_shader_get_uniform(name.c_str()), 1, GL_FALSE, (const GLfloat*)&val);
}
void opengl::ShaderUniforms::setUniform4f(const SCP_string &name, const vec4 &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::VEC4) {
			if (vm_vec_equal(_uniform_data_vec4[bind_info->index], val)) {
				// if the values are close enough, pass.
				return;
			}

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

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

		uniform_bind new_bind;

		new_bind.count = 1;
		new_bind.index = _uniform_data_vec4.size() - 1;
		new_bind.type = uniform_bind::VEC4;
		new_bind.name = name;

		_uniforms.push_back(new_bind);

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

	glUniform4f(findUniformLocation(name.c_str()), val.a1d[0], val.a1d[1], val.a1d[2], val.a1d[3]);
}
Beispiel #29
0
	int parse_font()
	{
		int font_idx;

		SCP_string input;
		stuff_string(input, F_NAME);
		SCP_stringstream ss(input);

		int fontNum;
		ss >> fontNum;

		if (ss.fail())
		{
			fontNum = FontManager::getFontIndex(input);

			if (fontNum < 0)
			{
				error_display(0, "Invalid font name \"%s\"!", input.c_str());
				font_idx = -1;
			}
			else
			{
				font_idx = fontNum;
			}
		}
		else
		{
			if (fontNum < 0 || fontNum >= FontManager::numberOfFonts())
			{
				error_display(0, "Invalid font number %d! must be greater or equal to zero and smaller than %d.", fontNum, FontManager::numberOfFonts());
				font_idx = -1;
			}
			else
			{
				font_idx = fontNum;
			}
		}

		return font_idx;
	}
void opengl::ShaderUniforms::setUniformi(const SCP_string &name, const int 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(uniform_index < _uniforms.size());

		uniform_bind *bind_info = &_uniforms[uniform_index];

		if (bind_info->type == uniform_bind::INT) {
			if (_uniform_data_ints[bind_info->index] == val) {
				return;
			}

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

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

		uniform_bind new_bind;

		new_bind.count = 1;
		new_bind.index = _uniform_data_ints.size() - 1;
		new_bind.type = uniform_bind::INT;
		new_bind.name = name;

		_uniforms.push_back(new_bind);

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

	glUniform1i(findUniformLocation(name.c_str()), val);
}