Ejemplo n.º 1
0
void RE_InitFBOs()
{
	GLenum DrawBuffers[1];	
	GLenum status;
	GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT };

	glConfig.oculusFBL = 0;
	glConfig.oculusFBR = 0;
	glGenFramebuffersEXT(1, &glConfig.oculusFBL);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, glConfig.oculusFBL);


	// The depth buffer	
	glGenRenderbuffers(1, &glConfig.oculusDepthRenderBufferLeft);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, glConfig.oculusDepthRenderBufferLeft);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, glConfig.vidWidth, glConfig.vidHeight);	
	
	glGenTextures(1, &glConfig.oculusRenderTargetLeft);	
	glBindTexture(GL_TEXTURE_2D, glConfig.oculusRenderTargetLeft);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, glConfig.vidWidth, glConfig.vidHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); // Empty Image
		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_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);
		glGenerateMipmapEXT(GL_TEXTURE_2D);
	
	glBindTexture(GL_TEXTURE_2D, 0);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, glConfig.oculusRenderTargetLeft, 0);


	glGenTextures(1, &glConfig.oculusRenderTargetRight);	
	glBindTexture(GL_TEXTURE_2D, glConfig.oculusRenderTargetRight);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, glConfig.vidWidth, glConfig.vidHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); // Empty Image
		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_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);
		glGenerateMipmapEXT(GL_TEXTURE_2D);
	
	glBindTexture(GL_TEXTURE_2D, 0);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, glConfig.oculusRenderTargetRight, 0);

	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, glConfig.oculusDepthRenderBufferLeft);

	//glDrawBuffers(2, (GLenum*)buffers);

	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if(status != GL_FRAMEBUFFER_COMPLETE_EXT)
		exit(1);

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);	// Unbind the FBO for now
}
Ejemplo n.º 2
0
t_value ml_glgeneratemipmapext (value target)
{
	CAMLparam1 (target);
	GLenum _target = conv_texture_binding_table[Int_val(target)]; 
	glGenerateMipmapEXT(_target);
	CAMLreturn (Val_unit);	
}
Ejemplo n.º 3
0
Texture2D Texture2D::createLinkedWith(FrameBuffer &buffer)
{
    Texture2D ret;
    ret.m_id = ResourceHeap::instance().create(textureConstructor,
                                               textureDestructor,
                                               ResourceHeap::Texture2D);
    ret.bind();

    // Set filtering parameters
    useParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    useParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    if (GLEW_EXT_texture_filter_anisotropic)
    {
        int maxAnisotropy = 0;
        glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
        useParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
    }

    // Link texture with framebuffer
    glTexImage2D(GL_TEXTURE_2D, /*level*/0,
                 GL_RGBA, buffer.width(), buffer.height(), /*border*/ 0,
                 GL_RGBA, GL_UNSIGNED_BYTE, /*pixels from FB*/ nullptr);
    glGenerateMipmapEXT(GL_TEXTURE_2D);

    // Link framebuffer with texture
    glFramebufferTexture2DEXT(
                buffer.type(),
                GL_COLOR_ATTACHMENT0_EXT, // attachment point
                GL_TEXTURE_2D,
                ret.m_id,
                0 // initial mip-level
                );
    return ret;
}
Ejemplo n.º 4
0
    void GLTexture::loadImpl()
    {
        if( mUsage & TU_RENDERTARGET )
        {
            createRenderTexture();
            return;
        }

        // Now the only copy is on the stack and will be cleaned in case of
        // exceptions being thrown from _loadImages
        LoadedImages loadedImages = mLoadedImages;
        mLoadedImages.setNull();

        // Call internal _loadImages, not loadImage since that's external and 
        // will determine load status etc again
        ConstImagePtrList imagePtrs;
        for (size_t i=0 ; i<loadedImages->size() ; ++i) {
            imagePtrs.push_back(&(*loadedImages)[i]);
        }

        _loadImages(imagePtrs);


        // Generate mipmaps after all texture levels have been loaded
        // This is required for compressed formats such as DXT
        // If we can do automip generation and the user desires this, do so
        if((mUsage & TU_AUTOMIPMAP) &&
            mNumRequestedMipmaps && mMipmapsHardwareGenerated)
        {
            glGenerateMipmapEXT(getGLTextureTarget());
        }
    }
