void r_set_heightmap(void) { #if OPENGL_DEBUG uint i; #endif OPENGL_EVENT_BEGIN(0, __PRETTY_FUNCTION__); if (gen_heightmap != NULL) glDeleteTextures(1, &r_hmap_tex); glGenTextures(1, &r_hmap_tex); glBindTexture(GL_TEXTURE_2D, r_hmap_tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8, HEIGHTMAP_SIZE, HEIGHTMAP_SIZE, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, gen_heightmap); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); #if OPENGL_DEBUG if (GLEW_KHR_debug) { glObjectLabel(GL_TEXTURE, r_hmap_tex, -1, "Heightmap"); for (i = 0; i < sizeof(r_ter_VBOs) / sizeof(r_ter_VBOs[0]); ++i) glObjectLabel(GL_BUFFER, r_ter_VBOs[i], -1, "Terrain"); } #endif OPENGL_EVENT_END(); }
bool initBuffer() { bool Validated(true); glGenBuffers(buffer::MAX, BufferName); glObjectLabel(GL_BUFFER, BufferName[buffer::ELEMENT], -1, "Element Array Buffer object"); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, ElementSize, ElementData, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glObjectLabel(GL_BUFFER, BufferName[buffer::VERTEX], -1, "Array Buffer object"); glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::VERTEX]); glBufferData(GL_ARRAY_BUFFER, VertexSize, VertexData, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); GLint UniformBufferOffset(0); glGetIntegerv( GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &UniformBufferOffset); GLint UniformBlockSize = glm::max(GLint(sizeof(glm::mat4)), UniformBufferOffset); glObjectLabel(GL_BUFFER, BufferName[buffer::TRANSFORM], -1, "Uniform Buffer object"); glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glBufferData(GL_UNIFORM_BUFFER, UniformBlockSize, NULL, GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); return Validated; }
bool initProgram() { bool Validated(true); glGenProgramPipelines(1, &PipelineName); glObjectLabel(GL_PROGRAM_PIPELINE, PipelineName, -1, "Pipeline Program object"); if(Validated) { glf::compiler Compiler; GLuint VertShaderName = Compiler.create(GL_VERTEX_SHADER, glf::DATA_DIRECTORY + VERT_SHADER_SOURCE, "--version 420 --profile core"); GLuint FragShaderName = Compiler.create(GL_FRAGMENT_SHADER, glf::DATA_DIRECTORY + FRAG_SHADER_SOURCE, "--version 420 --profile core"); Validated = Validated && Compiler.check(); ProgramName[program::VERTEX] = glCreateProgram(); glObjectLabel(GL_PROGRAM, PipelineName, -1, "Vertex Program object"); glProgramParameteri(ProgramName[program::VERTEX], GL_PROGRAM_SEPARABLE, GL_TRUE); glAttachShader(ProgramName[program::VERTEX], VertShaderName); glLinkProgram(ProgramName[program::VERTEX]); glDeleteShader(VertShaderName); ProgramName[program::FRAGMENT] = glCreateProgram(); glObjectLabel(GL_PROGRAM, PipelineName, -1, "Fragment Program object"); glProgramParameteri(ProgramName[program::FRAGMENT], GL_PROGRAM_SEPARABLE, GL_TRUE); glAttachShader(ProgramName[program::FRAGMENT], FragShaderName); glLinkProgram(ProgramName[program::FRAGMENT]); glDeleteShader(FragShaderName); Validated = Validated && glf::checkProgram(ProgramName[program::VERTEX]); Validated = Validated && glf::checkProgram(ProgramName[program::FRAGMENT]); } if(Validated) { glUseProgramStages(PipelineName, GL_VERTEX_SHADER_BIT, ProgramName[program::VERTEX]); glUseProgramStages(PipelineName, GL_FRAGMENT_SHADER_BIT, ProgramName[program::FRAGMENT]); } return Validated; }
void ObjectLabel(GLenum identifier, GLuint name, GLsizei size, const char* label) { if (GLEW_KHR_debug) { glObjectLabel(identifier, name, size, label); } }
void ae3d::Shader::Load( const char* vertexSource, const char* fragmentSource ) { GLuint vertexShader = CompileShader( vertexSource, GL_VERTEX_SHADER ); GLuint fragmentShader = CompileShader( fragmentSource, GL_FRAGMENT_SHADER ); GLuint program = GfxDevice::CreateProgramId(); if (GfxDevice::HasExtension( "KHR_debug" )) { glObjectLabel( GL_PROGRAM, id, (GLsizei)std::string( "shader" ).size(), "shader" ); } glAttachShader( program, vertexShader ); glAttachShader( program, fragmentShader ); glLinkProgram( program ); GLint wasLinked; glGetProgramiv( program, GL_LINK_STATUS, &wasLinked ); if (!wasLinked) { ae3d::System::Print("Shader linking failed.\n"); PrintInfoLog( program, InfoLogType::Program ); return; } id = program; uniformLocations = GetUniformLocations( program ); }
void CStdGL::ObjectLabel(uint32_t identifier, uint32_t name, int32_t length, const char * label) { #ifdef GL_KHR_debug if (glObjectLabel) glObjectLabel(identifier, name, length, label); #endif }
const ae3d::Texture2D* ae3d::Texture2D::GetDefaultTexture() { if (Texture2DGlobal::defaultTexture.GetWidth() == 0) { Texture2DGlobal::defaultTexture.width = 32; Texture2DGlobal::defaultTexture.height = 32; Texture2DGlobal::defaultTexture.handle = GfxDevice::CreateTextureId(); if (GfxDevice::HasExtension( "KHR_debug" )) { glObjectLabel( GL_TEXTURE, Texture2DGlobal::defaultTexture.handle, (GLsizei)std::string("default texture 2d").size(), "default texture 2d" ); } glBindTexture( GL_TEXTURE_2D, Texture2DGlobal::defaultTexture.handle ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); int data[ 32 * 32 * 4 ] = { 0xFFC0CB }; glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, Texture2DGlobal::defaultTexture.width, Texture2DGlobal::defaultTexture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); } return &Texture2DGlobal::defaultTexture; }
int pie_AddTexPage(iV_Image *s, const char *filename, bool gameTexture, int page) { ASSERT(s && filename, "Bad input parameter"); if (page < 0) { iTexPage tex; page = _TEX_PAGE.size(); glGenTextures(1, &tex.id); sstrcpy(tex.name, filename); _TEX_PAGE.append(tex); } else // replace { sstrcpy(_TEX_PAGE[page].name, filename); } debug(LOG_TEXTURE, "%s page=%d", filename, page); pie_SetTexturePage(page); if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { glObjectLabel(GL_TEXTURE, pie_Texture(page), -1, filename); } if (gameTexture) // this is a game texture, use texture compression { gluBuild2DMipmaps(GL_TEXTURE_2D, wz_texture_compression, s->width, s->height, iV_getPixelFormat(s), GL_UNSIGNED_BYTE, s->bmp); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } else // this is an interface texture, do not use compression { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->width, s->height, 0, iV_getPixelFormat(s), GL_UNSIGNED_BYTE, s->bmp); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } // it is uploaded, we do not need it anymore free(s->bmp); s->bmp = NULL; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Use anisotropic filtering, if available, but only max 4.0 to reduce processor burden if (GLEW_EXT_texture_filter_anisotropic) { GLfloat max; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, MIN(4.0f, max)); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); /* Send back the texpage number so we can store it in the IMD */ return page; }
void AbstractObject::labelImplementationKhr(const GLenum identifier, const GLuint name, const std::string& label) { #ifndef MAGNUM_TARGET_GLES glObjectLabel(identifier, name, label.size(), label.data()); #else static_cast<void>(identifier); static_cast<void>(name); static_cast<void>(label); CORRADE_INTERNAL_ASSERT(false); //glObjectLabelKHR(identifier, name, label.size(), label.data()); #endif }
void AbstractObject::labelImplementationKhr(const GLenum identifier, const GLuint name, const Containers::ArrayView<const char> label) { #ifndef MAGNUM_TARGET_GLES glObjectLabel(identifier, name, label.size(), label); #elif !defined(CORRADE_TARGET_NACL) glObjectLabelKHR(identifier, name, label.size(), label); #else static_cast<void>(identifier); static_cast<void>(name); static_cast<void>(label); CORRADE_ASSERT_UNREACHABLE(); #endif }
GLuint GSShaderOGL::LinkPipeline(const string& pretty_print, GLuint vs, GLuint gs, GLuint ps) { GLuint p; glCreateProgramPipelines(1, &p); glUseProgramStages(p, GL_VERTEX_SHADER_BIT, vs); glUseProgramStages(p, GL_GEOMETRY_SHADER_BIT, gs); glUseProgramStages(p, GL_FRAGMENT_SHADER_BIT, ps); glObjectLabel(GL_PROGRAM_PIPELINE, p, pretty_print.size(), pretty_print.c_str()); m_pipe_to_delete.push_back(p); return p; }
void Init() { glGenBuffers(1, &m_buffer); BindPbo(); glObjectLabel(GL_BUFFER, m_buffer, -1, "PBO"); glBufferStorage(GL_PIXEL_UNPACK_BUFFER, m_pbo_size, NULL, create_flags); m_map = (char*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, m_pbo_size, map_flags); m_offset = 0; for (size_t i = 0; i < countof(m_fence); i++) { m_fence[i] = 0; } UnbindPbo(); }
void createAndAllocBuffer(GLsizeiptr bufferSize, GLenum usageMask, GLuint& bufferIdOut, const bufferPtr data, const char* name) { glCreateBuffers(1, &bufferIdOut); if (Config::ENABLE_GPU_VALIDATION) { glObjectLabel(GL_BUFFER, bufferIdOut, -1, name != nullptr ? name : Util::StringFormat("DVD_GENERAL_BUFFER_%d", bufferIdOut).c_str()); } assert(bufferIdOut != 0 && "GLUtil::allocBuffer error: buffer creation failed"); glNamedBufferData(bufferIdOut, bufferSize, data, usageMask); }
bufferPtr createAndAllocPersistentBuffer(GLsizeiptr bufferSize, BufferStorageMask storageMask, BufferAccessMask accessMask, GLuint& bufferIdOut, bufferPtr const data, const char* name) { glCreateBuffers(1, &bufferIdOut); if (Config::ENABLE_GPU_VALIDATION) { glObjectLabel(GL_BUFFER, bufferIdOut, -1, name != nullptr ? name : Util::StringFormat("DVD_PERSISTENT_BUFFER_%d", bufferIdOut).c_str()); } assert(bufferIdOut != 0 && "GLUtil::allocPersistentBuffer error: buffer creation failed"); return allocPersistentBuffer(bufferIdOut, bufferSize, storageMask, accessMask, data); }
bool initTexture() { bool Validated(true); gli::texture2D Texture(gli::loadStorageDDS(glf::DATA_DIRECTORY + TEXTURE_DIFFUSE)); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &TextureName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName); glObjectLabel(GL_TEXTURE, TextureName, -1, "Texture object"); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexStorage2D(GL_TEXTURE_2D, GLint(Texture.levels()), GL_RGBA8, GLsizei(Texture[0].dimensions().x), GLsizei(Texture[0].dimensions().y)); for(gli::texture2D::size_type Level = 0; Level < Texture.levels(); ++Level) { glTexSubImage2D( GL_TEXTURE_2D, GLint(Level), 0, 0, GLsizei(Texture[Level].dimensions().x), GLsizei(Texture[Level].dimensions().y), GL_BGR, GL_UNSIGNED_BYTE, Texture[Level].data()); } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return Validated; }
bool initVertexArray() { bool Validated(true); glGenVertexArrays(1, &VertexArrayName); glBindVertexArray(VertexArrayName); glObjectLabel(GL_VERTEX_ARRAY, VertexArrayName, -1, "Vertex array object"); glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::VERTEX]); glVertexAttribPointer(glf::semantic::attr::POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(glf::vertex_v2fv2f), GLF_BUFFER_OFFSET(0)); glVertexAttribPointer(glf::semantic::attr::TEXCOORD, 2, GL_FLOAT, GL_FALSE, sizeof(glf::vertex_v2fv2f), GLF_BUFFER_OFFSET(sizeof(glm::vec2))); glBindBuffer(GL_ARRAY_BUFFER, 0); glEnableVertexAttribArray(glf::semantic::attr::POSITION); glEnableVertexAttribArray(glf::semantic::attr::TEXCOORD); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); glBindVertexArray(0); return Validated; }
GLhandleARB C4Shader::Create(GLenum iShaderType, const char *szWhat, const char *szShader) { // Create shader GLhandleARB hShader = glCreateShaderObjectARB(iShaderType); #ifdef GL_KHR_debug if (glObjectLabel) glObjectLabel(GL_SHADER, hShader, -1, szWhat); #endif // Compile glShaderSourceARB(hShader, 1, &szShader, 0); glCompileShaderARB(hShader); // Dump any information to log DumpInfoLog(szWhat, hShader); // Success? if(GetObjectStatus(hShader, GL_OBJECT_COMPILE_STATUS_ARB) == 1) return hShader; // Did not work :/ glDeleteObjectARB(hShader); return 0; }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglObjectLabel(JNIEnv *__env, jclass clazz, jint identifier, jint name, jint length, jlong labelAddress, jlong __functionAddress) { const GLchar *label = (const GLchar *)(intptr_t)labelAddress; glObjectLabelPROC glObjectLabel = (glObjectLabelPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) glObjectLabel(identifier, name, length, label); }
static inline bool r_create_program(const char *id, const char *vss, const char *fss, uint *vs, uint *fs, uint *prog) { OPENGL_EVENT_BEGIN(0, __PRETTY_FUNCTION__); *vs = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); *fs = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); // shut up compiler... glShaderSourceARB(*vs, 1, (const char **)&vss, NULL); glShaderSourceARB(*fs, 1, (const char **)&fss, NULL); // compile vertex shader glCompileShaderARB(*vs); if (!r_shader_check(*vs, GL_OBJECT_COMPILE_STATUS_ARB, id, "vertex shader compilation")) { OPENGL_EVENT_END(); return false; } // compile fragment shader glCompileShaderARB(*fs); if (!r_shader_check(*fs, GL_OBJECT_COMPILE_STATUS_ARB, id, "fragment shader compilation")) { OPENGL_EVENT_END(); return false; } // link the program together *prog = glCreateProgramObjectARB(); glAttachObjectARB(*prog, *vs); glAttachObjectARB(*prog, *fs); glLinkProgramARB(*prog); if (!r_shader_check(*prog, GL_OBJECT_LINK_STATUS_ARB, id, "GPU program linking")) { OPENGL_EVENT_END(); return false; } // validate the program glValidateProgramARB(*prog); if (!r_shader_check(*prog, GL_OBJECT_VALIDATE_STATUS_ARB, id, "GPU program validation")) { OPENGL_EVENT_END(); return false; } #if OPENGL_DEBUG if (GLEW_KHR_debug) { glObjectLabel(GL_SHADER, *vs, -1, id); glObjectLabel(GL_SHADER, *fs, -1, id); glObjectLabel(GL_PROGRAM, *prog, -1, id); } #endif OPENGL_EVENT_END(); return true; }
void opengl_set_object_label(GLenum type, GLuint handle, const SCP_string& name) { if (GLAD_GL_KHR_debug) { glObjectLabel(type, handle, (GLsizei) name.size(), name.c_str()); } }
void ae3d::Texture2D::Load( const FileSystem::FileContentsData& fileContents, TextureWrap aWrap, TextureFilter aFilter, Mipmaps aMipmaps, float aAnisotropy ) { filter = aFilter; wrap = aWrap; mipmaps = aMipmaps; anisotropy = aAnisotropy; if (!fileContents.isLoaded) { *this = Texture2DGlobal::defaultTexture; return; } const bool isCached = Texture2DGlobal::pathToCachedTexture.find( fileContents.path ) != Texture2DGlobal::pathToCachedTexture.end(); if (isCached && handle == 0) { *this = Texture2DGlobal::pathToCachedTexture[ fileContents.path ]; return; } // First load. if (handle == 0) { handle = GfxDevice::CreateTextureId(); if (GfxDevice::HasExtension( "KHR_debug" )) { glObjectLabel( GL_TEXTURE, handle, (GLsizei)fileContents.path.size(), fileContents.path.c_str() ); } fileWatcher.AddFile( fileContents.path, TexReload ); } glBindTexture( GL_TEXTURE_2D, handle ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter == TextureFilter::Nearest ? GL_NEAREST : (mipmaps == Mipmaps::Generate ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR ) ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter == TextureFilter::Nearest ? GL_NEAREST : GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap == TextureWrap::Repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap == TextureWrap::Repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE ); if (GfxDevice::HasExtension( "GL_EXT_texture_filter_anisotropic" ) && anisotropy > 1) { glTexParameterf( GL_TEXTURE_2D, 0x84FE/*GL_TEXTURE_MAX_ANISOTROPY_EXT*/, anisotropy ); } const bool isDDS = fileContents.path.find( ".dds" ) != std::string::npos || fileContents.path.find( ".DDS" ) != std::string::npos; if (HasStbExtension( fileContents.path )) { LoadSTB( fileContents ); } else if (isDDS) { LoadDDS( fileContents.path.c_str() ); } if (mipmaps == Mipmaps::Generate) { glGenerateMipmap( GL_TEXTURE_2D ); } Texture2DGlobal::pathToCachedTexture[ fileContents.path ] = *this; #if DEBUG Texture2DGlobal::pathToCachedTextureSizeInBytes[ fileContents.path ] = static_cast< std::size_t >(width * height * 4 * (mipmaps == Mipmaps::Generate ? 1.0f : 1.33333f)); //Texture2DGlobal::PrintMemoryUsage(); #endif }
bool C4Shader::Init(const char *szWhat, const char **szUniforms) { #ifndef USE_CONSOLE // No support? if(!GLEW_ARB_fragment_program) { Log(" gl: no shader support!"); return false; } // Clear old shader first if (hProg) Clear(); #endif StdStrBuf VertexShader = Build(VertexSlices, true), FragmentShader = Build(FragmentSlices, true); // Dump if (C4Shader::IsLogging()) { ShaderLogF("******** Vertex shader for %s:", szWhat); ShaderLog(VertexShader.getData()); ShaderLogF("******** Fragment shader for %s:", szWhat); ShaderLog(FragmentShader.getData()); } #ifndef USE_CONSOLE // Attempt to create shaders hVert = Create(GL_VERTEX_SHADER_ARB, FormatString("%s vertex shader", szWhat).getData(), VertexShader.getData()); hFrag = Create(GL_FRAGMENT_SHADER_ARB, FormatString("%s fragment shader", szWhat).getData(), FragmentShader.getData()); if(!hFrag || !hVert) return false; // Link program hProg = glCreateProgramObjectARB(); #ifdef GL_KHR_debug if (glObjectLabel) glObjectLabel(GL_PROGRAM, hProg, -1, szWhat); #endif glAttachObjectARB(hProg, hVert); glAttachObjectARB(hProg, hFrag); // Bind all input variables for (int i = 0; i <= VAI_BoneWeightsMax - VAI_BoneWeights; ++i) { glBindAttribLocation(hProg, VAI_BoneWeights + i, FormatString("oc_BoneWeights%d", i).getData()); glBindAttribLocation(hProg, VAI_BoneIndices + i, FormatString("oc_BoneIndices%d", i).getData()); } glLinkProgramARB(hProg); // Link successful? DumpInfoLog(FormatString("%s shader program", szWhat).getData(), hProg); if(GetObjectStatus(hProg, GL_OBJECT_LINK_STATUS_ARB) != 1) { Clear(); ShaderLogF(" gl: Failed to link %s shader!", szWhat); return false; } ShaderLogF(" gl: %s shader linked successfully", szWhat); // Okay, allocate uniform array iUniformCount = 0; while (szUniforms[iUniformCount]) iUniformCount++; pUniforms = new GLint[iUniformCount]; // Get uniform locations. Note this is expected to fail for a few of them // because the respective uniforms got optimized out! for (int i = 0; i < iUniformCount; i++) pUniforms[i] = glGetUniformLocationARB(hProg, szUniforms[i]); #endif return true; }
// Read/compile/link shaders SHADER_MODE pie_LoadShader(const char *programName, const char *vertexPath, const char *fragmentPath, const std::vector<std::string> &uniformNames) { pie_internal::SHADER_PROGRAM program; GLint status; bool success = true; // Assume overall success char *buffer[2]; program.program = glCreateProgram(); glBindAttribLocation(program.program, 0, "vertex"); glBindAttribLocation(program.program, 1, "vertexTexCoord"); glBindAttribLocation(program.program, 2, "vertexColor"); ASSERT_OR_RETURN(SHADER_NONE, program.program, "Could not create shader program!"); *buffer = (char *)""; if (vertexPath) { success = false; // Assume failure before reading shader file if ((*(buffer + 1) = readShaderBuf(vertexPath))) { GLuint shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(shader, 2, (const char **)buffer, nullptr); glCompileShader(shader); // Check for compilation errors glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if (!status) { debug(LOG_ERROR, "Vertex shader compilation has failed [%s]", vertexPath); printShaderInfoLog(LOG_ERROR, shader); } else { printShaderInfoLog(LOG_3D, shader); glAttachShader(program.program, shader); success = true; } if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { glObjectLabel(GL_SHADER, shader, -1, vertexPath); } free(*(buffer + 1)); } } if (success && fragmentPath) { success = false; // Assume failure before reading shader file if ((*(buffer + 1) = readShaderBuf(fragmentPath))) { GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(shader, 2, (const char **)buffer, nullptr); glCompileShader(shader); // Check for compilation errors glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if (!status) { debug(LOG_ERROR, "Fragment shader compilation has failed [%s]", fragmentPath); printShaderInfoLog(LOG_ERROR, shader); } else { printShaderInfoLog(LOG_3D, shader); glAttachShader(program.program, shader); success = true; } if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { glObjectLabel(GL_SHADER, shader, -1, fragmentPath); } free(*(buffer + 1)); } } if (success) { glLinkProgram(program.program); // Check for linkage errors glGetProgramiv(program.program, GL_LINK_STATUS, &status); if (!status) { debug(LOG_ERROR, "Shader program linkage has failed [%s, %s]", vertexPath, fragmentPath); printProgramInfoLog(LOG_ERROR, program.program); success = false; } else { printProgramInfoLog(LOG_3D, program.program); } if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { glObjectLabel(GL_PROGRAM, program.program, -1, programName); } } GLuint p = program.program; std::transform(uniformNames.begin(), uniformNames.end(), std::back_inserter(program.locations), [p](const std::string name) { return glGetUniformLocation(p, name.data()); }); getLocs(&program); glUseProgram(0); pie_internal::shaderProgram.push_back(program); return SHADER_MODE(pie_internal::shaderProgram.size() - 1); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengles_GLES32_nglObjectLabel(JNIEnv *__env, jclass clazz, jint identifier, jint name, jint length, jlong labelAddress) { glObjectLabelPROC glObjectLabel = (glObjectLabelPROC)tlsGetFunction(323); intptr_t label = (intptr_t)labelAddress; UNUSED_PARAM(clazz) glObjectLabel(identifier, name, length, label); }
void set_object_label (const type& object , const std::string& label) { glObjectLabel(type::native_type, object.id(), label.size(), label.data()); }
void C4ParticleChunk::Draw(C4TargetFacet cgo, C4Object *obj, C4ShaderCall& call, int texUnit, const StdProjectionMatrix& modelview) { if (particleCount == 0) return; const int stride = sizeof(C4Particle::DrawingData::Vertex); assert(sourceDefinition && "No source definition assigned to particle chunk."); C4TexRef *textureRef = &sourceDefinition->Gfx.GetFace().textures[0]; assert(textureRef != 0 && "Particle definition had no texture assigned."); // use a relative offset? // (note the normal matrix is unaffected by this) if ((attachment & C4ATTACH_MoveRelative) && (obj != 0)) { StdProjectionMatrix new_modelview(modelview); Translate(new_modelview, fixtof(obj->GetFixedX()), fixtof(obj->GetFixedY()), 0.0f); call.SetUniformMatrix4x4(C4SSU_ModelViewMatrix, new_modelview); } else { call.SetUniformMatrix4x4(C4SSU_ModelViewMatrix, modelview); } // enable additive blending for particles with that blit mode glBlendFunc(GL_SRC_ALPHA, (blitMode & C4GFXBLIT_ADDITIVE) ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA); glActiveTexture(texUnit); glBindTexture(GL_TEXTURE_2D, textureRef->texName); // generate the buffer as necessary if (drawingDataVertexBufferObject == 0) { // clear up old data ClearBufferObjects(); // generate new buffer objects glGenBuffers(1, &drawingDataVertexBufferObject); assert (drawingDataVertexBufferObject != 0 && "Could not generate OpenGL buffer object."); // Immediately bind the buffer. // glVertexAttribPointer requires a valid GL_ARRAY_BUFFER to be bound and we need the buffer to be created for glObjectLabel. glBindBuffer(GL_ARRAY_BUFFER, drawingDataVertexBufferObject); #ifdef GL_KHR_debug if (glObjectLabel) glObjectLabel(GL_BUFFER, drawingDataVertexBufferObject, -1, "<particles>/VBO"); #endif // generate new VAO ID drawingDataVertexArraysObject = pGL->GenVAOID(); assert (drawingDataVertexArraysObject != 0 && "Could not generate a VAO ID."); } // Push the new vertex data glBindBuffer(GL_ARRAY_BUFFER, drawingDataVertexBufferObject); glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(C4Particle::DrawingData::Vertex) * particleCount, &vertexCoordinates[0], GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); // set up the vertex array structure GLuint vao; const bool has_vao = pGL->GetVAO(drawingDataVertexArraysObject, vao); glBindVertexArray(vao); assert ((drawingDataVertexBufferObject != 0) && "No buffer object has been created yet."); assert ((drawingDataVertexArraysObject != 0) && "No vertex arrays object has been created yet."); if (!has_vao) { glBindBuffer(GL_ARRAY_BUFFER, drawingDataVertexBufferObject); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ::Particles.GetIBO()); #ifdef GL_KHR_debug if (glObjectLabel) glObjectLabel(GL_VERTEX_ARRAY, vao, -1, "<particles>/VAO"); #endif glEnableVertexAttribArray(call.GetAttribute(C4SSA_Position)); glEnableVertexAttribArray(call.GetAttribute(C4SSA_Color)); glEnableVertexAttribArray(call.GetAttribute(C4SSA_TexCoord)); glVertexAttribPointer(call.GetAttribute(C4SSA_Position), 2, GL_FLOAT, GL_FALSE, stride, reinterpret_cast<GLvoid*>(offsetof(C4Particle::DrawingData::Vertex, x))); glVertexAttribPointer(call.GetAttribute(C4SSA_TexCoord), 2, GL_FLOAT, GL_FALSE, stride, reinterpret_cast<GLvoid*>(offsetof(C4Particle::DrawingData::Vertex, u))); glVertexAttribPointer(call.GetAttribute(C4SSA_Color), 4, GL_FLOAT, GL_FALSE, stride, reinterpret_cast<GLvoid*>(offsetof(C4Particle::DrawingData::Vertex, r))); } glDrawElements(GL_TRIANGLE_STRIP, static_cast<GLsizei> (5 * particleCount), GL_UNSIGNED_INT, 0); // reset buffer data glBindVertexArray(0); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL43_nglObjectLabel(JNIEnv *env, jclass clazz, jint identifier, jint name, jint length, jlong label, jlong function_pointer) { const GLchar *label_address = (const GLchar *)(intptr_t)label; glObjectLabelPROC glObjectLabel = (glObjectLabelPROC)((intptr_t)function_pointer); glObjectLabel(identifier, name, length, label_address); }
// Read/compile/link shaders GLuint pie_LoadShader(const char *programName, const char *vertexPath, const char *fragmentPath) { SHADER_PROGRAM program; GLint status; bool success = true; // Assume overall success char *buffer[2]; memset(&program, 0, sizeof(program)); program.program = glCreateProgram(); ASSERT_OR_RETURN(false, program.program, "Could not create shader program!"); *buffer = (char *)""; if (vertexPath) { success = false; // Assume failure before reading shader file if ((*(buffer + 1) = readShaderBuf(vertexPath))) { GLuint shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(shader, 2, (const char **)buffer, NULL); glCompileShader(shader); // Check for compilation errors glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if (!status) { debug(LOG_ERROR, "Vertex shader compilation has failed [%s]", vertexPath); printShaderInfoLog(LOG_ERROR, shader); } else { printShaderInfoLog(LOG_3D, shader); glAttachShader(program.program, shader); success = true; } if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { glObjectLabel(GL_SHADER, shader, -1, vertexPath); } free(*(buffer + 1)); } } if (success && fragmentPath) { success = false; // Assume failure before reading shader file if ((*(buffer + 1) = readShaderBuf(fragmentPath))) { GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(shader, 2, (const char **)buffer, NULL); glCompileShader(shader); // Check for compilation errors glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if (!status) { debug(LOG_ERROR, "Fragment shader compilation has failed [%s]", fragmentPath); printShaderInfoLog(LOG_ERROR, shader); } else { printShaderInfoLog(LOG_3D, shader); glAttachShader(program.program, shader); success = true; } if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { glObjectLabel(GL_SHADER, shader, -1, fragmentPath); } free(*(buffer + 1)); } } if (success) { glLinkProgram(program.program); // Check for linkage errors glGetProgramiv(program.program, GL_LINK_STATUS, &status); if (!status) { debug(LOG_ERROR, "Shader program linkage has failed [%s, %s]", vertexPath, fragmentPath); printProgramInfoLog(LOG_ERROR, program.program); success = false; } else { printProgramInfoLog(LOG_3D, program.program); } if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { glObjectLabel(GL_PROGRAM, program.program, -1, programName); } } getLocs(&program); glUseProgram(0); shaderProgram.append(program); return shaderProgram.size() - 1; }