Esempio n. 1
0
void CTexture::Init(CPixelBuffer *pBuffer, bool bClamp, bool bMipmap)
{
	Cleanup();
	m_nType = (pBuffer->GetHeight() > 1) ? GL_TEXTURE_2D : GL_TEXTURE_1D;

	glGenTextures(1, &m_nID);
	Bind();
	//glTexParameteri(m_nType, GL_TEXTURE_WRAP_R, bClamp ? GL_CLAMP : GL_REPEAT);
	glTexParameteri(m_nType, GL_TEXTURE_WRAP_S, bClamp ? GL_CLAMP : GL_REPEAT);
	glTexParameteri(m_nType, GL_TEXTURE_WRAP_T, bClamp ? GL_CLAMP : GL_REPEAT);
	glTexParameteri(m_nType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(m_nType, GL_TEXTURE_MIN_FILTER, bMipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);

	switch(m_nType)
	{
		case GL_TEXTURE_1D:
			if(bMipmap)
				gluBuild1DMipmaps(GL_TEXTURE_1D, pBuffer->GetChannels(), pBuffer->GetWidth(), pBuffer->GetFormat(), pBuffer->GetDataType(), pBuffer->GetBuffer());
			else
				glTexImage1D(GL_TEXTURE_1D, 0, pBuffer->GetChannels(), pBuffer->GetWidth(), 0, pBuffer->GetFormat(), pBuffer->GetDataType(), pBuffer->GetBuffer());
			break;
		case GL_TEXTURE_2D:
			if(bMipmap)
				gluBuild2DMipmaps(GL_TEXTURE_2D, pBuffer->GetChannels(), pBuffer->GetWidth(), pBuffer->GetHeight(), pBuffer->GetFormat(), pBuffer->GetDataType(), pBuffer->GetBuffer());
			else
				glTexImage2D(GL_TEXTURE_2D, 0, pBuffer->GetChannels(), pBuffer->GetWidth(), pBuffer->GetHeight(), 0, pBuffer->GetFormat(), pBuffer->GetDataType(), pBuffer->GetBuffer());
			break;
	}
}
Esempio n. 2
0
static int tolua_glu_gluBuild1DMipmaps00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
     !tolua_isnumber(tolua_S,5,0,&tolua_err) ||
     !tolua_isusertype(tolua_S,6,"GLLbuffer",0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,7,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
   int target = ((  int)  tolua_tonumber(tolua_S,1,0));
   int components = ((  int)  tolua_tonumber(tolua_S,2,0));
   int width = ((  int)  tolua_tonumber(tolua_S,3,0));
   int format = ((  int)  tolua_tonumber(tolua_S,4,0));
   int type = ((  int)  tolua_tonumber(tolua_S,5,0));
  GLLbuffer* data = ((GLLbuffer*)  tolua_tousertype(tolua_S,6,0));
  {
    int tolua_ret = (  int)  gluBuild1DMipmaps(target,components,width,format,type,data);
   tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
  }
 }
 return 1;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'gluBuild1DMipmaps'.",&tolua_err);
 return 0;
#endif
}
Esempio n. 3
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);
}
Esempio n. 4
0
void MeshView::generateTexture()
{
    const int size = 1024;

    QImage image( size, 1, QImage::Format_ARGB32 );

    QRgb* line = (QRgb*)image.scanLine( 0 );
    DataFunctions::fillGradientCache( m_gradient, line, size );

    QImage textureImage = QGLWidget::convertToGLFormat( image );

    if ( m_textureId == 0 )
        glGenTextures( 1, &m_textureId );

    glBindTexture( GL_TEXTURE_1D, m_textureId );
    gluBuild1DMipmaps( GL_TEXTURE_1D, 4, size, GL_RGBA, GL_UNSIGNED_BYTE, textureImage.bits() );

    glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
    glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    glEnable( GL_TEXTURE_1D );
}
Esempio n. 5
0
File: utils.hpp Progetto: Bartzi/CG2
GLuint
loadTextureRAW1D(const char * filename, bool wrap, unsigned int width, unsigned int depth)
{
    //
    // Aufgabe 1.b
    //
    GLuint texture;
	char* data;
	FILE* file;

	data = (char*) malloc( width * depth );

	file = fopen( filename, "rb" );
	if ( file == NULL ) return 0;

	fread( data, width * depth, 1, file );
	fclose( file );

    glGenTextures( 1, &texture );
    GET_GLERROR(0);
	glBindTexture( GL_TEXTURE_1D, texture );
	GET_GLERROR(0);
	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
	GET_GLERROR(0);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
	GET_GLERROR(0);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	GET_GLERROR(0);
	glTexParameteri ( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, static_cast<GLfloat>(wrap ? GL_REPEAT : GL_CLAMP) );
	GET_GLERROR(0);
	glTexParameteri ( GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, static_cast<GLfloat>(wrap ? GL_REPEAT : GL_CLAMP) );
	GET_GLERROR(0);
	gluBuild1DMipmaps( GL_TEXTURE_1D, depth, width, (depth == 1) ? GL_LUMINANCE : GL_RGB, GL_UNSIGNED_BYTE, data );


	free ( data );

    return texture;
}
Esempio n. 6
0
bool    Texture :: upload ( int target, bool mipmap )
{
    if ( target == GL_TEXTURE_1D )
    {
        if ( mipmap )
            gluBuild1DMipmaps ( target, getNumComponents (), getWidth (),
                                getFormat (), GL_UNSIGNED_BYTE, getData () );
        else
            glTexImage1D      ( target, 0, getNumComponents (), getWidth (), 0,
                                getFormat (), GL_UNSIGNED_BYTE, getData () );
    }
    else
    {
        if ( mipmap )
            gluBuild2DMipmaps ( target, getNumComponents (), getWidth (), getHeight (),
                                getFormat (), GL_UNSIGNED_BYTE, getData () );
        else
            glTexImage2D      ( target, 0, getNumComponents (), getWidth (), getHeight (), 0,
                                getFormat (), GL_UNSIGNED_BYTE, getData () );
    }

    return true;
}
Esempio n. 7
0
/*BuildMipmaps(components, format, pixelsArray) -> error */
static int luaglu_build_mipmaps(lua_State *L)
{
  GLubyte *pixels;
  GLsizei width, height;
  int components;

  components = luaL_checkinteger(L, 1);
  height = luagl_get_array2uc(L, 3, &pixels, &width);

  if (height != -1)
  {
    lua_pushnumber(L, gluBuild2DMipmaps(GL_TEXTURE_2D, components, width/components, height, 
                 luagl_get_gl_enum(L, 2), GL_UNSIGNED_BYTE, pixels));
  }
  else
  {
    /* if not 2D, get 1D */
    width = luagl_get_arrayuc(L, 3, &pixels);
    lua_pushnumber(L, gluBuild1DMipmaps(GL_TEXTURE_1D, components, width/components, 
                 luagl_get_gl_enum(L, 2), GL_UNSIGNED_BYTE, pixels));
  }
  LUAGL_DELETE_ARRAY(pixels);
  return 1;
}
Esempio n. 8
0
/*Build1DMipmaps(components, width, format, type, pixels) -> error      (userdata)*/
static int luaglu_build_1d_mipmaps(lua_State *L)
{
  lua_pushnumber(L, gluBuild1DMipmaps(GL_TEXTURE_1D, (GLint)luaL_checkinteger(L, 1), luaL_checkinteger(L, 2), 
               luagl_get_gl_enum(L, 3), luagl_get_gl_enum(L, 4), luagl_checkuserdata(L, 5)));
  return 1;
}
void CTextureSurfaceList::BuildSurfaceList(const CMemoryBuffer & data, size_t width, size_t height, size_t depth)
{
	if(!width || !height || !depth)
		throw NOVA_EXP("CTextureSurfaceList::BuildSurfaseList - incorrect input size param.", BAD_OPERATION);

	GLenum type = CHardwarePixelBuffer::TextureTarget(mType);
	bool mipmap_hardware_gen = CRenderSystem::GetSingelton().CheckCapabilities(TEXTURE_CATEGORY, CAP_AUTOMIPMAP);
	COpenGLFormats informat;
	informat.SetExFormat(mPixelFormat);
	mMaxMipmaps = GetMaxMipmaps(width, height, depth);

	glEnable(type);

	if(mType == CHardwarePixelBuffer::USE_CUBEMAP_TEXTURE && mFace > 0) {}
	else
		glGenTextures(1, &mTargetId);

	glBindTexture(type, mTargetId);

	if(mMipState == USE_HARDWARE_MIPMAPS)
	{
		if(!mipmap_hardware_gen)
			mMipState = USE_SOFTWARE_MIPMAPS;
	}

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	if(mMipState == DO_NOT_USE_MIPMAPS)
	{
		glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

		mMaxMipmaps = 1;

		switch(mType)
		{
		case CHardwarePixelBuffer::USE_TEXTURE_1D:
			glTexImage1D(GL_TEXTURE_1D, 0, informat.GetInternalChannels(),
				width, 0, informat.GetFormat(), GL_UNSIGNED_BYTE, data.GetBegin());
			break;
		case CHardwarePixelBuffer::USE_TEXTURE_2D:
			glTexImage2D(GL_TEXTURE_2D, 0, informat.GetInternalChannels(),
				width, height, 0, informat.GetFormat(), GL_UNSIGNED_BYTE, data.GetBegin());
			break;
		case CHardwarePixelBuffer::USE_TEXTURE_3D:
			glTexImage3D(GL_TEXTURE_3D, 0, informat.GetInternalChannels(),
				width, height, depth, 0, informat.GetFormat(), GL_UNSIGNED_BYTE, data.GetBegin());
			break;
		case CHardwarePixelBuffer::USE_CUBEMAP_TEXTURE:
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + mFace, 0, informat.GetInternalChannels(),
				width, height, 0, informat.GetFormat(), GL_UNSIGNED_BYTE, data.GetBegin());
			break;
		}
	}
	else if(mMipState == USE_SOFTWARE_MIPMAPS)
	{
		glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

		switch(mType)
		{
		case CHardwarePixelBuffer::USE_TEXTURE_1D:
			gluBuild1DMipmaps(GL_TEXTURE_1D, informat.GetInternalChannels(),
				width, informat.GetFormat(), GL_UNSIGNED_BYTE, data.GetBegin());
			break;
		case CHardwarePixelBuffer::USE_TEXTURE_2D:
			gluBuild2DMipmaps(GL_TEXTURE_2D, informat.GetInternalChannels(),
				width, height, informat.GetFormat(), GL_UNSIGNED_BYTE, data.GetBegin());
			break;
		case CHardwarePixelBuffer::USE_CUBEMAP_TEXTURE:
			gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_X + mFace, informat.GetInternalChannels(),
				width, height, informat.GetFormat(), GL_UNSIGNED_BYTE, data.GetBegin());
			break;
		case CHardwarePixelBuffer::USE_TEXTURE_3D:
			throw NOVA_EXP("CTextureSurfaceList::BuildSurfaseList - \
				OpenGL can not support software 3D mipmaps", BAD_OPERATION);
			break;
		}
	}
