void init(void) { glClearColor(0.3, 0.3, 0.3, 1); glGenVertexArrays(1, &vao_quad); glBindVertexArray(vao_quad); #define N 30 GLfloat vertices[4][4] = { { -0.90, -0.90, 0, N }, { 0.90, -0.90, N, N }, { -0.90, 0.90, 0, 0 }, { 0.90, 0.90, N, 0 }, }; glGenBuffers(1, &buf_quad); glBindBuffer(GL_ARRAY_BUFFER, buf_quad); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); GLuint h_prog = build_program_from_files("quad_tex_mipmap.vert", "quad_tex_mipmap.frag"); glUseProgram(h_prog); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, BUFFER_OFFSET(0)); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, BUFFER_OFFSET(sizeof(GLfloat)*2)); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glm::mat4 M = glm::rotate(glm::mat4(1.0f), -85.0f, glm::vec3(1.0f, 0.0f, 0.0f)); glm::mat4 V = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -1.0f)); glm::mat4 P = glm::perspective(45.0f, 1.0f, 0.1f, 5.0f); glUniformMatrix4fv(glGetUniformLocation(h_prog, "MVP"), 1, GL_FALSE, glm::value_ptr(P*V*M)); glUniform4f(glGetUniformLocation(h_prog, "color"), 1, 1, .5, .5); glUniform1i(glGetUniformLocation(h_prog, "tex"), 4); glEnable(GL_CULL_FACE); load_textures(); glGenSamplers(1, &sampler); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT); // glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); // glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glBindSampler(3, sampler); glBindSampler(4, sampler); }
PIGLIT_GL_TEST_CONFIG_END enum piglit_result piglit_display(void) { bool pass = true; GLuint tex, sampler, fb; const float tex_data[16] = {0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}; const float *green = tex_data; glClearColor(0, 0, 1, 0); glClear(GL_COLOR_BUFFER_BIT); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_FLOAT, tex_data); glGenFramebuffers(1, &fb); glBindFramebuffer(GL_FRAMEBUFFER, fb); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0); assert(glGetError() == 0); glGenSamplers(1, &sampler); glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindSampler(0, sampler); glBindFramebuffer(GL_READ_FRAMEBUFFER, fb); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo); glBlitFramebuffer(0, 0, 1, 1, 0, 0, piglit_width, piglit_height, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo); pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green); piglit_present_results(); glDeleteSamplers(1, &sampler); glDeleteTextures(1, &tex); glDeleteFramebuffers(1, &fb); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
static cg_sampler_cache_entry_t * _cg_sampler_cache_get_entry_gl(cg_sampler_cache_t *cache, const cg_sampler_cache_entry_t *key) { cg_sampler_cache_entry_t *entry; entry = c_hash_table_lookup(cache->hash_table_gl, key); if (entry == NULL) { cg_device_t *dev = cache->dev; entry = c_slice_dup(cg_sampler_cache_entry_t, key); if (_cg_has_private_feature(dev, CG_PRIVATE_FEATURE_SAMPLER_OBJECTS)) { GE(dev, glGenSamplers(1, &entry->sampler_object)); GE(dev, glSamplerParameteri(entry->sampler_object, GL_TEXTURE_MIN_FILTER, entry->min_filter)); GE(dev, glSamplerParameteri(entry->sampler_object, GL_TEXTURE_MAG_FILTER, entry->mag_filter)); set_wrap_mode(dev, entry->sampler_object, GL_TEXTURE_WRAP_S, entry->wrap_mode_s); set_wrap_mode(dev, entry->sampler_object, GL_TEXTURE_WRAP_T, entry->wrap_mode_t); set_wrap_mode(dev, entry->sampler_object, GL_TEXTURE_WRAP_R, entry->wrap_mode_p); } else { /* If sampler objects aren't supported then we'll invent a unique number so that pipelines can still compare the unique state just by comparing the sampler object numbers */ entry->sampler_object = cache->next_fake_sampler_object_number++; } c_hash_table_insert(cache->hash_table_gl, entry, entry); } return entry; }
void Mesh::loadTexture(const std::string &path) { if(glIsTexture(m_meshTexture) == GL_FALSE) glGenTextures(1, &m_meshTexture); if(glIsSampler(m_meshSampler) == GL_FALSE) glGenSamplers(1, &m_meshSampler); // Setup sampler data glSamplerParameteri(m_meshSampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(m_meshSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glSamplerParameteri(m_meshSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_meshSampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); SDL_Surface* surface = IMG_Load(path.c_str()); GLint readFormat = GL_RGB; if(surface->format->BytesPerPixel == 4) { if(surface->format->Rmask == 0xFF) readFormat = GL_RGBA; else if(surface->format->Bmask == 0xFF) readFormat = GL_BGRA; } else if(surface->format->BytesPerPixel == 3) { if(surface->format->Rmask == 0xFF) readFormat = GL_RGB; else if(surface->format->Bmask == 0xFF) readFormat = GL_BGR; } if(surface->format->Rmask) GLfloat texDat[] = { 1.f,1.f,1.f,1.f, 0.f,1.f, 0.f, 1.f, 1.f,1.f,1.f,1.f, 0.f,1.f, 0.f, 1.f, }; // Setup texture data glBindTexture(GL_TEXTURE_2D, m_meshTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, readFormat, GL_UNSIGNED_BYTE, surface->pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glBindTexture(GL_TEXTURE_2D, 0); SDL_FreeSurface(surface); }
void OGLWindow::InitOGLState() { VSync(true); glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); //Initialise OGL shader m_shader = new OGLShaderProgram(); m_skyBoxShader = new OGLShaderProgram(); m_shader->CreateShaderProgram(); m_shader->AttachAndCompileShaderFromFile(L"../asset/shader/glsl/basic.vert", SHADER_VERTEX); m_shader->AttachAndCompileShaderFromFile(L"../asset/shader/glsl/basic.frag", SHADER_FRAGMENT); m_shader->BindAttributeLocation( 0, "position" ); m_shader->BindAttributeLocation( 1, "inNormal" ); m_shader->BindAttributeLocation( 2, "inUV" ); //shading skybox via shaders m_skyBoxShader->CreateShaderProgram(); m_skyBoxShader->AttachAndCompileShaderFromFile(L"../asset/shader/glsl/skybox.vert", SHADER_VERTEX); m_skyBoxShader->AttachAndCompileShaderFromFile(L"../asset/shader/glsl/skybox.frag", SHADER_FRAGMENT); m_skyBoxShader->BindAttributeLocation(0, "position"); m_skyBoxShader->BindAttributeLocation(1, "inNormal"); m_skyBoxShader->BindAttributeLocation(2, "inUV"); glBindFragDataLocation( m_shader->GetProgramHandle(), 0, "outFrag" ); glBindFragDataLocation(m_skyBoxShader->GetProgramHandle(), 0, "outFrag"); m_shader->BuildShaderProgram(); m_shader->ActivateShaderProgram(); m_skyBoxShader->BuildShaderProgram(); m_shader->ActivateShaderProgram(); glUniform1i( m_uniform_texture, 0 ); //Create a texture sampler glGenSamplers( 1, (GLuint*)(&m_texDefaultSampler) ); glSamplerParameteri(m_texDefaultSampler , GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_texDefaultSampler , GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_texDefaultSampler , GL_TEXTURE_MIN_FILTER , GL_LINEAR); glSamplerParameteri(m_texDefaultSampler , GL_TEXTURE_MAG_FILTER , GL_LINEAR); }
void OGL4Sampler::SetCompareFunction(TEXTURE_COMPARE_FUNC value) { switch(value) { case CF_LEQUAL: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); break; case CF_GEQUAL: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_GEQUAL); break; case CF_LESS: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_LESS); break; case CF_GREATER: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_GREATER); break; case CF_EQUAL: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_EQUAL); break; case CF_NOTEQUAL: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_NOTEQUAL); break; case CF_ALWAYS: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_ALWAYS); break; case CF_NEVER: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_FUNC, GL_NEVER); break; default: assert(0); break; } }
static void exec(std::vector<unsigned> &v, std::vector<GLenum> &e) { unsigned id; glGenSamplers(1, &id); glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); v.push_back(createNearestSampler()); e.push_back(GL_TEXTURE_2D); CreateSamplers<tp...>::exec(v, e); }
void Renderer::loadTextures() { { QVector<QString> files; files << "dirt.png" << "sand.png" << "grass.png" << "mountain.png"; QVector<QImage> images(files.count(), QImage(QSize(700,700), QImage::Format_RGBA8888)); for (int i=0; i<images.count(); i++) { QImage &image = images[i]; if (!image.load(gDefaultPathTextures + files[i])) qDebug() << "Error loading texture " << gDefaultPathTextures + files[i]; } int imageSize = images.first().width(); //for now, assume all images are the same width and height glGenTextures(1, &mTextures.terrain); qDebug() << "I am " << mTextures.terrain; glBindTexture(GL_TEXTURE_2D_ARRAY, mTextures.terrain); GLenum format = GL_BGRA; int mipLevels = 8; glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevels, GL_RGBA8, imageSize, imageSize, 4); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, imageSize, imageSize, 1, format, GL_UNSIGNED_BYTE, images[0].bits()); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, imageSize, imageSize, 1, format, GL_UNSIGNED_BYTE, images[1].bits()); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 2, imageSize, imageSize, 1, format, GL_UNSIGNED_BYTE, images[2].bits()); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 3, imageSize, imageSize, 1, format, GL_UNSIGNED_BYTE, images[3].bits()); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); glSamplerParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); } }
GLuint CreateSampler(GLenum min_filter, GLenum mag_filter, GLenum u_wrap, GLenum v_wrap) { GLuint sampler_id; glGenSamplers(1, &sampler_id); if (NULL == sampler_id) { return NULL; } glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER, min_filter); // Default: GL_NEAREST_MIPMAP_LINEAR glSamplerParameteri(sampler_id, GL_TEXTURE_MAG_FILTER, mag_filter); // Default: GL_LINEAR glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, u_wrap); // Default: GL_REPEAT glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T, v_wrap); // Default: GL_REPEAT m_samplerID = sampler_id; return sampler_id; }
GLTextureSamplerObject::GLTextureSamplerObject( const DTextureSampler& state ) { glGenSamplers(1, &mGLSampObj); mState = state; GLenum addrModeU = GLTranslator::getGLTextureAddressMode(state.addressU); GLenum addrModeV = GLTranslator::getGLTextureAddressMode(state.addressV); GLenum addrModeW = GLTranslator::getGLTextureAddressMode(state.addressW); glSamplerParameteri(mGLSampObj, GL_TEXTURE_WRAP_S, addrModeU); glSamplerParameteri(mGLSampObj, GL_TEXTURE_WRAP_T, addrModeV); glSamplerParameteri(mGLSampObj, GL_TEXTURE_WRAP_R, addrModeW); GLenum minFilter; GLenum magFilter; float maxAnisotropy = 1.0f; if (state.minFilter == FO_Anistropic || state.magFilter == FO_Anistropic || state.mipFilter == FO_Anistropic) { magFilter = GL_LINEAR; minFilter = GL_LINEAR_MIPMAP_LINEAR; } else { if (state.mipFilter != FO_None) { if (state.mipFilter == FO_Linear) { minFilter = (state.minFilter == FO_Linear) ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_LINEAR; } else { minFilter = (state.minFilter == FO_Linear) ? GL_LINEAR_MIPMAP_NEAREST : GL_NEAREST_MIPMAP_NEAREST; } magFilter = (state.magFilter == FO_Linear) ? GL_LINEAR : GL_NEAREST; } else { minFilter = (state.minFilter == FO_Linear) ? GL_LINEAR : GL_NEAREST; magFilter = (state.magFilter == FO_Linear) ? GL_LINEAR : GL_NEAREST; } } glSamplerParameteri(mGLSampObj, GL_TEXTURE_MIN_FILTER, minFilter); glSamplerParameteri(mGLSampObj, GL_TEXTURE_MAG_FILTER, magFilter); glSamplerParameterf(mGLSampObj, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy); glSamplerParameterf(mGLSampObj, GL_TEXTURE_MIN_LOD, state.minLod); glSamplerParameterf(mGLSampObj, GL_TEXTURE_MAX_LOD, state.maxLod); if (state.samplerComparison != CF_AlwaysFail) { glSamplerParameteri(mGLSampObj, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); } else { glSamplerParameteri(mGLSampObj, GL_TEXTURE_COMPARE_MODE, GL_NONE); } glSamplerParameteri(mGLSampObj, GL_TEXTURE_COMPARE_FUNC, GLTranslator::getGLCompareFunction(state.samplerComparison)); glSamplerParameterf(mGLSampObj, GL_TEXTURE_LOD_BIAS, state.mipLodBias); }
void display() { glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glEnable(GL_SCISSOR_TEST); glDisable(GL_FRAMEBUFFER_SRGB); glScissorIndexed(0, 0, 0, Window.Size.x, Window.Size.y); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); { glm::mat4 Projection = glm::perspective(45.0f, float(FRAMEBUFFER_SIZE.x) / float(FRAMEBUFFER_SIZE.y), 0.1f, 100.0f); glm::mat4 MVP = Projection * View * Model; glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y)); glDisable(GL_FRAMEBUFFER_SRGB); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]); renderScene(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), MVP, Texture2DName); glBindFramebuffer(GL_FRAMEBUFFER, 0); } { glm::mat4 Projection = glm::perspective(45.0f, float(Window.Size.x) / float(Window.Size.y), 0.1f, 100.0f); glm::mat4 MVP = Projection * View * Model; glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); // Correct display glScissorIndexed(0, 0, Window.Size.y / 2 - 1, Window.Size.x, Window.Size.y / 2); glEnable(GL_FRAMEBUFFER_SRGB); glSamplerParameteri(SamplerName, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); // GL_DECODE_EXT renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName); glDisable(GL_FRAMEBUFFER_SRGB); // Incorrected display glScissorIndexed(0, 0, 0, Window.Size.x, Window.Size.y / 2); glEnable(GL_FRAMEBUFFER_SRGB); glSamplerParameteri(SamplerName, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); // GL_DECODE_EXT renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName); glDisable(GL_FRAMEBUFFER_SRGB); } glf::swapBuffers(); glf::checkError("display"); }
//----------------------------------------------------------------------------------- int Renderer::CreateSampler(GLenum min_filter, //fragment counts for more than one texel, how does it shrink? GLenum magFilter, //more texels than fragments, how does it stretch? GLenum uWrap, //If u is < 0 or > 1, how does it behave? GLenum vWrap) //Same, but for v { GLuint id; glGenSamplers(1, &id); glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, min_filter); glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, magFilter); glSamplerParameteri(id, GL_TEXTURE_WRAP_S, uWrap); //For some reason, OpenGL refers to UV's as ST's glSamplerParameteri(id, GL_TEXTURE_WRAP_T, vWrap); return id; }
void OGL4Sampler::SetCompareMode(TEXTURE_COMPARE_MODE value) { switch(value) { case TCM_REF: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); break; case TCM_NONE: glSamplerParameteri(m_sampler, GL_TEXTURE_COMPARE_MODE, GL_NONE); break; default: assert(0); return; } }
Stats::Stats(int viewport_width, int viewport_height) : texture_atlas(0) , texture_font(0) , vertex_count(0) , position_vbo(0) , texcoord_vbo(0) , vao(0) , sampler(0) , text_vs(0) , text_fs(0) , text_program(0) , uniform_instance_buffer(0) { texture_atlas = texture_atlas_new(512, 512, 1); texture_font = texture_font_new_from_file(texture_atlas, 11, (DIRECTORY_FONTS + FILE_DEFAULT_FONT).c_str()); texture_font_load_glyphs(texture_font, FONT_CHARSET_CACHE); // Create a sampler object for the font. glGenSamplers(1, &sampler); glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Load the shader program. text_vs = compile_shader_from_file(DIRECTORY_SHADERS + FILE_TEXT_VS, GL_VERTEX_SHADER); text_fs = compile_shader_from_file(DIRECTORY_SHADERS + FILE_TEXT_FS, GL_FRAGMENT_SHADER); text_program = glCreateProgram(); glAttachShader(text_program, text_vs); glAttachShader(text_program, text_fs); link_program(text_program); // Setup a scale matrix to go from screen space to normalized device space. glm::mat3 scale(2.0f / viewport_width, 0.0f, 0.0f, 0.0f, 2.0f / viewport_height, 0.0f, 0.0f, 0.0f, 1.0f); glm::mat3 translation(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, MARGIN_X, MARGIN_Y, 1.0f); uniform_instance_data.model_matrix = glm::mat3x4(translation * scale); uniform_instance_data.color = glm::vec4(1.0f, 1.0f, 0.0f, 1.0f); glGenBuffers(1, &uniform_instance_buffer); glBindBufferBase(GL_UNIFORM_BUFFER, UNIFORM_INSTANCE_BINDING, uniform_instance_buffer); glBufferData(GL_UNIFORM_BUFFER, sizeof(TextPerInstance), &uniform_instance_data, GL_DYNAMIC_DRAW); }
static void set_wrap_mode(cg_device_t *dev, GLuint sampler_object, GLenum param, cg_sampler_cache_wrap_mode_t wrap_mode) { GE(dev, glSamplerParameteri(sampler_object, param, wrap_mode)); }
bool initSampler() { glGenSamplers(1, &SamplerName); glSamplerParameteri(SamplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(SamplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //glSamplerParameteri(SamplerName, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //glSamplerParameteri(SamplerName, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //glSamplerParameteri(SamplerName, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glSamplerParameterfv(SamplerName, GL_TEXTURE_BORDER_COLOR, &glm::vec4(0.0f)[0]); glSamplerParameterf(SamplerName, GL_TEXTURE_MIN_LOD, -1000.f); glSamplerParameterf(SamplerName, GL_TEXTURE_MAX_LOD, 1000.f); glSamplerParameterf(SamplerName, GL_TEXTURE_LOD_BIAS, 0.0f); glSamplerParameteri(SamplerName, GL_TEXTURE_COMPARE_MODE, GL_NONE); glSamplerParameteri(SamplerName, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); return this->checkError("initSampler"); }
void Clouds::samplerInit() { // sampler glGenSamplers(1, &linearSampler_noMipMaps); glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(linearSampler_noMipMaps, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glGenSamplers(1, &linearSampler_MipMaps); glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(linearSampler_MipMaps, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); }
OpenGLSamplerState::OpenGLSamplerState( const SamplerStateDesc& desc ) : SamplerState(desc), mSamplerOGL(0) { glGenSamplers(1, &mSamplerOGL); glSamplerParameteri(mSamplerOGL, GL_TEXTURE_WRAP_S, OpenGLMapping::Mapping(desc.AddressU)); glSamplerParameteri(mSamplerOGL, GL_TEXTURE_WRAP_T, OpenGLMapping::Mapping(desc.AddressV)); glSamplerParameteri(mSamplerOGL, GL_TEXTURE_WRAP_R, OpenGLMapping::Mapping(desc.AddressW)); GLenum min, mag; OpenGLMapping::Mapping( min, mag, desc.Filter ); glSamplerParameteri(mSamplerOGL, GL_TEXTURE_MAG_FILTER, mag); glSamplerParameteri(mSamplerOGL, GL_TEXTURE_MIN_FILTER, min); glSamplerParameterf(mSamplerOGL, GL_TEXTURE_MAX_ANISOTROPY_EXT, desc.MaxAnisotropy); glSamplerParameterf(mSamplerOGL, GL_TEXTURE_MIN_LOD, desc.MinLOD); glSamplerParameterf(mSamplerOGL, GL_TEXTURE_MAX_LOD, desc.MaxLOD); glSamplerParameterf(mSamplerOGL, GL_TEXTURE_LOD_BIAS , desc.MipLODBias); glSamplerParameterfv(mSamplerOGL, GL_TEXTURE_BORDER_COLOR, desc.BorderColor()); if (desc.CompareSampler) { // Use GL_COMPARE_REF_TO_TEXTURE glSamplerParameteri(mSamplerOGL, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glSamplerParameteri(mSamplerOGL, GL_TEXTURE_COMPARE_FUNC, OpenGLMapping::Mapping(desc.ComparisonFunc)); } OGL_ERROR_CHECK(); }
void TextureData::SetFiltering(dword p_iMag,dword p_iMin) { switch(p_iMag) { case MAG_NEAREST: glSamplerParameteri(m_iSampler,GL_TEXTURE_MAG_FILTER,GL_NEAREST); break; case MAG_BILINEAR: glSamplerParameteri(m_iSampler,GL_TEXTURE_MAG_FILTER,GL_LINEAR); break; }; switch(p_iMin) { case MIN_NEAREST: glSamplerParameteri(m_iSampler,GL_TEXTURE_MIN_FILTER,GL_NEAREST); break; case MIN_BILINEAR: glSamplerParameteri(m_iSampler,GL_TEXTURE_MIN_FILTER,GL_LINEAR); break; case MIN_NEAREST_MIPMAP: glSamplerParameteri(m_iSampler,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST); break; case MIN_BILINEAR_MIPMAP: glSamplerParameteri(m_iSampler,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); break; case MIN_TRILINEAR: glSamplerParameteri(m_iSampler,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); break; }; m_iMagFilter=p_iMag; m_iMinFilter=p_iMin; };
void GL::Sampler::setSamplingState(TextureTarget target, const SamplingState& state) { if (state.isParameterSet(SamplingState::Parameter::WrapS)) glSamplerParameteri(GLenum(target), GL_TEXTURE_WRAP_S, GLint(state.wrap.s)); if (state.isParameterSet(SamplingState::Parameter::WrapT)) glSamplerParameteri(GLenum(target), GL_TEXTURE_WRAP_T, GLint(state.wrap.t)); if (state.isParameterSet(SamplingState::Parameter::WrapR)) glSamplerParameteri(GLenum(target), GL_TEXTURE_WRAP_R, GLint(state.wrap.r)); if (state.isParameterSet(SamplingState::Parameter::MinFilter)) glSamplerParameteri(GLenum(target), GL_TEXTURE_MIN_FILTER, GLint(state.filter.min)); if (state.isParameterSet(SamplingState::Parameter::MagFilter)) glSamplerParameteri(GLenum(target), GL_TEXTURE_MAG_FILTER, GLint(state.filter.mag)); if (state.isParameterSet(SamplingState::Parameter::BorderColor)) glSamplerParameterfv(GLenum(target), GL_TEXTURE_BORDER_COLOR, &(state.borderColor.r)); if (state.isParameterSet(SamplingState::Parameter::MinLOD)) glSamplerParameterf(GLenum(target), GL_TEXTURE_MIN_LOD, state.LOD.min); if (state.isParameterSet(SamplingState::Parameter::MaxLOD)) glSamplerParameterf(GLenum(target), GL_TEXTURE_MAX_LOD, state.LOD.max); if (state.isParameterSet(SamplingState::Parameter::LODbias)) glSamplerParameterf(GLenum(target), GL_TEXTURE_LOD_BIAS, state.LOD.bias); if (state.isParameterSet(SamplingState::Parameter::CompareMode)) glSamplerParameteri(GLenum(target), GL_TEXTURE_COMPARE_MODE, GLint(state.compare.mode)); if (state.isParameterSet(SamplingState::Parameter::CompareFunc)) glSamplerParameteri(GLenum(target), GL_TEXTURE_COMPARE_FUNC, GLint(state.compare.func)); }
GLuint glCreateSamplerGTC(GLenum mag, GLenum min, GLenum mip, GLenum wrap, GLfloat borderColor[4], GLenum compare) { assert(mag == GL_LINEAR || mag == GL_NEAREST); assert(min == GL_LINEAR || min == GL_NEAREST); assert(mip == GL_LINEAR || mip == GL_NEAREST); GLuint sampler = 0; glCreateSamplers(1, &sampler); GLint minFilter = GL_NONE; if (min == GL_LINEAR) minFilter = mip == GL_LINEAR ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR_MIPMAP_NEAREST; else minFilter = mip == GL_LINEAR ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST; glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, minFilter); glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, mag); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, wrap); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, wrap); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_R, wrap); glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, borderColor); glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, compare == GL_NONE ? GL_NONE : GL_COMPARE_R_TO_TEXTURE); glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_FUNC, compare != GL_NONE ? compare : GL_LEQUAL); return sampler; }
void CTexture::SetFiltering(int a_tfMagnification, int a_tfMinification) { glBindSampler(0, uiSampler); // Set magnification filter if(a_tfMagnification == TEXTURE_FILTER_MAG_NEAREST) glSamplerParameteri(uiSampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); else if(a_tfMagnification == TEXTURE_FILTER_MAG_BILINEAR) glSamplerParameteri(uiSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Set minification filter if(a_tfMinification == TEXTURE_FILTER_MIN_NEAREST) glSamplerParameteri(uiSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST); else if(a_tfMinification == TEXTURE_FILTER_MIN_BILINEAR) glSamplerParameteri(uiSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); else if(a_tfMinification == TEXTURE_FILTER_MIN_NEAREST_MIPMAP) glSamplerParameteri(uiSampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); else if(a_tfMinification == TEXTURE_FILTER_MIN_BILINEAR_MIPMAP) glSamplerParameteri(uiSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); else if(a_tfMinification == TEXTURE_FILTER_MIN_TRILINEAR) glSamplerParameteri(uiSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); tfMinification = a_tfMinification; tfMagnification = a_tfMagnification; }
void Texture1D::updateToDeviceMemory(Image<unsigned int>&& source) { if (texture) glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_1D, texture); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA8, width(source) * height(source), 0, GL_RGBA, GL_UNSIGNED_BYTE, rawData(source)); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, (useFiltering) ? GL_LINEAR : GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, (useFiltering) ? GL_LINEAR : GL_NEAREST); if (sampler) glGenSamplers(1, &sampler); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_REPEAT); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_REPEAT); glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, (useFiltering) ? GL_LINEAR : GL_NEAREST); glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, (useFiltering) ? GL_LINEAR : GL_NEAREST); PGA_Rendering_GL_checkError(); }
CopyShader::CopyShader(FullscreenQuad& quad) : quad(quad), fs(Framework::preprocessShaderSource(::fs, "copy.fs").c_str()) { quad.attach(prog); prog.attachShader(fs); prog.link(); glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); glUseProgram(prog); GLuint tex = glGetUniformLocation(prog, "src"); glUniform1i(tex, 0); GL_CHECK_ERROR(); }
// Create the plane, including its geometry, texture mapping, normal, and colour void CCubemap::Create(string sPositiveX, string sNegativeX, string sPositiveY, string sNegativeY, string sPositiveZ, string sNegativeZ) { int iWidth, iHeight; // Generate an OpenGL texture ID for this texture glGenTextures(1, &m_uiTexture); glBindTexture(GL_TEXTURE_CUBE_MAP, m_uiTexture); // Load the six sides BYTE *pbImagePosX, *pbImageNegX, *pbImagePosY, *pbImageNegY, *pbImagePosZ, *pbImageNegZ; LoadTexture(sPositiveX, &pbImagePosX, iWidth, iHeight); LoadTexture(sNegativeX, &pbImageNegX, iWidth, iHeight); LoadTexture(sPositiveY, &pbImagePosY, iWidth, iHeight); LoadTexture(sNegativeY, &pbImageNegY, iWidth, iHeight); LoadTexture(sPositiveZ, &pbImagePosZ, iWidth, iHeight); LoadTexture(sNegativeZ, &pbImageNegZ, iWidth, iHeight); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, iWidth, iHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, pbImagePosX); glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, iWidth, iHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, pbImageNegX); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, iWidth, iHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, pbImagePosY); glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, iWidth, iHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, pbImageNegY); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, iWidth, iHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, pbImagePosZ); glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, iWidth, iHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, pbImageNegZ); delete[] pbImagePosX; delete[] pbImageNegX; delete[] pbImagePosY; delete[] pbImageNegY; delete[] pbImagePosZ; delete[] pbImageNegZ; glGenSamplers(1, &m_uiSampler); glSamplerParameteri(m_uiSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(m_uiSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(m_uiSampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_uiSampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_uiSampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glGenerateMipmap(GL_TEXTURE_CUBE_MAP); }
void LoadTextures() { glGenTextures(2, g_textures); std::string filename(LOCAL_FILE_DIR); filename += "gamma_ramp.png"; try { std::auto_ptr<glimg::ImageSet> pImageSet(glimg::loaders::stb::LoadFromFile(filename.c_str())); glimg::SingleImage image = pImageSet->GetImage(0, 0, 0); glimg::Dimensions dims = image.GetDimensions(); glimg::OpenGLPixelTransferParams pxTrans = glimg::GetUploadFormatType(pImageSet->GetFormat(), 0); glBindTexture(GL_TEXTURE_2D, g_textures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, dims.width, dims.height, 0, pxTrans.format, pxTrans.type, image.GetImageData()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, pImageSet->GetMipmapCount() - 1); glBindTexture(GL_TEXTURE_2D, g_textures[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8, dims.width, dims.height, 0, pxTrans.format, pxTrans.type, image.GetImageData()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, pImageSet->GetMipmapCount() - 1); glBindTexture(GL_TEXTURE_2D, 0); } catch(std::exception &e) { printf("%s\n", e.what()); throw; } glGenSamplers(1, &g_samplerObj); glSamplerParameteri(g_samplerObj, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(g_samplerObj, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(g_samplerObj, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(g_samplerObj, GL_TEXTURE_MIN_FILTER, GL_NEAREST); }
void SamplerCache::SetParameters(GLuint sampler_id, const Params& params) { static const GLint min_filters[8] = { GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, }; static const GLint wrap_settings[4] = { GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT, GL_REPEAT, }; auto& tm0 = params.tm0; auto& tm1 = params.tm1; glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER, min_filters[tm0.min_filter % ArraySize(min_filters)]); glSamplerParameteri(sampler_id, GL_TEXTURE_MAG_FILTER, tm0.mag_filter ? GL_LINEAR : GL_NEAREST); glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, wrap_settings[tm0.wrap_s]); glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T, wrap_settings[tm0.wrap_t]); glSamplerParameterf(sampler_id, GL_TEXTURE_MIN_LOD, tm1.min_lod / 16.f); glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_LOD, tm1.max_lod / 16.f); if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL) { glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, (s32)tm0.lod_bias / 32.f); if (g_ActiveConfig.iMaxAnisotropy > 0) glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)(1 << g_ActiveConfig.iMaxAnisotropy)); } }
SamplerCache::SamplerCache() : m_last_max_anisotropy() { glGenSamplers(2, m_sampler_id); glSamplerParameteri(m_sampler_id[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST); glSamplerParameteri(m_sampler_id[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(m_sampler_id[0], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_sampler_id[0], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_sampler_id[1], GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(m_sampler_id[1], GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(m_sampler_id[1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_sampler_id[1], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); }
SamplerCache::SamplerCache() { glGenSamplers(1, &m_point_sampler); glGenSamplers(1, &m_linear_sampler); glSamplerParameteri(m_point_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glSamplerParameteri(m_point_sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(m_point_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_point_sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_linear_sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(m_linear_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameteri(m_linear_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(m_linear_sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); }
void Renderer::loadTextures() { glGenTextures(1, &mTextures.water); { QImage image(gDefaultPathTextures + "water.png"); int imageSize = image.width(); //for now, assume all images are the same width and height glBindTexture(GL_TEXTURE_2D, mTextures.water); glUniform1i(ShaderProgram::raw().uniformLocation("waterTexture"), 0); int mipLevels = 8; glTexStorage2D(GL_TEXTURE_2D, mipLevels, GL_RGBA8, imageSize, imageSize); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imageSize, imageSize, GL_BGRA, GL_UNSIGNED_BYTE, image.bits()); glGenerateMipmap(GL_TEXTURE_2D); glSamplerParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glSamplerParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); } }