// TODO set texture unit upfront Texture2D::Texture2D(GLsizei width, GLsizei height, GLuint mipmapLevels) { glEnable(GL_TEXTURE_2D); m_width = width; m_height = height; m_mipmapLevels = 8; glGenTextures(1, &m_TBO); bind(); glTexStorage2D(GL_TEXTURE_2D, m_mipmapLevels, GL_RGBA32F, m_width, m_height); if(m_mipmapLevels > 0) { setMagFilter(GL_LINEAR_MIPMAP_LINEAR); setMinFilter(GL_LINEAR_MIPMAP_LINEAR); } else { setMagFilter(GL_LINEAR); setMinFilter(GL_LINEAR); } setWrapModeS(GL_REPEAT); setWrapModeT(GL_REPEAT); }
SamplerState::SamplerState() { memset(this, 0, sizeof(SamplerState)); setMinFilter(GL_NEAREST_MIPMAP_LINEAR); setMagFilter(GL_LINEAR); setWrapS(GL_REPEAT); setWrapT(GL_REPEAT); setWrapR(GL_REPEAT); setMaxAnisotropy(1.0f); setMinLod(-1000.0f); setMaxLod(1000.0f); setCompareMode(GL_NONE); setCompareFunc(GL_LEQUAL); setSRGBDecode(GL_DECODE_EXT); }
Sampler::Sampler ( unsigned int wrapModeS , unsigned int wrapModeT , unsigned int wrapModeR , unsigned int minFilter , unsigned int magFilter ) : id( createGLSampler() ) { bind( Texture< 0 >::SETUP_UNIT ); setWrapModeS( wrapModeS ); setWrapModeT( wrapModeT ); setWrapModeR( wrapModeR ); setMinFilter( minFilter ); setMagFilter( magFilter ); }
PHRect PHGLTexture2D::loadFromData(uint8_t * buf, size_t w, size_t h, size_t bw, size_t bh, enum pixelFormat fmt, bool aa) { if (gm->hasCapability(PHGLCapabilityAppleLimitedNPOT)) { bool pots = ((w & ~(w ^ (w-1))) == 0) && ((h & ~(h ^ (h-1))) == 0); if (!pots) { aa = false; } } bind_begin; setWrapS(clampToEdge); setWrapT(clampToEdge); setMinFilter(aa?linearMipmapNearest:linear); setMagFilter(linear); setData(buf, bw, bh, fmt); bind_end; return PHRect(0, 0, w/float(bw), h/float(bh)); }
bool Texture2D::generateTextureHandle() { if (d->textureId > 0) { m_error = "Refusing to overwrite existing texture handle."; return false; } glGenTextures(1, &d->textureId); if (d->textureId == 0) { m_error = "Error generating texture handle."; return false; } // Set up defaults to match the documentation: setMinFilter(Linear); setMagFilter(Linear); setWrappingS(Repeat); setWrappingT(Repeat); return true; }