29
29
30
30
#include < Corrade/Containers/Array.h>
31
31
#include < Corrade/Containers/Iterable.h>
32
+ #include < Corrade/Containers/Pair.h>
32
33
#include < Corrade/Containers/StridedArrayView.h>
33
34
#ifndef MAGNUM_TARGET_WEBGL
34
35
#include < Corrade/Containers/String.h>
35
36
#endif
36
37
#include < Corrade/Containers/StringStl.h> /* * @todo remove once <string>-free */
37
38
#include < Corrade/Containers/Reference.h>
39
+ #include < Corrade/Utility/Algorithms.h>
38
40
#include < Corrade/Utility/DebugStl.h>
39
41
40
42
#include " Magnum/GL/Context.h"
@@ -340,7 +342,7 @@ AbstractShaderProgram& AbstractShaderProgram::setLabel(const Containers::StringV
340
342
}
341
343
#endif
342
344
343
- std::pair <bool , std::string > AbstractShaderProgram::validate () {
345
+ Containers::Pair <bool , Containers::String > AbstractShaderProgram::validate () {
344
346
glValidateProgram (_id);
345
347
346
348
/* Check validation status */
@@ -350,12 +352,11 @@ std::pair<bool, std::string> AbstractShaderProgram::validate() {
350
352
351
353
/* Error or warning message. The string is returned null-terminated, scrap
352
354
the \0 at the end afterwards */
353
- std::string message (logLength, ' \n ' );
355
+ Containers::String message (ValueInit, Math::max ( logLength, 1 )- 1 );
354
356
if (message.size () > 1 )
355
357
glGetProgramInfoLog (_id, message.size (), nullptr , &message[0 ]);
356
- message.resize (Math::max (logLength, 1 )-1 );
357
358
358
- return {success, std::move (message)};
359
+ return {bool ( success) , std::move (message)};
359
360
}
360
361
361
362
AbstractShaderProgram& AbstractShaderProgram::draw (Mesh& mesh) {
@@ -554,32 +555,35 @@ void AbstractShaderProgram::bindFragmentDataLocationIndexedInternal(const Unsign
554
555
#endif
555
556
556
557
#ifndef MAGNUM_TARGET_GLES2
557
- void AbstractShaderProgram::setTransformFeedbackOutputs (const Containers::ArrayView<const std::string > outputs, const TransformFeedbackBufferMode bufferMode) {
558
+ void AbstractShaderProgram::setTransformFeedbackOutputs (const Containers::ArrayView<const Containers::String > outputs, const TransformFeedbackBufferMode bufferMode) {
558
559
(this ->*Context::current ().state ().shaderProgram .transformFeedbackVaryingsImplementation )(outputs, bufferMode);
559
560
}
560
561
561
- void AbstractShaderProgram::setTransformFeedbackOutputs (const std::initializer_list<std::string > outputs, const TransformFeedbackBufferMode bufferMode) {
562
+ void AbstractShaderProgram::setTransformFeedbackOutputs (const std::initializer_list<Containers::String > outputs, const TransformFeedbackBufferMode bufferMode) {
562
563
setTransformFeedbackOutputs (Containers::arrayView (outputs), bufferMode);
563
564
}
564
565
565
- void AbstractShaderProgram::transformFeedbackVaryingsImplementationDefault (const Containers::ArrayView<const std::string > outputs, const TransformFeedbackBufferMode bufferMode) {
566
+ void AbstractShaderProgram::transformFeedbackVaryingsImplementationDefault (const Containers::ArrayView<const Containers::String > outputs, const TransformFeedbackBufferMode bufferMode) {
566
567
/* * @todo VLAs */
567
568
Containers::Array<const char *> names{outputs.size ()};
568
569
569
570
Int i = 0 ;
570
- for (const std::string & output: outputs) names[i++] = output.data ();
571
+ for (const Containers::String & output: outputs) names[i++] = output.data ();
571
572
572
573
glTransformFeedbackVaryings (_id, outputs.size (), names, GLenum (bufferMode));
573
574
}
574
575
575
576
#ifdef CORRADE_TARGET_WINDOWS
576
- void AbstractShaderProgram::transformFeedbackVaryingsImplementationDanglingWorkaround (const Containers::ArrayView<const std::string > outputs, const TransformFeedbackBufferMode bufferMode) {
577
+ void AbstractShaderProgram::transformFeedbackVaryingsImplementationDanglingWorkaround (const Containers::ArrayView<const Containers::String > outputs, const TransformFeedbackBufferMode bufferMode) {
577
578
/* NVidia on Windows doesn't copy the names when calling
578
579
glTransformFeedbackVaryings() so it then fails at link time because the
579
580
char* are dangling. We have to do the copy on the engine side and keep
580
581
the values until link time (which can happen any time and multiple
581
582
times, so basically for the remaining lifetime of the shader program) */
582
- _transformFeedbackVaryingNames.assign (outputs.begin (), outputs.end ());
583
+ _transformFeedbackVaryingNames =
584
+ Containers::Array<Containers::String>{ValueInit, outputs.size ()};
585
+ for (size_t i = 0 ; i < outputs.size (); ++i)
586
+ _transformFeedbackVaryingNames[i] = outputs[i];
583
587
584
588
transformFeedbackVaryingsImplementationDefault ({_transformFeedbackVaryingNames.data (), _transformFeedbackVaryingNames.size ()}, bufferMode);
585
589
}
@@ -608,10 +612,9 @@ bool AbstractShaderProgram::checkLink(const Containers::Iterable<Shader>& shader
608
612
609
613
/* Error or warning message. The string is returned null-terminated,
610
614
strip the \0 at the end afterwards. */
611
- std::string message (logLength, ' \n ' );
615
+ Containers::String message (ValueInit, Math::max ( logLength, 1 )- 1 );
612
616
if (message.size () > 1 )
613
617
glGetProgramInfoLog (_id, message.size (), nullptr , &message[0 ]);
614
- message.resize (Math::max (logLength, 1 )-1 );
615
618
616
619
/* Some drivers are chatty and can't keep shut when there's nothing to
617
620
be said, handle that as well. */
@@ -655,16 +658,16 @@ bool AbstractShaderProgram::isLinkFinished() {
655
658
return success == GL_TRUE;
656
659
}
657
660
658
- void AbstractShaderProgram::cleanLogImplementationNoOp (std::string &) {}
661
+ void AbstractShaderProgram::cleanLogImplementationNoOp (Containers::String &) {}
659
662
660
663
#if defined(CORRADE_TARGET_WINDOWS) && !defined(MAGNUM_TARGET_GLES)
661
- void AbstractShaderProgram::cleanLogImplementationIntelWindows (std::string & message) {
664
+ void AbstractShaderProgram::cleanLogImplementationIntelWindows (Containers::String & message) {
662
665
if (message == " No errors.\n " ) message = {};
663
666
}
664
667
#endif
665
668
666
669
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_WEBGL)
667
- void AbstractShaderProgram::cleanLogImplementationAngle (std::string & message) {
670
+ void AbstractShaderProgram::cleanLogImplementationAngle (Containers::String & message) {
668
671
if (message == " \n " ) message = {};
669
672
}
670
673
#endif
@@ -676,15 +679,15 @@ void AbstractShaderProgram::completionStatusImplementationFallback(GLuint, GLenu
676
679
Int AbstractShaderProgram::uniformLocationInternal (const Containers::ArrayView<const char > name) {
677
680
const GLint location = glGetUniformLocation (_id, name);
678
681
if (location == -1 )
679
- Warning{} << " GL::AbstractShaderProgram: location of uniform \' " << Debug::nospace << std::string {name, name.size ()} << Debug::nospace << " \' cannot be retrieved" ;
682
+ Warning{} << " GL::AbstractShaderProgram: location of uniform \' " << Debug::nospace << Containers::String {name, name.size ()} << Debug::nospace << " \' cannot be retrieved" ;
680
683
return location;
681
684
}
682
685
683
686
#ifndef MAGNUM_TARGET_GLES2
684
687
UnsignedInt AbstractShaderProgram::uniformBlockIndexInternal (const Containers::ArrayView<const char > name) {
685
688
const GLuint index = glGetUniformBlockIndex (_id, name);
686
689
if (index == GL_INVALID_INDEX)
687
- Warning{} << " GL::AbstractShaderProgram: index of uniform block \' " << Debug::nospace << std::string {name, name.size ()} << Debug::nospace << " \' cannot be retrieved" ;
690
+ Warning{} << " GL::AbstractShaderProgram: index of uniform block \' " << Debug::nospace << Containers::String {name, name.size ()} << Debug::nospace << " \' cannot be retrieved" ;
688
691
return index ;
689
692
}
690
693
#endif
0 commit comments