void Texture::setup_texture_data(
								 int dim,
								 Image::ColorEncoding encoding_in, 
								 Memory::pointer base_mem_in,
								 Texture::FilteringMode mode,
								 int width, int height, int depth) 
{
	const int static_buffer_size = 1024*1024 ;
	static Memory::byte static_buffer[static_buffer_size * 4] ;
	Memory::pointer dynamic_buffer = nil ;
	Memory::pointer base_mem = base_mem_in ;
	Image::ColorEncoding encoding = encoding_in ;

	mipmap_ = (mode == Texture::MIPMAP) ;
	linear_filter_ = (mode != Texture::NO_FILTERING) ;

	if(height == 0) {
		height++ ;
	}
	if(depth == 0) {
		depth++ ;
	}

	int size = width * height * depth ;

	if(encode_indexed_to_rgb_ && (encoding == Image::GRAY || encoding == Image::INDEXED)) {
		if(dim == 3 && encoding == Image::GRAY) {
		} 
		else
		{
			encoding = Image::RGBA ;
			if(size <= static_buffer_size) {
				base_mem = static_buffer ;
			} else {
				dynamic_buffer = new Memory::byte[size*4] ;
				base_mem = dynamic_buffer ;
			}
			indexed_to_rgb(size, base_mem_in, Image::RGBA, base_mem) ;
		}
	}

	switch(dim) 
	{
	case 1:
		switch(encoding) 
		{
		case Image::GRAY :
		case Image::INDEXED :
			gluBuild1DMipmaps(
				GL_TEXTURE_1D, GL_RGBA, width,
				GL_COLOR_INDEX, GL_UNSIGNED_BYTE, base_mem
				) ;
			break ;
		case Image::RGB :
			gluBuild1DMipmaps(
				GL_TEXTURE_1D, GL_RGB, width, 
				GL_RGB, GL_UNSIGNED_BYTE, base_mem
				) ;
			break ;
		case Image::RGBA :
			gluBuild1DMipmaps(
				GL_TEXTURE_1D, GL_RGBA, width,
				GL_RGBA, GL_UNSIGNED_BYTE, base_mem
				) ;
			break ;
		case Image::FLOAT32 :
			{				
				Memory::pointer colormapped_texture_values = new Memory::byte[4 * width];
				float32_to_rgb(size, base_mem_in, Image::RGBA, colormapped_texture_values);

				gluBuild1DMipmaps(
					GL_TEXTURE_1D, GL_RGBA, width,
					GL_RGBA, GL_UNSIGNED_BYTE, colormapped_texture_values
					) ; 

				delete[] colormapped_texture_values;
				break ;
			}
		default: {
			bool implemented = false ;
			ogf_assert(implemented) ;
				 }
		}
		break ;
	case 2:
		switch(encoding) 
		{
		case Image::GRAY :
		case Image::INDEXED :
			if(mipmap_) {
				gluBuild2DMipmaps(
					GL_TEXTURE_2D, GL_RGBA, width, height,
					GL_COLOR_INDEX, GL_UNSIGNED_BYTE, base_mem
					) ;
			} else {
				glTexImage2D(
					GL_TEXTURE_2D, 0, GL_RGBA, width, height,
					0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, base_mem
					) ;
			}
			break ;
		case Image::RGB :
			if(mipmap_) {
				gluBuild2DMipmaps(
					GL_TEXTURE_2D, GL_RGB, width, height, 
					GL_RGB, GL_UNSIGNED_BYTE, base_mem
					) ;
			} else {
				glTexImage2D(
					GL_TEXTURE_2D, 0, GL_RGB, width, height,
					0, GL_RGB, GL_UNSIGNED_BYTE, base_mem
					) ;
			}
			break ;
		case Image::RGBA :
			if(mipmap_) {
				gluBuild2DMipmaps(
					GL_TEXTURE_2D, GL_RGBA, width, height,
					GL_RGBA, GL_UNSIGNED_BYTE, base_mem
					) ;
			} else {
				glTexImage2D(
					GL_TEXTURE_2D, 0, GL_RGBA, width, height,
					0, GL_RGBA, GL_UNSIGNED_BYTE, base_mem
					) ;
			}
			break ;
		case Image::RGB_FLOAT32: 
			glTexImage2D(
				GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGB32_NV, width, height,
				0, GL_RGB, GL_FLOAT, base_mem
				) ;
			break ;
		case Image::RGBA_FLOAT32: 
			glTexImage2D(
				GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, width, height,
				0, GL_RGBA, GL_FLOAT, base_mem
				) ;
			break ;
		case Image::FLOAT32 :
			{		
				Memory::pointer colormapped_texture_values = new Memory::byte[4 * width * height];
				float32_to_rgb(size, base_mem_in, Image::RGBA, colormapped_texture_values);

				if(mipmap_) {
					gluBuild2DMipmaps(
						GL_TEXTURE_2D, GL_RGBA, width, height,
						GL_RGBA, GL_UNSIGNED_BYTE, colormapped_texture_values
						) ; 
				} else {
					glTexImage2D(
						GL_TEXTURE_2D, 0, GL_RGBA, width, height,
						0, GL_RGBA, GL_UNSIGNED_BYTE, colormapped_texture_values 
						) ;
				}

				delete[] colormapped_texture_values;
				break ;
			}
		default: 
			{
				bool implemented = false ;
				ogf_assert(implemented) ;
			} break ;
		}
		break ;
	case 3:
		// Note: gluBuild3DMipmaps does not seem to exist under Windows	   
#ifdef WIN32
		mipmap_ = false ;
#endif
		switch(encoding) {
	case Image::GRAY : 
		if(mipmap_) {
#ifndef WIN32		   
			gluBuild3DMipmaps(
				GL_TEXTURE_3D, GL_LUMINANCE, width, height, depth,
				GL_LUMINANCE, GL_UNSIGNED_BYTE, base_mem
				) ;
#endif		   
		} else {
			glTexImage3DEXT(
				GL_TEXTURE_3D, 0, GL_LUMINANCE, width, height, depth,
				0, GL_LUMINANCE, GL_UNSIGNED_BYTE, base_mem
				) ;
		}
		break ;
	case Image::INDEXED :
		if(mipmap_) {
#ifndef WIN32
			gluBuild3DMipmaps(
				GL_TEXTURE_3D, GL_RGBA, width, height, depth,
				GL_RGB, GL_UNSIGNED_BYTE, base_mem
				) ;
#endif
		} else {
			glTexImage3DEXT(
				GL_TEXTURE_3D, 0, GL_RGB, width, height, depth,
				0, GL_RGB, GL_UNSIGNED_BYTE, base_mem
				) ;
		}
		break ;
	case Image::RGB :
		if(mipmap_) {
#ifndef WIN32
			gluBuild3DMipmaps(
				GL_TEXTURE_3D, GL_RGB, width, height, depth,
				GL_RGB, GL_UNSIGNED_BYTE, base_mem
				) ; 
#endif
		} else {
			glTexImage3DEXT(
				GL_TEXTURE_3D, 0, GL_RGB, width, height, depth,
				0, GL_RGB, GL_UNSIGNED_BYTE, base_mem
				) ;
		}
		break ;
	case Image::RGBA :
		if(mipmap_) {
#ifndef WIN32
			gluBuild3DMipmaps(
				GL_TEXTURE_3D, GL_RGBA, width, height, depth,
				GL_RGBA, GL_UNSIGNED_BYTE, base_mem
				) ; 
#endif
		} else {
			glTexImage3DEXT(
				GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth,
				0, GL_RGBA, GL_UNSIGNED_BYTE, base_mem
				) ;
		}
		break ;
	case Image::FLOAT32 :
		{				
			Memory::pointer colormapped_texture_values = new Memory::byte[4 * width * height * depth];
			float32_to_rgb(size, base_mem_in, Image::RGBA, colormapped_texture_values);

			if(mipmap_) {
#ifndef WIN32
				gluBuild3DMipmaps(
					GL_TEXTURE_3D, GL_RGBA, width, height, depth,
					GL_RGBA, GL_UNSIGNED_BYTE, colormapped_texture_values
					) ; 
#endif
			} else {
				glTexImage3DEXT(
					GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth,
					0, GL_RGBA, GL_UNSIGNED_BYTE, colormapped_texture_values 
					) ;
			}

			delete[] colormapped_texture_values;
			break ;
		}
	default: {
		bool implemented = false ;
		ogf_assert(implemented) ;
			 }
		}
		break ;
	}
	delete[] dynamic_buffer ;
}
void DriftingGratingStimulus::load(shared_ptr<StimulusDisplay> display) {
    if (loaded)
        return;
	
	for(int i = 0; i < display->getNContexts(); ++i) {
		
        
        display->setCurrent(i);
        
        GLuint textures[2];
        glGenTextures(2, textures);
        mask_textures.push_back(textures[0]);
        grating_textures.push_back(textures[1]);
        
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE0_ARB);
		glEnable(GL_TEXTURE_1D);
		
        
        
        // ----------------------------------------
        //                  GRATING
        // ----------------------------------------
        
		// select our current texture
		glBindTexture( GL_TEXTURE_1D, grating_textures[i] );
		
		// select modulate to mix texture with color for shading
		glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
		
		// when texture area is small, bilinear filter the closest mipmap
		glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
		// when texture area is large, bilinear filter the first mipmap
		glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		
		// if wrap is true, the texture wraps over at the edges (repeat)
		//       ... false, the texture ends at the edges (clamp)
		glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT );
		glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT );
		
        
		gluBuild1DMipmaps(GL_TEXTURE_1D,
						  GL_LUMINANCE,
						  grating->getDataSize(),
						  GL_LUMINANCE,
						  GL_FLOAT,
						  grating->get1DData());
		
		glEnable(GL_TEXTURE_1D);
		
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(1,1,1,1); 
        
       
        
        
        // ----------------------------------------
        //                  MASK
        // ----------------------------------------
        
		
		glActiveTextureARB(GL_TEXTURE1_ARB);
        glEnable(GL_TEXTURE_2D);
		
        
		// select our current texture
		glBindTexture( GL_TEXTURE_2D, mask_textures[i] );
		
		// select modulate to mix texture with color for shading
		glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
		
         
        
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );	
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
		
		gluBuild2DMipmaps(GL_TEXTURE_2D,
						  2,
						  mask->getSize(),
						  mask->getSize(),
						  GL_LUMINANCE_ALPHA,
						  GL_FLOAT,
						  mask->get2DData());
		
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
		glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
		glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
        
        // Unbind grating texture
        glActiveTextureARB(GL_TEXTURE0_ARB); 
        glBindTexture( GL_TEXTURE_1D, 0 );
        glBindTexture( GL_TEXTURE_2D, 0 );
        glDisable(GL_TEXTURE_1D);
        glDisable(GL_TEXTURE_2D);
        
        // Unbind mask texture
        glActiveTextureARB(GL_TEXTURE1_ARB);
        glBindTexture( GL_TEXTURE_1D, 0 );
        glBindTexture( GL_TEXTURE_2D, 0 );
        glDisable(GL_TEXTURE_1D);
        glDisable(GL_TEXTURE_2D);
        
        glActiveTextureARB(0);

	}
    
    loaded = true;
}   
void GenerateDisplayLists()
{
	// generowanie identyfikatora listy wyświetlania
	RECT_LIST = glGenLists(1);

	// lista wyświetlania - prostokąt
	glNewList(RECT_LIST, GL_COMPILE);

	// nałżenie tekstury na prostokąt
	glBegin(GL_QUADS);
	glTexCoord1f(1.0);
	glVertex2f(1.5, 0.7);
	glTexCoord1f(0.0);
	glVertex2f(-1.5, 0.7);
	glTexCoord1f(0.0);
	glVertex2f(-1.5, -0.7);
	glTexCoord1f(1.0);
	glVertex2f(1.5, -0.7);
	glEnd();

	// koniec listy wyświetlania
	glEndList();

	// sprawdzenie czy implementacja biblioteki obsługuje tekstury o wymiarze 256
	GLint size;
	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
	if (size < 512)
	{
		printf("Rozmiar tekstur mniejszy od 512");
		exit(0);
	}

	// generowanie identyfikatora listy wyświetlania
	SPECTRUM_1_LIST = glGenLists(1);

	// lista wyświetlania - pierwsza "tęcza"
	glNewList(SPECTRUM_1_LIST, GL_COMPILE);

	// definiowanie tekstury i mipmap
	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_512);
	glTexImage1D(GL_TEXTURE_1D, 1, GL_RGB, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_256);
	glTexImage1D(GL_TEXTURE_1D, 2, GL_RGB, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_128);
	glTexImage1D(GL_TEXTURE_1D, 3, GL_RGB, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_64);
	glTexImage1D(GL_TEXTURE_1D, 4, GL_RGB, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_32);
	glTexImage1D(GL_TEXTURE_1D, 5, GL_RGB, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_16);
	glTexImage1D(GL_TEXTURE_1D, 6, GL_RGB, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_8);
	glTexImage1D(GL_TEXTURE_1D, 7, GL_RGB, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_4);
	glTexImage1D(GL_TEXTURE_1D, 8, GL_RGB, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_2);
	glTexImage1D(GL_TEXTURE_1D, 9, GL_RGB, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_1);

	// odłżenie macierzy modelowania na stos
	glPushMatrix();

	// przesunięcie prostokąta do góry o dwie jednostki
	glTranslatef(0.0, 2.0, 0.0);

	// nałżenie tekstury na prostokąt
	glCallList(RECT_LIST);

	// zdjęcie macierzy modelowania ze stosu
	glPopMatrix();

	// koniec listy wyświetlania
	glEndList();

	// generowanie identyfikatora listy wyświetlania
	SPECTRUM_2_LIST = glGenLists(1);

	// lista wyświetlania - druga "tęcza"
	glNewList(SPECTRUM_2_LIST, GL_COMPILE);

	// definiowanie tekstury łącznie z mipmapami
	gluBuild1DMipmaps(GL_TEXTURE_1D, GL_RGB, 512, GL_RGB, GL_UNSIGNED_BYTE, spectrum_512);

	// nałżenie tekstury na prostokąt
	glCallList(RECT_LIST);

	// koniec listy wyświetlania
	glEndList();

	// generowanie identyfikatora listy wyświetlania
	SPECTRUM_3_LIST = glGenLists(1);

	// lista wyświetlania - trzecia "tęcza"
	glNewList(SPECTRUM_3_LIST, GL_COMPILE);

	// włączenie automatycznego generowania mipmap
	glTexParameteri(GL_TEXTURE_1D, GL_GENERATE_MIPMAP, GL_TRUE);

	// definiowanie tekstury
	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, spectrum_512);

	// wyłączenie automatycznego generowania mipmap
	glTexParameteri(GL_TEXTURE_1D, GL_GENERATE_MIPMAP, GL_FALSE);

	// odłżenie macierzy modelowania na stos
	glPushMatrix();

	// przesunięcie prostokąta do dołu o dwie jednostki
	glTranslatef(0.0, -2.0, 0.0);

	// nałżenie tekstury na prostokąt
	glCallList(RECT_LIST);

	// zdjęcie macierzy modelowania ze stosu
	glPopMatrix();

	// koniec listy wyświetlania
	glEndList();
}