Ejemplo n.º 5
0
bool Texture::LoadXOR() {
	width_ = height_ = 256;
	unsigned char *buf = new unsigned char[width_*height_*4];
	for (int y = 0; y < 256; y++) {
		for (int x = 0; x < 256; x++) {
			buf[(y*width_ + x)*4 + 0] = x^y;
			buf[(y*width_ + x)*4 + 1] = x^y;
			buf[(y*width_ + x)*4 + 2] = x^y;
			buf[(y*width_ + x)*4 + 3] = 0xFF;
		}
	}
	GL_CHECK();
	glGenTextures(1, &id_);
	glBindTexture(GL_TEXTURE_2D, id_);
	SetTextureParameters(ZIM_GEN_MIPS);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_, height_, 0,
		GL_RGBA, GL_UNSIGNED_BYTE, buf);
	if(gl_extensions.FBO_ARB){
		glGenerateMipmap(GL_TEXTURE_2D);
	}else{
#ifndef USING_GLES2
		glGenerateMipmapEXT(GL_TEXTURE_2D);
#endif
	}
	GL_CHECK();
	delete [] buf;
	return true;
}
void GFXGLTextureObject::reloadFromCache()
{
   if(!mZombieCache)
      return;
      
   if(mBinding == GL_TEXTURE_3D)
   {
      static_cast<GFXGLTextureManager*>(TEXMGR)->_loadTexture(this, mZombieCache);
      delete[] mZombieCache;
      mZombieCache = NULL;
      return;
   }
   
   PRESERVE_TEXTURE(mBinding);
   glBindTexture(mBinding, mHandle);

   if(mBinding == GL_TEXTURE_2D)
		glTexSubImage2D(mBinding, 0, 0, 0, mTextureSize.x, mTextureSize.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
   else if(mBinding == GL_TEXTURE_1D)
		glTexSubImage1D(mBinding, 0, 0, (mTextureSize.x > 1 ? mTextureSize.x : mTextureSize.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
   
   if(GFX->getCardProfiler()->queryProfile("GL::Workaround::needsExplicitGenerateMipmap") && mMipLevels != 1)
      glGenerateMipmapEXT(mBinding);
      
   delete[] mZombieCache;
   mZombieCache = NULL;
   mIsZombie = false;
}
Ejemplo n.º 7
0
bool Texture::LoadJPEG(const char *filename, bool genMips) {
	ILOG("Loading jpeg %s", filename);
	unsigned char *image_data;
	int actual_comps;
	image_data = jpgd::decompress_jpeg_image_from_file(filename, &width_, &height_, &actual_comps, 4);
	if (!image_data) {
		ELOG("jpeg: image data returned was 0");
		return false;
	}
	ILOG("Jpeg decoder failed to get RGB, got: %i x %i x %i", actual_comps, width_, height_);
	ILOG("First four bytes: %i %i %i %i", image_data[0], image_data[1], image_data[2], image_data[3]);

	GL_CHECK();
	glGenTextures(1, &id_);
	glBindTexture(GL_TEXTURE_2D, id_);
	SetTextureParameters(genMips ? ZIM_GEN_MIPS : ZIM_CLAMP);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_, height_, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
	if (genMips) {
		if (gl_extensions.FBO_ARB) {
			glGenerateMipmap(GL_TEXTURE_2D);
		} else {
#ifndef USING_GLES2
			glGenerateMipmapEXT(GL_TEXTURE_2D);
#endif
		}
	}
	GL_CHECK();
	free(image_data);
	return true;
}
Ejemplo n.º 8
0
void ToneMapping::process() {

    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();

    outport_.activateTarget();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    TextureUnit colorUnit, depthUnit;
    inport_.bindColorTexture(colorUnit.getEnum());
    if (toneMappingMethod_.get() == "rahman-retinex") {
        glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
        glGenerateMipmapEXT(GL_TEXTURE_2D);
    }
    inport_.bindDepthTexture(depthUnit.getEnum());

    // initialize shader
    program_->activate();
    setGlobalShaderParameters(program_);

    // set uniforms
    program_->setUniform("colorTex_", colorUnit.getUnitNumber());
    program_->setUniform("depthTex_", depthUnit.getUnitNumber());
    inport_.setTextureParameters(program_, "textureParameters_");

    // set method specific uniforms
    if (toneMappingMethod_.get() == "s-curve") {
        program_->setUniform("sigma_", scurveSigma_.get());
        program_->setUniform("power_", scurvePower_.get());
    }
    if (toneMappingMethod_.get() == "rahman-retinex") {
        if(rahmanTotalUpdate_ || inport_.hasChanged()){
            wTotal_ = 0.0f;
            float i = 0.0f;
            while(i<rahmanIterations_.get()){
                wTotal_ += pow(rahmanIterations_.get() - i + 1, rahmanFrequency_.get());
                i++;
            }
            rahmanTotalUpdate_ = false;
        }

        //colorUnit.activate();
        //glGenerateMipmapEXT(GL_TEXTURE_2D);

        program_->setUniform("frequency_", rahmanFrequency_.get());
        program_->setUniform("subtractionFactor_", rahmanSubtractionFactor_.get());
        program_->setUniform("iterations_", rahmanIterations_.get());
        program_->setUniform("maxLevel_", rahmanMaxLevel_.get());
        program_->setUniform("wTotal_", wTotal_);
    }

    renderQuad();

    program_->deactivate();
    outport_.deactivateTarget();
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}
Ejemplo n.º 9
0
void addTexture(TextureData *textureData, TextureRef *textureRef) {
   SDL_Surface *surface = (SDL_Surface *) textureData->data;

   int byteSize = surface->format->BytesPerPixel;
   
   // add a new texture. (update for RGBA)
   GLuint textureBuffer;
   glGenTextures(1, &textureBuffer);
   glBindTexture(GL_TEXTURE_2D, textureBuffer);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   
   if (byteSize == 3) {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, surface->w, surface->h, 0,
                   GL_BGR, GL_UNSIGNED_BYTE, surface->pixels);
   }
   else {
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0,
                  GL_BGRA, GL_UNSIGNED_BYTE, surface->pixels);
   }
   
   
   glGenerateMipmapEXT(GL_TEXTURE_2D);
   
   // Update the texture reference
   textureRef->textureBuffer = textureBuffer;
   textureRef->loaded = true;
   textureRef->loading = false;
   
   delete surface;
   delete textureData;
}
Ejemplo n.º 10
0
void Image::checkMipmapsCreated() const
{
	if (filter.mipmap != FILTER_NEAREST && filter.mipmap != FILTER_LINEAR)
		return;

	if (!hasMipmapSupport())
		throw love::Exception("Mipmap filtering is not supported on this system!");

	// some old GPUs/systems claim support for NPOT textures, but fail when generating mipmaps
	// we can't detect which systems will do this, so we fail gracefully for all NPOT images
	int w = int(width), h = int(height);
	if (w != next_p2(w) || h != next_p2(h))
		throw love::Exception("Could not generate mipmaps: image does not have power of two dimensions!");

	bind();

	GLint mipmapscreated;
	glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, &mipmapscreated);

	// generate mipmaps for this image if we haven't already
	if (!mipmapscreated)
	{
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

		if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
			glGenerateMipmap(GL_TEXTURE_2D);
		else if (GLEE_EXT_framebuffer_object)
			glGenerateMipmapEXT(GL_TEXTURE_2D);
		else
			// modify single texel to trigger mipmap chain generation
			glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data->getData());
	}
}
Ejemplo n.º 11
0
void Texture::createTextureObject(int context_id)
{
	GLuint& id = _ids[context_id];

	glEnable(GL_TEXTURE_2D);
	glGenTextures(1, &id);
	glBindTexture(GL_TEXTURE_2D, id);

	applyParams();  

	// Get the maximum texture size for this GPU.
	GLint max_size = 0;
	glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_size);
	if (_width > max_size || _height > max_size)
	{
		gluBuild2DMipmaps(GL_TEXTURE_2D,
	                  _params.internalFormat,
	                  _width, _height,
	                  GL_BGRA,
	                  GL_UNSIGNED_BYTE,
	                  FreeImage_GetBits (_data));
		checkGLErrors("Texture::createTextureObject1 - gluBuild2DMipmaps");
	}
	else
	{
		glTexImage2D (GL_TEXTURE_2D, 0, _params.internalFormat, _width, _height, 0, GL_BGRA, GL_UNSIGNED_BYTE, FreeImage_GetBits (_data));
		glGenerateMipmapEXT (GL_TEXTURE_2D);
		checkGLErrors("Texture::createTextureObject1 - glTexImage2D");
	}

	unbind();
}
Ejemplo n.º 12
0
static int
create_fbo(void)
{
	GLuint tex, fb;
	GLenum status;
	int i, dim;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);

	for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
		glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA,
			     dim, dim,
			     0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	}
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex,
				  0);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "FBO incomplete\n");
		goto done;
	}

	glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT);
	piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE);

	glColor4fv(red);
	piglit_draw_rect(0, 0, TEX_WIDTH / 2, TEX_HEIGHT / 2);
	glColor4fv(green);
	piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, TEX_HEIGHT / 2);
	glColor4fv(blue);
	piglit_draw_rect(0, TEX_HEIGHT / 2, TEX_WIDTH/2, TEX_HEIGHT);
	glColor4fv(white);
	piglit_draw_rect(TEX_WIDTH / 2, TEX_HEIGHT / 2, TEX_WIDTH, TEX_HEIGHT);

	glScissor(10, 10, 10, 10);
	glEnable(GL_SCISSOR_TEST);
	glGenerateMipmapEXT(GL_TEXTURE_2D);
	glDisable(GL_SCISSOR_TEST);
