Kill off some usages of c_str.

Also changes some function params, but this is ok.
Some simplifications were also able to be made (ie. killing off strcmps with ==, etc).
This commit is contained in:
Lioncash
2014-03-12 15:33:41 -04:00
parent dccc6d8b47
commit a82675b7d5
170 changed files with 812 additions and 704 deletions

View File

@ -1755,7 +1755,7 @@ namespace GLExtensions
// Public members
u32 Version() { return _GLVersion; }
bool Supports(std::string name)
bool Supports(const std::string& name)
{
return m_extension_list[name];
}

View File

@ -40,7 +40,7 @@ namespace GLExtensions
// Function for checking if the hardware supports an extension
// example: if (GLExtensions::Supports("GL_ARB_multi_map"))
bool Supports(std::string name);
bool Supports(const std::string& name);
// Returns OpenGL version in format 430
u32 Version();

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include "Common/IniFile.h"
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
@ -27,11 +28,9 @@ unsigned int VideoBackend::PeekMessages()
}
// Show the current FPS
void VideoBackend::UpdateFPSDisplay(const char *text)
void VideoBackend::UpdateFPSDisplay(const std::string& text)
{
char temp[100];
snprintf(temp, sizeof temp, "%s | %s | %s", scm_rev_str, GetDisplayName().c_str(), text);
return GLInterface->UpdateFPSDisplay(temp);
return GLInterface->UpdateFPSDisplay(StringFromFormat("%s | %s | %s", scm_rev_str, GetDisplayName().c_str(), text.c_str()));
}
}
@ -48,7 +47,7 @@ void InitInterface()
#endif
}
GLuint OpenGL_CompileProgram ( const char* vertexShader, const char* fragmentShader )
GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShader)
{
// generate objects
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);

View File

