mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
gobj: slightly more efficient string handling in Shader::make()
This commit is contained in:
parent
1cada85e6b
commit
fe3dab192f
@ -694,9 +694,9 @@ read_datagram(DatagramIterator &scan) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
INLINE Shader::ShaderFile::
|
INLINE Shader::ShaderFile::
|
||||||
ShaderFile(const string &shared) :
|
ShaderFile(string shared) :
|
||||||
_separate(false),
|
_separate(false),
|
||||||
_shared(shared)
|
_shared(move(shared))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -704,17 +704,14 @@ ShaderFile(const string &shared) :
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
INLINE Shader::ShaderFile::
|
INLINE Shader::ShaderFile::
|
||||||
ShaderFile(const string &vertex,
|
ShaderFile(string vertex, string fragment, string geometry,
|
||||||
const string &fragment,
|
string tess_control, string tess_evaluation) :
|
||||||
const string &geometry,
|
|
||||||
const string &tess_control,
|
|
||||||
const string &tess_evaluation) :
|
|
||||||
_separate(true),
|
_separate(true),
|
||||||
_vertex(vertex),
|
_vertex(move(vertex)),
|
||||||
_fragment(fragment),
|
_fragment(move(fragment)),
|
||||||
_geometry(geometry),
|
_geometry(move(geometry)),
|
||||||
_tess_control(tess_control),
|
_tess_control(move(tess_control)),
|
||||||
_tess_evaluation(tess_evaluation)
|
_tess_evaluation(move(tess_evaluation))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3179,7 +3179,7 @@ load_compute(ShaderLanguage lang, const Filename &fn) {
|
|||||||
* Loads the shader, using the string as shader body.
|
* Loads the shader, using the string as shader body.
|
||||||
*/
|
*/
|
||||||
PT(Shader) Shader::
|
PT(Shader) Shader::
|
||||||
make(const string &body, ShaderLanguage lang) {
|
make(string body, ShaderLanguage lang) {
|
||||||
if (lang == SL_GLSL) {
|
if (lang == SL_GLSL) {
|
||||||
shader_cat.error()
|
shader_cat.error()
|
||||||
<< "GLSL shaders must have separate shader bodies!\n";
|
<< "GLSL shaders must have separate shader bodies!\n";
|
||||||
@ -3197,7 +3197,7 @@ make(const string &body, ShaderLanguage lang) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ShaderFile sbody(body);
|
ShaderFile sbody(move(body));
|
||||||
|
|
||||||
if (cache_generated_shaders) {
|
if (cache_generated_shaders) {
|
||||||
ShaderTable::const_iterator i = _make_table.find(sbody);
|
ShaderTable::const_iterator i = _make_table.find(sbody);
|
||||||
@ -3208,7 +3208,7 @@ make(const string &body, ShaderLanguage lang) {
|
|||||||
|
|
||||||
PT(Shader) shader = new Shader(lang);
|
PT(Shader) shader = new Shader(lang);
|
||||||
shader->_filename = ShaderFile("created-shader");
|
shader->_filename = ShaderFile("created-shader");
|
||||||
shader->_text = sbody;
|
shader->_text = move(sbody);
|
||||||
|
|
||||||
#ifdef HAVE_CG
|
#ifdef HAVE_CG
|
||||||
if (lang == SL_Cg) {
|
if (lang == SL_Cg) {
|
||||||
@ -3223,7 +3223,7 @@ make(const string &body, ShaderLanguage lang) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (cache_generated_shaders) {
|
if (cache_generated_shaders) {
|
||||||
_make_table[sbody] = shader;
|
_make_table[shader->_text] = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dump_generated_shaders) {
|
if (dump_generated_shaders) {
|
||||||
@ -3235,7 +3235,7 @@ make(const string &body, ShaderLanguage lang) {
|
|||||||
|
|
||||||
pofstream s;
|
pofstream s;
|
||||||
s.open(fn.c_str(), ios::out | ios::trunc);
|
s.open(fn.c_str(), ios::out | ios::trunc);
|
||||||
s << body;
|
s << shader->get_text();
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
return shader;
|
return shader;
|
||||||
@ -3245,9 +3245,8 @@ make(const string &body, ShaderLanguage lang) {
|
|||||||
* Loads the shader, using the strings as shader bodies.
|
* Loads the shader, using the strings as shader bodies.
|
||||||
*/
|
*/
|
||||||
PT(Shader) Shader::
|
PT(Shader) Shader::
|
||||||
make(ShaderLanguage lang, const string &vertex, const string &fragment,
|
make(ShaderLanguage lang, string vertex, string fragment, string geometry,
|
||||||
const string &geometry, const string &tess_control,
|
string tess_control, string tess_evaluation) {
|
||||||
const string &tess_evaluation) {
|
|
||||||
#ifndef HAVE_CG
|
#ifndef HAVE_CG
|
||||||
if (lang == SL_Cg) {
|
if (lang == SL_Cg) {
|
||||||
shader_cat.error() << "Support for Cg shaders is not enabled.\n";
|
shader_cat.error() << "Support for Cg shaders is not enabled.\n";
|
||||||
@ -3260,7 +3259,8 @@ make(ShaderLanguage lang, const string &vertex, const string &fragment,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderFile sbody(vertex, fragment, geometry, tess_control, tess_evaluation);
|
ShaderFile sbody(move(vertex), move(fragment), move(geometry),
|
||||||
|
move(tess_control), move(tess_evaluation));
|
||||||
|
|
||||||
if (cache_generated_shaders) {
|
if (cache_generated_shaders) {
|
||||||
ShaderTable::const_iterator i = _make_table.find(sbody);
|
ShaderTable::const_iterator i = _make_table.find(sbody);
|
||||||
@ -3271,7 +3271,7 @@ make(ShaderLanguage lang, const string &vertex, const string &fragment,
|
|||||||
|
|
||||||
PT(Shader) shader = new Shader(lang);
|
PT(Shader) shader = new Shader(lang);
|
||||||
shader->_filename = ShaderFile("created-shader");
|
shader->_filename = ShaderFile("created-shader");
|
||||||
shader->_text = sbody;
|
shader->_text = move(sbody);
|
||||||
|
|
||||||
#ifdef HAVE_CG
|
#ifdef HAVE_CG
|
||||||
if (lang == SL_Cg) {
|
if (lang == SL_Cg) {
|
||||||
@ -3284,7 +3284,7 @@ make(ShaderLanguage lang, const string &vertex, const string &fragment,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (cache_generated_shaders) {
|
if (cache_generated_shaders) {
|
||||||
_make_table[sbody] = shader;
|
_make_table[shader->_text] = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shader;
|
return shader;
|
||||||
@ -3294,7 +3294,7 @@ make(ShaderLanguage lang, const string &vertex, const string &fragment,
|
|||||||
* Loads the compute shader from the given string.
|
* Loads the compute shader from the given string.
|
||||||
*/
|
*/
|
||||||
PT(Shader) Shader::
|
PT(Shader) Shader::
|
||||||
make_compute(ShaderLanguage lang, const string &body) {
|
make_compute(ShaderLanguage lang, string body) {
|
||||||
if (lang != SL_GLSL) {
|
if (lang != SL_GLSL) {
|
||||||
shader_cat.error()
|
shader_cat.error()
|
||||||
<< "Only GLSL compute shaders are currently supported.\n";
|
<< "Only GLSL compute shaders are currently supported.\n";
|
||||||
@ -3303,7 +3303,7 @@ make_compute(ShaderLanguage lang, const string &body) {
|
|||||||
|
|
||||||
ShaderFile sbody;
|
ShaderFile sbody;
|
||||||
sbody._separate = true;
|
sbody._separate = true;
|
||||||
sbody._compute = body;
|
sbody._compute = move(body);
|
||||||
|
|
||||||
if (cache_generated_shaders) {
|
if (cache_generated_shaders) {
|
||||||
ShaderTable::const_iterator i = _make_table.find(sbody);
|
ShaderTable::const_iterator i = _make_table.find(sbody);
|
||||||
@ -3314,10 +3314,10 @@ make_compute(ShaderLanguage lang, const string &body) {
|
|||||||
|
|
||||||
PT(Shader) shader = new Shader(lang);
|
PT(Shader) shader = new Shader(lang);
|
||||||
shader->_filename = ShaderFile("created-shader");
|
shader->_filename = ShaderFile("created-shader");
|
||||||
shader->_text = sbody;
|
shader->_text = move(sbody);
|
||||||
|
|
||||||
if (cache_generated_shaders) {
|
if (cache_generated_shaders) {
|
||||||
_make_table[sbody] = shader;
|
_make_table[shader->_text] = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shader;
|
return shader;
|
||||||
|
@ -84,7 +84,7 @@ PUBLISHED:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static PT(Shader) load(const Filename &file, ShaderLanguage lang = SL_none);
|
static PT(Shader) load(const Filename &file, ShaderLanguage lang = SL_none);
|
||||||
static PT(Shader) make(const string &body, ShaderLanguage lang = SL_none);
|
static PT(Shader) make(string body, ShaderLanguage lang = SL_none);
|
||||||
static PT(Shader) load(ShaderLanguage lang,
|
static PT(Shader) load(ShaderLanguage lang,
|
||||||
const Filename &vertex, const Filename &fragment,
|
const Filename &vertex, const Filename &fragment,
|
||||||
const Filename &geometry = "",
|
const Filename &geometry = "",
|
||||||
@ -92,11 +92,11 @@ PUBLISHED:
|
|||||||
const Filename &tess_evaluation = "");
|
const Filename &tess_evaluation = "");
|
||||||
static PT(Shader) load_compute(ShaderLanguage lang, const Filename &fn);
|
static PT(Shader) load_compute(ShaderLanguage lang, const Filename &fn);
|
||||||
static PT(Shader) make(ShaderLanguage lang,
|
static PT(Shader) make(ShaderLanguage lang,
|
||||||
const string &vertex, const string &fragment,
|
string vertex, string fragment,
|
||||||
const string &geometry = "",
|
string geometry = "",
|
||||||
const string &tess_control = "",
|
string tess_control = "",
|
||||||
const string &tess_evaluation = "");
|
string tess_evaluation = "");
|
||||||
static PT(Shader) make_compute(ShaderLanguage lang, const string &body);
|
static PT(Shader) make_compute(ShaderLanguage lang, string body);
|
||||||
|
|
||||||
INLINE Filename get_filename(ShaderType type = ST_none) const;
|
INLINE Filename get_filename(ShaderType type = ST_none) const;
|
||||||
INLINE void set_filename(ShaderType type, const Filename &filename);
|
INLINE void set_filename(ShaderType type, const Filename &filename);
|
||||||
@ -464,12 +464,9 @@ public:
|
|||||||
class ShaderFile : public ReferenceCount {
|
class ShaderFile : public ReferenceCount {
|
||||||
public:
|
public:
|
||||||
INLINE ShaderFile() {};
|
INLINE ShaderFile() {};
|
||||||
INLINE ShaderFile(const string &shared);
|
INLINE ShaderFile(string shared);
|
||||||
INLINE ShaderFile(const string &vertex,
|
INLINE ShaderFile(string vertex, string fragment, string geometry,
|
||||||
const string &fragment,
|
string tess_control, string tess_evaluation);
|
||||||
const string &geometry,
|
|
||||||
const string &tess_control,
|
|
||||||
const string &tess_evaluation);
|
|
||||||
|
|
||||||
INLINE void write_datagram(Datagram &dg) const;
|
INLINE void write_datagram(Datagram &dg) const;
|
||||||
INLINE void read_datagram(DatagramIterator &source);
|
INLINE void read_datagram(DatagramIterator &source);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user