done:
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);

	return tex;
}
Ejemplo n.º 13
0
static GLuint
create_array_fbo_2d(void)
{
	GLuint tex, fb;
	GLenum status;
	int i, dim;
	int layer;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, tex);
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
		glTexImage3D(GL_TEXTURE_2D_ARRAY_EXT, i, format,
			     dim, dim, num_layers, 0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	}
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

	for (layer = 0; layer < num_layers; layer++) {
		glFramebufferTextureLayer(GL_FRAMEBUFFER_EXT,
					  GL_COLOR_ATTACHMENT0_EXT,
					  tex,
					  0,
					  layer);
		if (!piglit_check_gl_error(GL_NO_ERROR))
		        piglit_report_result(PIGLIT_FAIL);

		status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
			load_texture_2d_array();
			goto done;
		}

		glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT);
		piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE);

		glColor4fv(layer_color[layer]);
		piglit_draw_rect(0, 0, TEX_WIDTH / 2, TEX_HEIGHT / 2);
		glColor4fv(green);
		piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, TEX_HEIGHT / 2);
		glColor4fv(blue);
		piglit_draw_rect(0, TEX_HEIGHT / 2, TEX_WIDTH/2, TEX_HEIGHT);
		glColor4fv(white);
		piglit_draw_rect(TEX_WIDTH / 2, TEX_HEIGHT / 2, TEX_WIDTH, TEX_HEIGHT);
	}