@ -133,7 +133,7 @@ void ApplyShader()
// Fallback to shared user dir
path = File::GetSysDirectory() + SHADERS_DIR DIR_SEP + g_ActiveConfig.sPostProcessingShader + ".glsl";
}
if (!File::ReadFileToString(path.c_str(), code)) {
if (!File::ReadFileToString(path, code)) {
ERROR_LOG(VIDEO, "Post-processing shader not found: %s", path.c_str());
return;
}

View File

@ -381,7 +381,7 @@ void ProgramShaderCache::Init(void)
else
{
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX).c_str());
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
char cache_filename[MAX_PATH];
sprintf(cache_filename, "%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),

View File

@ -141,9 +141,12 @@ RasterFont::RasterFont()
glActiveTexture(GL_TEXTURE0+8);
glBindTexture(GL_TEXTURE_2D, texture);
u32* texture_data = new u32[char_width*char_count*char_height];
for (u32 y=0; y<char_height; y++) {
for (u32 c=0; c<char_count; c++) {
for (u32 x=0; x<char_width; x++) {
for (u32 y = 0; y < char_height; y++)
{
for (u32 c = 0; c < char_count; c++)
{
for (u32 x = 0; x < char_width; x++)
{
bool pixel = (0 != (rasters[c][y] & (1<<(char_width-x-1))));
texture_data[char_width*char_count*y+char_width*c+x] = pixel ? -1 : 0;
}
@ -181,10 +184,9 @@ RasterFont::~RasterFont()
s_shader.Destroy();
}
void RasterFont::printMultilineText(const char *text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
void RasterFont::printMultilineText(const std::string& text, double start_x, double start_y, double z, int bbWidth, int bbHeight, u32 color)
{
size_t length = strlen(text);
GLfloat *vertices = new GLfloat[length*6*4];
GLfloat* vertices = new GLfloat[text.length() * 6 * 4];
int usage = 0;
GLfloat delta_x = GLfloat(2*char_width)/GLfloat(bbWidth);
@ -195,22 +197,24 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
GLfloat x = GLfloat(start_x);
GLfloat y = GLfloat(start_y);
for (size_t i=0; i<length; i++) {
u8 c = text[i];
if (c == '\n') {
for (const char& c : text)
{
if (c == '\n')
{
x = GLfloat(start_x);
y -= delta_y + border_y;
continue;
}
// do not print spaces, they can be skipped easily
if (c == ' ') {
if (c == ' ')
{
x += delta_x + border_x;
continue;
}
if (c < char_offset || c >= char_count+char_offset) continue;
if (c < char_offset || c >= char_count+char_offset)
continue;
vertices[usage++] = x;
vertices[usage++] = y;
@ -245,7 +249,8 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
x += delta_x + border_x;
}
if (!usage) {
if (!usage)
{
delete [] vertices;
return;
}
@ -258,7 +263,8 @@ void RasterFont::printMultilineText(const char *text, double start_x, double sta
s_shader.Bind();
if (color != cached_color) {
if (color != cached_color)
{
glUniform4f(uniform_color_id, GLfloat((color>>16)&0xff)/255.f,GLfloat((color>>8)&0xff)/255.f,GLfloat((color>>0)&0xff)/255.f,GLfloat((color>>24)&0xff)/255.f);
cached_color = color;
}

View File

@ -4,6 +4,8 @@
#pragma once
#include <string>
namespace OGL
{
@ -14,7 +16,7 @@ public:
~RasterFont(void);
static int debug;
void printMultilineText(const char *text, double x, double y, double z, int bbWidth, int bbHeight, u32 color);
void printMultilineText(const std::string& text, double x, double y, double z, int bbWidth, int bbHeight, u32 color);
private:
u32 VBO;

View File

@ -5,6 +5,7 @@
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include "Common/Atomic.h"
@ -829,7 +830,7 @@ void Renderer::DrawDebugInfo()
}
}
void Renderer::RenderText(const char *text, int left, int top, u32 color)
void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
{
const int nBackbufferWidth = (int)GLInterface->GetBackBufferWidth();
const int nBackbufferHeight = (int)GLInterface->GetBackBufferHeight();
@ -1436,7 +1437,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
{
OSD::AddMessage(StringFromFormat(
"Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)",
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h).c_str(), 2000);
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h), 2000);
}
}
if (bAVIDumping)
@ -1485,7 +1486,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl
OSD::AddMessage("Error opening framedump.raw for writing.", 2000);
else
{
OSD::AddMessage(StringFromFormat("Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h).c_str(), 2000);
OSD::AddMessage(StringFromFormat("Dumping Frames to \"%s\" (%dx%d RGB24)", movie_file_name.c_str(), w, h), 2000);
}
}
if (pFrameDump)

View File

@ -1,5 +1,6 @@
#pragma once
#include <string>
#include "VideoCommon/RenderBase.h"
namespace OGL
@ -27,8 +28,8 @@ extern struct VideoConfig {
bool bSupportOGL31;
bool bSupportViewportFloat;
const char *gl_vendor;
const char *gl_renderer;
const char* gl_vendor;
const char* gl_renderer;
const char* gl_version;
const char* glsl_version;
@ -60,7 +61,7 @@ public:
void ApplyState(bool bUseDstAlpha) override {}
void RestoreState() override {}
void RenderText(const char* pstr, int left, int top, u32 color) override;
void RenderText(const std::string& text, int left, int top, u32 color) override;
void DrawDebugInfo();
void FlipImageData(u8 *data, int w, int h, int pixel_width = 3);

View File

@ -1,5 +1,6 @@
#pragma once
#include <string>
#include "VideoCommon/VideoBackendBase.h"
namespace OGL
@ -18,7 +19,7 @@ class VideoBackend : public VideoBackendHardware
void ShowConfig(void* parent) override;
void UpdateFPSDisplay(const char*) override;
void UpdateFPSDisplay(const std::string&) override;
unsigned int PeekMessages() override;
};

View File

@ -123,7 +123,7 @@ void GetShaders(std::vector<std::string> &shaders)
File::ScanDirectoryTree(directory, entry);
for (auto& file : entry.children)
{
std::string name = file.virtualName.c_str();
std::string name = file.virtualName;
if (name.size() < 5)
continue;
if (strcasecmp(name.substr(name.size() - 5).c_str(), ".glsl"))
@ -176,7 +176,7 @@ bool VideoBackend::Initialize(void *&window_handle)
frameCount = 0;
g_Config.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_opengl.ini").c_str());
g_Config.Load(File::GetUserPath(D_CONFIG_IDX) + "gfx_opengl.ini");
g_Config.GameIniLoad();
g_Config.UpdateProjectionHack();
g_Config.VerifyValidity();