Skip to content
Permalink
Browse files

MSVC fix gl.GetDefaultShaderSources

  • Loading branch information...
rtri
rtri committed Oct 7, 2019
1 parent 8430fcf commit b9df50beb750b146e7c0e69d7dcfe768abc267c4
Showing with 14 additions and 9 deletions.
  1. +7 −3 rts/Rendering/Shaders/ShaderHandler.cpp
  2. +7 −6 rts/Rendering/Shaders/ShaderHandler.h
@@ -44,13 +44,17 @@ void CShaderHandler::InsertExtProgramObject(const char* name, Shader::IProgramOb

assert(GetExtShaderSources(name) == nullptr);

extProgramObjects.insert(name, prog);
extShaderSources.insert(name, {});
// for RenderDataBuffer shaders, collision freedom is
// guaranteed at compile-time by GetShaderName switch
const unsigned int hash = hashString(name);

extProgramObjects.insert(hash, prog);
extShaderSources.insert(hash, {});

// the attached shader objects may go away later, so make
// copies of their source strings while those still exist
for (const Shader::IShaderObject* shader: prog->GetShaderObjs()) {
extShaderSources[name][ GL::ShaderTypeToEnum(shader->GetType()) ] = shader->GetSrc(false);
extShaderSources[hash][ GL::ShaderTypeToEnum(shader->GetType()) ] = shader->GetSrc(false);
}
}

@@ -6,6 +6,7 @@
#include <string>

#include "Rendering/GL/myGL.h" //GLuint
#include "System/StringHash.h"
#include "System/UnorderedMap.hpp"

namespace Shader {
@@ -19,8 +20,8 @@ class CShaderHandler {
typedef spring::unsynced_map<std::string, Shader::IProgramObject*>::iterator ProgramObjMapIt;
typedef spring::unsynced_map<std::string, ProgramObjMap> ProgramTable;
// indexed by literals
typedef spring::unsynced_map<const char*, std::array<std::string, GL::SHADER_TYPE_CNT>> ExtShaderSourceMap;
typedef spring::unsynced_map<const char*, Shader::IProgramObject*> ExtProgramObjMap;
typedef spring::unsynced_map<unsigned int, std::array<std::string, GL::SHADER_TYPE_CNT>> ExtShaderSourceMap;
typedef spring::unsynced_map<unsigned int, Shader::IProgramObject*> ExtProgramObjMap;

static CShaderHandler* GetInstance();

@@ -40,8 +41,8 @@ class CShaderHandler {

void InsertExtProgramObject(const char* name, Shader::IProgramObject* prog);
void RemoveExtProgramObject(const char* name, Shader::IProgramObject* prog) {
extProgramObjects.erase(name);
extShaderSources.erase(name);
extProgramObjects.erase(hashString(name));
extShaderSources.erase(hashString(name));
}

bool ReleaseProgramObjects(const std::string& poClass, bool persistent = false);
@@ -57,7 +58,7 @@ class CShaderHandler {
Shader::IShaderObject* CreateShaderObject(const std::string& soName, const std::string& soDefs, int soType);

Shader::IProgramObject* GetExtProgramObject(const char* name) {
const auto it = extProgramObjects.find(name);
const auto it = extProgramObjects.find(hashString(name));

if (it == extProgramObjects.end())
return nullptr;
@@ -66,7 +67,7 @@ class CShaderHandler {
}

const std::array<std::string, GL::SHADER_TYPE_CNT>* GetExtShaderSources(const char* name) const {
const auto it = extShaderSources.find(name);
const auto it = extShaderSources.find(hashString(name));

if (it == extShaderSources.end())
return nullptr;

0 comments on commit b9df50b

Please sign in to comment.
You can’t perform that action at this time.