done:
	glGenerateMipmapEXT(GL_TEXTURE_2D_ARRAY_EXT);
	glDeleteFramebuffersEXT(1, &fb);
	return tex;
}
Ejemplo n.º 14
0
void FrameBuffer::automaticallyGenerateMipmaps(int attachment)
{
	assert(m_automaticMipmapsEnabled);
	
	GLenum type = textureType(attachment);
	glBindTexture(type, textureID(attachment));
	glGenerateMipmapEXT(type);
	glBindTexture(type, 0);
}
Ejemplo n.º 15
0
void GLTexture::refresh() {
	Bitmap *bitmap = getBitmap();

	/* Bind to the texture */
	glBindTexture(m_glType, m_id);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	if (m_type == ETexture1D) {
		Assert((math::isPowerOfTwo(m_size.x) && m_size.y == 1)
			|| (math::isPowerOfTwo(m_size.y) && m_size.x == 1));

		if (isMipMapped()) {
			/* Let GLU generate mipmaps for us */
			gluBuild1DMipmaps(m_glType, m_internalFormat, m_size.x == 1 ? m_size.y : m_size.x,
				m_format, m_dataFormat, bitmap->getData());
		} else {
		}
		glTexImage1D(m_glType, 0, m_internalFormat, m_size.x == 1 ? m_size.y : m_size.x,
			0, m_format, m_dataFormat, bitmap->getData());
	} else if (m_type == ETexture2D) {
		/* Anisotropic texture filtering */
		float anisotropy = (float) getMaxAnisotropy();
		if (isMipMapped() && m_filterType == EMipMapLinear && anisotropy > 1.0f)
			glTexParameterf(m_glType, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);

		glTexImage2D(m_glType, 0, m_internalFormat, m_size.x, m_size.y,
			0, m_format, m_dataFormat, bitmap->getData());
	} else if (m_type == ETextureCubeMap) {
		Assert(bitmap != NULL);
		Assert(bitmap->getWidth() == bitmap->getHeight());
		Assert(math::isPowerOfTwo(bitmap->getWidth()));
		if (isMipMapped())
			glTexParameteri(m_glType, GL_GENERATE_MIPMAP, GL_TRUE);

		for (int i=0; i<6; i++) {
			Bitmap *bitmap = getBitmap(i);

			GLuint pos;
			switch (i) {
				case ECubeMapPositiveX: pos = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break;
				case ECubeMapNegativeX: pos = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break;
				case ECubeMapPositiveY: pos = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break;
				case ECubeMapNegativeY: pos = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break;
				case ECubeMapPositiveZ: pos = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break;
				case ECubeMapNegativeZ: pos = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break;
				default: Log(EError, "Unknown cube map index"); return;
			};

			glTexImage2D(pos, 0, m_internalFormat, bitmap->getWidth(), bitmap->getHeight(),
				0, m_format, m_dataFormat, bitmap->getData());
		}
	} else {
		Log(EError, "Unknown texture type!");
	}
	if (isMipMapped())
		glGenerateMipmapEXT(m_glType);
}
Ejemplo n.º 16
0
void Texture::createMipmaps (int context_id)
{
	if (valid (context_id))
	{
		bind (context_id);
		glGenerateMipmapEXT (GL_TEXTURE_2D);
		unbind ();
	}
}
void WebGraphicsContext3DDefaultImpl::generateMipmap(unsigned long target)
{
    makeContextCurrent();
    if (glGenerateMipmapEXT)
        glGenerateMipmapEXT(target);
    // FIXME: provide alternative code path? This will be unpleasant
    // to implement if glGenerateMipmapEXT is not available -- it will
    // require a texture readback and re-upload.
}
Ejemplo n.º 18
0
void
piglit_init(int argc, char **argv)
{
	piglit_require_extension("GL_EXT_framebuffer_object");

	glGenerateMipmapEXT(GL_TEXTURE_2D);

	piglit_report_result(PIGLIT_PASS);
}
Ejemplo n.º 19
0
void Renderer::endRenderFBO()
{
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // unbind
    
    glBindTexture(GL_TEXTURE_2D, img);
    glGenerateMipmapEXT(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 0);
    
    glViewport(0, 0, WIDTH, HEIGHT);
}
 inline void VL_glGenerateMipmap(GLenum target)
 {
   if (glGenerateMipmap)
     glGenerateMipmap(target);
   else
   if (glGenerateMipmapEXT)
     glGenerateMipmapEXT(target);
   else
     VL_UNSUPPORTED_FUNC();
 }
