void shader::compile( void ) { glCompileShader( _shader ); GLint res; glGetShaderiv( _shader, GL_COMPILE_STATUS, &res ); if ( res == GL_FALSE ) { GLint len = 0; glGetShaderiv( _shader, GL_SHADER_SOURCE_LENGTH, &len ); std::string source( static_cast<size_t>( len ), '\0' ); glGetShaderSource( _shader, len, nullptr, &source[0] ); std::cerr << "Compile error in:\n" << source << std::endl; throw std::runtime_error( log() ); } else { std::string l = base::trim( log() ); if ( !l.empty() ) { GLint len = 0; glGetShaderiv( _shader, GL_SHADER_SOURCE_LENGTH, &len ); std::string source( static_cast<size_t>( len + 1 ), '\0' ); glGetShaderSource( _shader, len+1, nullptr, &source[0] ); std::clog << "========================================" << std::endl; std::clog << "Compile warning:\n" << source << std::endl; std::clog << "----------------------------------------" << std::endl; std::clog << l << std::endl; std::clog << "========================================" << std::endl; } } }
void Shader::DebugPrintSources() { char buf[16384]; glGetShaderSource(vertexID, 16384, NULL, buf); printf("%s\n", buf); glGetShaderSource(fragmentID, 16384, NULL, buf); printf("%s\n", buf); }
static void dumpShaderObj(JSONWriter &json, GLhandleARB shaderObj) { if (!shaderObj) { return; } GLint shader_type = 0; glGetObjectParameterivARB(shaderObj, GL_OBJECT_TYPE_ARB, &shader_type); if (!shader_type) { return; } GLint source_length = 0; glGetObjectParameterivARB(shaderObj, GL_OBJECT_SHADER_SOURCE_LENGTH_ARB, &source_length); if (!source_length) { return; } GLcharARB *source = new GLcharARB[source_length]; GLsizei length = 0; source[0] = 0; glGetShaderSource(shaderObj, source_length, &length, source); json.beginMember(enumToString(shader_type)); json.writeString(source); json.endMember(); delete [] source; }
static void dumpShader(JSONWriter &json, GLuint shader) { if (!shader) { return; } GLint shader_type = 0; glGetShaderiv(shader, GL_SHADER_TYPE, &shader_type); if (!shader_type) { return; } GLint source_length = 0; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &source_length); if (!source_length) { return; } GLchar *source = new GLchar[source_length]; GLsizei length = 0; source[0] = 0; glGetShaderSource(shader, source_length, &length, source); json.beginMember(enumToString(shader_type)); json.writeString(source); json.endMember(); delete [] source; }
const std::string BasicShader::source() const { GLint len = 0; glGetShaderiv(mName, GL_SHADER_SOURCE_LENGTH, &len); std::unique_ptr<GLchar[]> data(new GLchar[len]); glGetShaderSource(mName, len, nullptr, data.get()); return std::string(data.get()); }
void Shader::extractSource(std::string& source) const { GlError error; source.clear(); if (_shaderId == 0) { return; } GLint sourceLength = 0; glGetShaderiv(_shaderId, GL_SHADER_SOURCE_LENGTH, &sourceLength); if (error.hasOccured()) { std::cerr << error.toString("Error while retrieving shader source length (glGetShaderiv(_shaderId, GL_SHADER_SOURCE_LENGTH, sourceLength))") << std::endl; } if (sourceLength == 0) { return; } GLchar* sourceBuffer = new GLchar[sourceLength]; glGetShaderSource(_shaderId, sourceLength, NULL, sourceBuffer); if (error.hasOccured()) { std::cerr << error.toString("Error while retrieving shader source (glGetShaderSource)") << std::endl; } else { source = sourceBuffer; } delete[] sourceBuffer; }
bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source) { GLint status; if (!source) { return false; } const GLchar *sources[] = { #if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT (type == GL_VERTEX_SHADER ? "precision mediump float;\n precision mediump int;\n" : "precision mediump float;\n precision mediump int;\n"), #elif (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && CC_TARGET_PLATFORM != CC_PLATFORM_LINUX && CC_TARGET_PLATFORM != CC_PLATFORM_MAC) (type == GL_VERTEX_SHADER ? "precision highp float;\n precision highp int;\n" : "precision mediump float;\n precision mediump int;\n"), #endif "uniform mat4 CC_PMatrix;\n" "uniform mat4 CC_MVMatrix;\n" "uniform mat4 CC_MVPMatrix;\n" "uniform mat3 CC_NormalMatrix;\n" "uniform vec4 CC_Time;\n" "uniform vec4 CC_SinTime;\n" "uniform vec4 CC_CosTime;\n" "uniform vec4 CC_Random01;\n" "uniform sampler2D CC_Texture0;\n" "uniform sampler2D CC_Texture1;\n" "uniform sampler2D CC_Texture2;\n" "uniform sampler2D CC_Texture3;\n" "//CC INCLUDES END\n\n", source, }; *shader = glCreateShader(type); glShaderSource(*shader, sizeof(sources)/sizeof(*sources), sources, nullptr); glCompileShader(*shader); glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); if (! status) { GLsizei length; glGetShaderiv(*shader, GL_SHADER_SOURCE_LENGTH, &length); GLchar* src = (GLchar *)malloc(sizeof(GLchar) * length); glGetShaderSource(*shader, length, nullptr, src); CCLOG("cocos2d: ERROR: Failed to compile shader:\n%s", src); if (type == GL_VERTEX_SHADER) { CCLOG("cocos2d: %s", getVertexShaderLog().c_str()); } else { CCLOG("cocos2d: %s", getFragmentShaderLog().c_str()); } free(src); return false;; } return (status == GL_TRUE); }
static void getShaderSource(ShaderMap &shaderMap, GLuint shader) { if (!shader) { return; } GLint shader_type = 0; glGetShaderiv(shader, GL_SHADER_TYPE, &shader_type); if (!shader_type) { return; } GLint source_length = 0; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &source_length); if (!source_length) { return; } GLchar *source = new GLchar[source_length]; GLsizei length = 0; source[0] = 0; glGetShaderSource(shader, source_length, &length, source); shaderMap[enumToString(shader_type)] += source; delete [] source; }
void print_shader_log(GLuint shader) { GLint loglen = 0; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &loglen); char *info_log = malloc(loglen+1); info_log[0] = '\x00'; info_log[loglen] = '\x00'; glGetShaderInfoLog(shader, loglen, NULL, info_log); GLint srclen = 0; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &srclen); char *src = malloc(srclen+1); src[0] = '\x00'; src[srclen] = '\x00'; glGetShaderSource(shader, srclen, NULL, src); // Walk shader log char *v = info_log; while(*v != '\x00') { char *f = strchr(v, '\n'); if(f == NULL) f = v+strlen(v); int is_ln = (*f == '\n'); if(is_ln) *f = '\x00'; int n_file = 0; int n_line = 0; int n_chr = 0; sscanf(v, "%d:%d(%d)", &n_file, &n_line, &n_chr); // Intel sscanf(v, "%d(%d)", &n_file, &n_line); // nVidia sscanf(v, "ERROR: %d:%d:", &n_file, &n_line); // ATI (XXX: confirm it works) char *s = src; int i; for(i = 1; i < n_line && s != NULL; i++) { s = strchr(s, '\n'); if(s != NULL) s++; } char *sf = strchr(s, '\n'); if(sf == NULL) sf = s+strlen(s); int is_sln = (*sf == '\n'); if(is_sln) *sf = '\x00'; printf("\x1B[1m%s\x1B[0m\n", v); printf("%s\n\n", s); if(is_sln) *sf = '\n'; if(is_ln) *f = '\n'; if(is_ln) f++; v = f; } printf("\n"); free(info_log); }
std::string Shader::getSource() const { GLint sourceLength = get(GL_SHADER_SOURCE_LENGTH); std::vector<char> source(sourceLength); glGetShaderSource(id(), sourceLength, nullptr, source.data()); return std::string(source.data(), sourceLength); }
std::string Shader::getSource() const { GLint sourceLength; glGetShaderiv( getGLId(), GL_SHADER_SOURCE_LENGTH, &sourceLength ); std::vector<char> source( sourceLength ); glGetShaderSource( getGLId(), sourceLength, nullptr, source.data() ); return( source.data() ); }
/** * Create a new shader on the gpu * @param name Name of the asset * @param data Data of the texture file * @param size Size of data */ Shader::Shader(std::string pName, std::string pSrc) { _name = pName; if (_name.find(".vs") != std::string::npos) _type = GL_VERTEX_SHADER; else if (_name.find(".fs") != std::string::npos) _type = GL_FRAGMENT_SHADER; else if (_name.find(".gs") != std::string::npos) _type = GL_GEOMETRY_SHADER; else if (_name.find(".cs") != std::string::npos) _type = GL_COMPUTE_SHADER; else if (_name.find(".tcs") != std::string::npos) _type = GL_TESS_CONTROL_SHADER; else if (_name.find(".tes") != std::string::npos) _type = GL_TESS_EVALUATION_SHADER; else throw Exception("No shader type found"); GLuint tempShader = glCreateShader(_type); const char* tempSrcAR = pSrc.c_str(); glShaderSource(tempShader, 1, &tempSrcAR, nullptr); glCompileShader(tempShader); GLint compileStatus = 0; GLint logSize = 0; GLsizei length = 0; GLchar* logAR; glGetShaderiv(tempShader, GL_COMPILE_STATUS, &compileStatus); if (compileStatus != (GLint)GL_TRUE) { glGetShaderiv(tempShader, GL_SHADER_SOURCE_LENGTH, &logSize); logAR = new GLchar[logSize]; glGetShaderSource(tempShader, logSize, &length, logAR); Log("Shader " + _name + " source : "); Log(ToString(logAR)); delete[] logAR; glGetShaderiv(tempShader, GL_INFO_LOG_LENGTH, &logSize); logAR = new GLchar[logSize]; glGetShaderInfoLog(tempShader, logSize, &length, logAR); Log("Shader " + _name + " compile log : "); Log(ToString(logAR)); delete[] logAR; throw Exception("Shader " + _name + " did not compile , see log above"); } _shader = tempShader; CheckGLError(); }
bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source, const std::string& compileTimeHeaders, const std::string& convertedDefines) { GLint status; if (!source) { return false; } std::string headersDef; if (compileTimeHeaders.empty()) { #if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT headersDef = (type == GL_VERTEX_SHADER ? "precision mediump float;\n precision mediump int;\n" : "precision mediump float;\n precision mediump int;\n"); #elif (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32 && CC_TARGET_PLATFORM != CC_PLATFORM_LINUX && CC_TARGET_PLATFORM != CC_PLATFORM_MAC) headersDef = (type == GL_VERTEX_SHADER ? "precision highp float;\n precision highp int;\n" : "precision mediump float;\n precision mediump int;\n"); #endif }else{ headersDef = compileTimeHeaders; } const GLchar *sources[] = { headersDef.c_str(), COCOS2D_SHADER_UNIFORMS, convertedDefines.c_str(), source}; *shader = glCreateShader(type); glShaderSource(*shader, sizeof(sources)/sizeof(*sources), sources, nullptr); glCompileShader(*shader); glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); if (! status) { GLsizei length; glGetShaderiv(*shader, GL_SHADER_SOURCE_LENGTH, &length); GLchar* src = (GLchar *)malloc(sizeof(GLchar) * length); glGetShaderSource(*shader, length, nullptr, src); CCLOG("cocos2d: ERROR: Failed to compile shader:\n%s", src); if (type == GL_VERTEX_SHADER) { CCLOG("cocos2d: %s", getVertexShaderLog().c_str()); } else { CCLOG("cocos2d: %s", getFragmentShaderLog().c_str()); } free(src); return false; } return (status == GL_TRUE); }
String8& Program::dumpShader(String8& result, GLenum /*type*/) { GLuint shader = GL_FRAGMENT_SHADER ? mFragmentShader : mVertexShader; GLint l; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &l); char* src = new char[l]; glGetShaderSource(shader, l, NULL, src); result.append(src); delete [] src; return result; }
::String getShaderSource(int id) { int len = 0; glGetShaderiv(id, GL_SHADER_SOURCE_LENGTH, &len); if (len == 0) return null(); char *buf = new char[len+1]; glGetShaderSource(id, len+1, 0, buf); ::String result(buf); delete [] buf; return result; }
/** Retrieve shader source. * @param [out] out Character buffer where the source code will be stored. * @param [in] outSize Character buffer size in bytes. * @param [out] length Source code length. * @return true if the shader source code was successfully retrieved. */ bool Shader::getSource(char* out, size_t outSize, size_t& length) const { if(0 == _id) { return false; } GLsizei sourceLength; glGetShaderSource(_id, outSize, &sourceLength, out); length = static_cast<size_t>(sourceLength); return true; }
std::string Shader::getSource() const { GLint source_length; glGetShaderiv(m_shader, GL_SHADER_SOURCE_LENGTH, &source_length); auto buff = std::make_unique<char[]>(source_length); glGetShaderSource(m_shader, source_length, NULL, buff.get()); return buff.get(); }
static PyObject* py_glGetShaderSource(PyObject *, PyObject *args) { CHECK_ARG_COUNT(args, 1); Uint shader(PyTuple_GetItem(args, 0)); GLint len=0; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &len); //GLchar *src = new GLchar[len+1]; Array1D<Char> src(len+1); glGetShaderSource(shader, len, NULL, src); return PyString_FromString(src); //delete[] src; }
void myShowShader(GLuint shader) { GLint len = 0; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &len); char * buf = new char[len]; glGetShaderSource(shader, len, nullptr, buf); print(buf); delete [] buf; }
_JATTA_EXPORT Jatta::String Jatta::OpenGL::Shader::GetSource() { GLint size; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &size); GLCHECK("Failed to get shader source length."); GLsizei length; GLchar* buffer = new GLchar[size]; glGetShaderSource(shader, (GLsizei)size, &length, buffer); GLCHECK("Failed to get shader source."); String source((char*)buffer); delete[] buffer; return source; }
int gl_GetShaderSource(State & state){ GLuint shaderID = (GLuint)state.stack->to<int>(1); GLint maxLength; GLsizei length; glGetShaderiv(shaderID, GL_SHADER_SOURCE_LENGTH, &maxLength); GLchar * src = new char[maxLength]; glGetShaderSource(shaderID, maxLength, &length, src); state.stack->pushLString(src, length); delete[] src; return 1; }
/* void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source ) */ static jstring android_glGetShaderSource(JNIEnv *_env, jobject, jint shader) { GLint shaderLen = 0; glGetShaderiv((GLuint)shader, GL_SHADER_SOURCE_LENGTH, &shaderLen); if (!shaderLen) { return _env->NewStringUTF(""); } char* buf = (char*) malloc(shaderLen); if (buf == NULL) { jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory"); return NULL; } glGetShaderSource(shader, shaderLen, NULL, buf); jstring result = _env->NewStringUTF(buf); free(buf); return result; }
Handle<Value> GLESglGetShaderSourceCallback(const Arguments& args) { if (args.Length() != 1) return v8::Undefined(); //get arguments unsigned shader = args[0]->Uint32Value(); //query string length int len = 0; glGetShaderiv((GLuint)shader, GL_SHADER_SOURCE_LENGTH, &len); char* log = new char[len]; glGetShaderSource((GLuint)shader, (GLsizei)len, NULL, log); return String::New(log); }
WebString WebGraphicsContext3DDefaultImpl::getShaderSource(WebGLId shader) { makeContextCurrent(); GLint logLength; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength); if (!logLength) return WebString(); GLchar* log = 0; if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log)) return WebString(); GLsizei returnedLogLength; glGetShaderSource(shader, logLength, &returnedLogLength, log); ASSERT(logLength == returnedLogLength + 1); WebString res = WebString::fromUTF8(log, returnedLogLength); fastFree(log); return res; }
std::string GL3ShaderObjectProvider::get_shader_source() const { OpenGL::set_active(); std::string result; GLsizei buffer_size = 16 * 1024; while (buffer_size < 2 * 1024 * 1024) { auto shader_source = new GLchar[buffer_size]; GLsizei length = 0; glGetShaderSource(handle, buffer_size, &length, shader_source); if (length < buffer_size - 1) result = std::string(shader_source, length); delete[] shader_source; if (length < buffer_size - 1) break; buffer_size *= 2; } return result; }
String GraphicsContext3D::getShaderSource(Platform3DObject shader) { makeContextCurrent(); GLint length = 0; glGetShaderiv(shader, GraphicsContext3D::SHADER_SOURCE_LENGTH, &length); GLsizei size = 0; GLchar* info = (GLchar*) fastMalloc(length); if (!info) return ""; glGetShaderSource(shader, length, &size, info); String result(info); fastFree(info); return result; }
// DOMString? getShaderSource(WebGLShader? shader); bool JSB_glGetShaderSource(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" ); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; uint32_t arg0; ok &= jsval_to_uint( cx, args.get(0), &arg0 ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); GLsizei length; glGetShaderiv(arg0, GL_SHADER_SOURCE_LENGTH, &length); GLchar* src = new (std::nothrow) GLchar[length]; glGetShaderSource(arg0, length, NULL, src); args.rval().set(charptr_to_jsval(cx, src)); CC_SAFE_DELETE_ARRAY(src); return true; }
void ShaderCompiler::DumpDebugInfo(const GLuint shaderId) { // We utilize GL_LOGERR here since we can safely just exit this method when a error occurs // Get shader source. GLint length; GL_LOGERR(glGetShaderiv(shaderId, GL_SHADER_SOURCE_LENGTH, &length)); std::vector<GLchar> source(length); GL_LOGERR(glGetShaderSource(shaderId, source.size(), NULL, &source[0])); DFMCLOG_LINE("Debug source START:\n" << &source[0] << "\nDebug source END\n\n"); // Fetch the log GL_LOGERR(glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &length)); std::vector<GLchar> errorLog(length); GL_LOGERR(glGetShaderInfoLog(shaderId, errorLog.size(), NULL, &errorLog[0])); DFMCLOG_LINE("Log START:\n" << &errorLog[0] << "\nLog END\n\n"); }
// DOMString? getShaderSource(WebGLShader? shader); JSBool JSB_glGetShaderSource(JSContext *cx, uint32_t argc, jsval *vp) { JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" ); jsval *argvp = JS_ARGV(cx,vp); JSBool ok = JS_TRUE; uint32_t arg0; ok &= jsval_to_uint( cx, *argvp++, &arg0 ); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments"); GLsizei length; glGetShaderiv(arg0, GL_SHADER_SOURCE_LENGTH, &length); GLchar* src = new GLchar[length]; glGetShaderSource(arg0, length, NULL, src); JS_SET_RVAL(cx, vp, charptr_to_jsval(cx, src)); CC_SAFE_DELETE_ARRAY(src); return JS_TRUE; }
void ShaderObject::printShaderInfoLog(GLint shader) { int infoLogLen = 0; int charsWritten = 0; GLchar *infoLog; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLen); if (infoLogLen > 0) { infoLog = new GLchar[infoLogLen]; glGetShaderInfoLog(shader, infoLogLen, &charsWritten, infoLog); std::cerr << "InfoLog:" << std::endl << infoLog << std::endl; delete [] infoLog; } int sourceLenght; glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &sourceLenght); infoLog = new GLchar[sourceLenght]; glGetShaderSource(shader, sourceLenght, &charsWritten, infoLog); std::cerr << "InfoLog:" << std::endl << infoLog << std::endl; delete [] infoLog; }