Revert "Revert "glShaderSource should respect length parameter""
This reverts commit 406145dc1eb3bd909b9528d2443ed414570dda24.
The revert also handles negative length as is described in the spec:
https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glShaderSource.xml
Reason for revert: fix it
Change-Id: I2d7ca1ab3c23fc0b36b6e97f510c8e533364249c
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index 783812c..cc009a9 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -1743,8 +1743,22 @@
// Track original sources---they may be translated in the backend
std::vector<std::string> orig_sources;
- for (int i = 0; i < count; i++) {
- orig_sources.push_back(std::string((const char*)(string[i])));
+ if (length) {
+ for (int i = 0; i < count; i++) {
+ // Each element in the length array may contain the length of the corresponding
+ // string (the null character is not counted as part of the string length) or a
+ // value less than 0 to indicate that the string is null terminated.
+ if (length[i] >= 0) {
+ orig_sources.push_back(std::string((const char*)(string[i]),
+ (const char*)(string[i]) + length[i]));
+ } else {
+ orig_sources.push_back(std::string((const char*)(string[i])));
+ }
+ }
+ } else {
+ for (int i = 0; i < count; i++) {
+ orig_sources.push_back(std::string((const char*)(string[i])));
+ }
}
shaderData->sources = orig_sources;