static int
create_fbo(void)
{
	GLuint tex, fb;
	GLenum status;
	int i, dim;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);

	for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
		glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA,
			     dim, dim,
			     0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	}
	assert(glGetError() == 0);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
				  GL_COLOR_ATTACHMENT0_EXT,
				  GL_TEXTURE_2D,
				  tex,
				  0);
	assert(glGetError() == 0);

	status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "FBO incomplete\n");
		goto done;
	}

	glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT);
	piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE);

	glColor4fv(red);
	piglit_draw_rect(0, 0, TEX_WIDTH / 2, TEX_HEIGHT / 2);
	glColor4fv(green);
	piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, TEX_HEIGHT / 2);
	glColor4fv(blue);
	piglit_draw_rect(0, TEX_HEIGHT / 2, TEX_WIDTH/2, TEX_HEIGHT);
	glColor4fv(white);
	piglit_draw_rect(TEX_WIDTH / 2, TEX_HEIGHT / 2, TEX_WIDTH, TEX_HEIGHT);

	/* Bind back to the (small) window to trigger the bug */
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);

	glGenerateMipmapEXT(GL_TEXTURE_2D);
done:
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);

	return tex;
}
Ejemplo n.º 22
0
    void
    BufferToTexture::performAction(GLSourceBuffer theSourceBuffer)
    {
        if (theSourceBuffer == FRAME_BUFFER) {
            glReadBuffer(GL_BACK);
        }

        unsigned myWidth = getWidth();
        unsigned myHeight = getHeight();
        GLuint myTextureID = _myTexture->getTextureId();
        AC_DEBUG << "BufferToTexture::performAction '" << _myTexture->get<NameTag>() << "' id=" << _myTexture->get<IdTag>() << " offset=" << _myOffset << " " << myWidth << "x" << myHeight << " texId=" << myTextureID;
        if (_myCopyToImage) {

            ImagePtr myImage = _myTexture->getImage();
            if (!myImage) {
                AC_WARNING << "Texture '" << _myTexture->get<NameTag>() << "' id=" << _myTexture->get<IdTag>() << " has no image associated";
            } else {
                AC_DEBUG << "BufferToTexture::performAction copy to image '" << myImage->get<NameTag>() << "' id=" << myImage->get<IdTag>();

                // copy framebuffer to Image raster
                PixelEncodingInfo myPixelEncodingInfo = getDefaultGLTextureParams(myImage->getRasterEncoding());
                myPixelEncodingInfo.internalformat = asGLTextureInternalFormat(_myTexture->getInternalEncoding());

                glReadPixels(_myOffset[0],_myOffset[1], myWidth,myHeight,
                        myPixelEncodingInfo.externalformat, myPixelEncodingInfo.pixeltype,
                        myImage->getRasterPtr()->pixels().begin());
                CHECK_OGL_ERROR;

                //_myTexture->preload();
            }
        } else if (myTextureID > 0) {
            GLenum myTextureTarget = asGLTextureTarget(_myTexture->getType());
            if (myTextureTarget == GL_TEXTURE_2D) {
                AC_DEBUG << "BufferToTexture::performAction copy to texture";

                // copy framebuffer to texture
                glBindTexture(GL_TEXTURE_2D, myTextureID);
                glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, _myOffset[0],_myOffset[1], myWidth,myHeight);
                CHECK_OGL_ERROR;

                // generate mipmap levels
                if (hasCap("GL_GENERATE_MIPMAP") && _myTexture->get<TextureMipmapTag>()) {
                    AC_TRACE << "BufferToTexture::performAction: generating mipmap levels";
                    glGenerateMipmapEXT(GL_TEXTURE_2D);
                    CHECK_OGL_ERROR;
                }

                glBindTexture(GL_TEXTURE_2D, 0);
            } else {
                AC_WARNING << "Copy to texture only supported for 'texture_2d'";
            }
        } else {
            AC_DEBUG << "BufferToTexture::performAction texture '" << _myTexture->get<NameTag>() << "' is not valid";
        }
    }
Ejemplo n.º 23
0
enum piglit_result
piglit_display(void)
{
	bool pass = true;
	float red[4] = {1.0, 0.0, 0.0, 0.0};
	float green[4] = {0.0, 1.0, 0.0, 0.0};
	GLuint q, texture;
	int tex_size = 64;
	int i;

	glClearColor(0.5, 0.5, 0.5, 0.5);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Set up a texture object with green at level 0, red elsewhere */
	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, texture);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
			GL_LINEAR_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

	for (i = 0; tex_size / (1 << i) > 0; i++)
		fill_level(i, tex_size / (1 << i), i == 0 ? green : red);

	glGenQueries(1, &q);

	/* Generate query fail. */
	glBeginQuery(GL_SAMPLES_PASSED, q);
	glEndQuery(GL_SAMPLES_PASSED);

	/* Mipmap generation should not be affected by conditional rendering. */
	glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV);
	glGenerateMipmapEXT(GL_TEXTURE_2D);
	glEndConditionalRenderNV();

	/* This should draw level 1, since starting window size is 32
	 * and texture is 64.
	 */
	glEnable(GL_TEXTURE_2D);
	piglit_draw_rect_tex(-1, -1, 2, 2,
			     0, 0, 1, 1);
	glDisable(GL_TEXTURE_2D);

	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
				      green);

	glutSwapBuffers();

	glDeleteQueries(1, &q);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Ejemplo n.º 24
0
void Texture::GenerateMipmaps(const Image& image, MipmapGeneration mipmapGeneration, const GLInfo& glInfo) const
{
   Texture::SetUnpackAlignmentForPixelComponents(image.NumPixelComponents());

   Texture::SendTextureData(image, 0);

   if (mipmapGeneration == MipmapGeneration::Manual)
   {
      GenerateManualMipmaps(image);
      return;
   }

   if (mipmapGeneration == MipmapGeneration::GLGenerateMipMap)
   {
      GLInfo::Vendor vendor = glInfo.GetVendor();

      if ((vendor == GLInfo::Vendor::Microsoft) || (vendor == GLInfo::Vendor::Unknown))
      {
         GenerateMipmapsLegacy(image);
         return;
      }

      bool vendorIsATI = (vendor == GLInfo::Vendor::ATI);

      if (GLEW_VERSION_3_0)
      {
         if (vendorIsATI)
         {
            glEnable(GL_TEXTURE_2D);
         }

         glGenerateMipmap(GL_TEXTURE_2D);
         return;
      }

      if (GLEW_VERSION_2_1 && glewIsExtensionSupported("GL_EXT_framebuffer_object"))
      {
         if (vendorIsATI)
         {
            glEnable(GL_TEXTURE_2D);
         }

         glGenerateMipmapEXT(GL_TEXTURE_2D);
         return;
      }
   }

   if (mipmapGeneration == MipmapGeneration::None)
   {
      return;
   }

   GenerateMipmapsLegacy(image);
}
void RenderToTexture::unbind()
{
	// output goes to the FBO and it’s attached buffers
	glPopAttrib();
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	if (generate_mipmaps)
	{
		glBindTexture(GL_TEXTURE_2D, texture_id);
		glGenerateMipmapEXT(GL_TEXTURE_2D);
	}
}
Ejemplo n.º 26
0
static GLuint
create_array_fbo_1d(void)
{
	GLuint tex, fb;
	GLenum status;
	int i, dim;
	int layer;

	if (format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
		return 0;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_1D_ARRAY_EXT, tex);
	assert(glGetError() == 0);

	for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
		glTexImage2D(GL_TEXTURE_1D_ARRAY_EXT, i, format,
			     dim, num_layers, 0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	}
	assert(glGetError() == 0);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

	for (layer = 0; layer < num_layers; layer++) {
		glFramebufferTextureLayer(GL_FRAMEBUFFER_EXT,
					  GL_COLOR_ATTACHMENT0_EXT,
					  tex,
					  0,
					  layer);
		assert(glGetError() == 0);

		status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
			load_texture_1d_array();
			goto done;
		}

		glViewport(0, 0, TEX_WIDTH, 1);
		piglit_ortho_projection(TEX_WIDTH, 1, GL_FALSE);

		glColor4fv(layer_color[layer]);
		piglit_draw_rect(0, 0, TEX_WIDTH / 2, 1);
		glColor4fv(layer_color[(layer + 1) % 4]);
		piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, 1);
	}

done:
	glDeleteFramebuffersEXT(1, &fb);
	glGenerateMipmapEXT(GL_TEXTURE_1D_ARRAY_EXT);
	return tex;
}
Ejemplo n.º 27
0
void FrameBufferObject::generateDepthBufferMipMap() const
{
	if(this->depthType==FBO_DepthBufferType_TEXTURE)
	{
		if(this->depthMinificationFiltering==GL_NEAREST
		|| this->depthMinificationFiltering==GL_LINEAR)
			return;	//don't allow to generate mipmap chain for texture that don't support it at the creation

		glBindTexture(GL_TEXTURE_2D, this->depthID);
		glGenerateMipmapEXT(GL_TEXTURE_2D);
	}
}
Ejemplo n.º 28
0
void FrameBufferObject::generateColorBufferMipMap(const unsigned int colorBufferNum) const
{
	if(this->nbColorAttachement>0 && (int)colorBufferNum<this->nbColorAttachement)
	{
		if(this->colorMinificationFiltering[colorBufferNum]==GL_NEAREST
		|| this->colorMinificationFiltering[colorBufferNum]==GL_LINEAR)
			return;	//don't allow to generate mipmap chain for texture that don't support it at the creation

		glBindTexture(GL_TEXTURE_2D, this->colorTextures[colorBufferNum]);
		glGenerateMipmapEXT(GL_TEXTURE_2D);
	}
}
Ejemplo n.º 29
0
	void OGLTexture::BuildMipSubLevels()
	{
		if (glloader_GL_EXT_framebuffer_object())
		{
			this->GLBindTexture();
			glGenerateMipmapEXT(target_type_);
		}
		else
		{
			THR(errc::function_not_supported);
		}
	}
Ejemplo n.º 30
0
void glBuildMipmaps(const GLenum target, GLint internalFormat, const GLsizei width, const GLsizei height, const GLenum format, const GLenum type, const void* data)
{
	ScopedTimer timer("Textures::glBuildMipmaps");

	if (globalRendering->compressTextures) {
		switch ( internalFormat ) {
			case 4:
			case GL_RGBA8 :
			case GL_RGBA :  internalFormat = GL_COMPRESSED_RGBA_ARB; break;

			case 3:
			case GL_RGB8 :
			case GL_RGB :   internalFormat = GL_COMPRESSED_RGB_ARB; break;

			case GL_LUMINANCE: internalFormat = GL_COMPRESSED_LUMINANCE_ARB; break;
		}
	}

	// create mipmapped texture

	if (IS_GL_FUNCTION_AVAILABLE(glGenerateMipmapEXT) && !globalRendering->atiHacks) {
		// newest method
		glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, data);
		if (globalRendering->atiHacks) {
			glEnable(target);
			glGenerateMipmapEXT(target);
			glDisable(target);
		} else {
			glGenerateMipmapEXT(target);
		}
	} else if (GLEW_VERSION_1_4) {
		// This required GL-1.4
		// instead of using glu, we rely on glTexImage2D to create the Mipmaps.
		glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE);
		glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, data);
	} else {
		gluBuild2DMipmaps(target, internalFormat, width, height, format, type, data);
	}
}