/* Context activation is done by the caller. */ static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, int gl_level, BOOL srgb_mode) { IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface; const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info; const struct wined3d_format *format = This->resource.format; TRACE("iface %p, level %u, srgb %#x, format %s (%#x).\n", iface, gl_level, srgb_mode, debug_d3dformat(format->id), format->id); volume_bind_and_dirtify(iface); TRACE("Calling glTexImage3D %x level=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n", GL_TEXTURE_3D, gl_level, format->glInternal, This->currentDesc.Width, This->currentDesc.Height, This->currentDesc.Depth, 0, format->glFormat, format->glType, This->resource.allocatedMemory); ENTER_GL(); GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, gl_level, format->glInternal, This->currentDesc.Width, This->currentDesc.Height, This->currentDesc.Depth, 0, format->glFormat, format->glType, This->resource.allocatedMemory)); checkGLcall("glTexImage3D"); LEAVE_GL(); /* When adding code releasing This->resource.allocatedMemory to save data keep in mind that * GL_UNPACK_CLIENT_STORAGE_APPLE is enabled by default if supported(GL_APPLE_client_storage). * Thus do not release This->resource.allocatedMemory if GL_APPLE_client_storage is supported. */ return WINED3D_OK; }
void load3DTexture(void) { printf("setting up 3d textures...\n"); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); #ifdef GL_EXT_texture3D glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R_EXT, GL_REPEAT); glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_LUMINANCE8_ALPHA8_EXT, vol_width, vol_height, vol_depth, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, voxels); #endif if (tex3dSupported) { /* enable texturing, blending etc */ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } setMatrix(); }
void TripleChannelRaycaster::initDataItem(Raycaster::DataItem* dataItem) const { /* Call the base class method: */ Raycaster::initDataItem(dataItem); /* Get a pointer to the data item: */ DataItem* myDataItem=dynamic_cast<DataItem*>(dataItem); /* Create the data volume texture: */ glBindTexture(GL_TEXTURE_3D,myDataItem->volumeTextureID); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_R,GL_CLAMP); glTexImage3DEXT(GL_TEXTURE_3D,0,GL_RGB8,myDataItem->textureSize[0],myDataItem->textureSize[1],myDataItem->textureSize[2],0,GL_RGB,GL_UNSIGNED_BYTE,0); glBindTexture(GL_TEXTURE_3D,0); /* Create the color map textures: */ for(int channel=0;channel<3;++channel) { glBindTexture(GL_TEXTURE_1D,myDataItem->colorMapTextureIDs[channel]); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); } glBindTexture(GL_TEXTURE_1D,0); }
/* Context activation is done by the caller. */ static void wined3d_volume_allocate_texture(struct wined3d_volume *volume, const struct wined3d_context *context, BOOL srgb) { const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_format *format = volume->resource.format; void *mem = NULL; if (gl_info->supported[APPLE_CLIENT_STORAGE] && !format->convert && volume_prepare_system_memory(volume)) { TRACE("Enabling GL_UNPACK_CLIENT_STORAGE_APPLE for volume %p\n", volume); gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)"); mem = volume->resource.heap_memory; volume->flags |= WINED3D_VFLAG_CLIENT_STORAGE; } GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, volume->texture_level, srgb ? format->glGammaInternal : format->glInternal, volume->resource.width, volume->resource.height, volume->resource.depth, 0, format->glFormat, format->glType, mem)); checkGLcall("glTexImage3D"); if (mem) { gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)"); } }
static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, GLenum gl_level) { IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface; const PixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format); if(GL_SUPPORT(EXT_TEXTURE3D)) { TRACE("Calling glTexImage3D %x level=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n", GL_TEXTURE_3D, gl_level, formatEntry->glInternal, This->currentDesc.Width, This->currentDesc.Height, This->currentDesc.Depth, 0, formatEntry->glFormat, formatEntry->glType, This->resource.allocatedMemory); GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, gl_level, formatEntry->glInternal, This->currentDesc.Width, This->currentDesc.Height, This->currentDesc.Depth, 0, formatEntry->glFormat, formatEntry->glType, This->resource.allocatedMemory)); checkGLcall("glTexImage3D"); } else WARN("This OpenGL implementation doesn't support 3D textures\n"); return WINED3D_OK; }
void Texture2dArray::upload( int xres, int yres, int zres, int format, int component, void *data ) { m_xres = xres; m_yres = yres; m_zres = zres; glBindTexture(GL_TEXTURE_2D_ARRAY, m_id); glTexImage3DEXT(GL_TEXTURE_2D_ARRAY, 0, m_textureFormat, m_xres, m_yres, m_zres, 0, format, component, data); }
void Texture2dArray::uploadFloat32( int xres, int yres, int zres, float *pixels ) { m_xres = xres; m_yres = yres; m_zres = zres; glBindTexture(GL_TEXTURE_2D_ARRAY, m_id); glTexImage3DEXT(GL_TEXTURE_2D_ARRAY, 0, m_textureFormat, m_xres, m_yres, m_zres, 0, GL_ALPHA, GL_FLOAT, pixels); }
void Texture3d::uploadRGBAFloat32( int xres, int yres, int zres, float *pixels ) { m_xres = xres; m_yres = yres; m_zres = zres; glBindTexture(GL_TEXTURE_3D, m_id); glTexImage3DEXT(GL_TEXTURE_3D, 0, m_textureFormat, m_xres, m_yres, m_zres, 0, GL_RGBA, GL_FLOAT, pixels); }
void Texture2dArray::uploadRGBA8( int xres, int yres, int zres, unsigned char *pixels ) { m_xres = xres; m_yres = yres; m_zres = zres; glBindTexture(GL_TEXTURE_2D_ARRAY, m_id); glTexImage3DEXT(GL_TEXTURE_2D_ARRAY, 0, m_textureFormat, m_xres, m_yres, m_zres, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); }
void PaletteRenderer::uploadTexture3D(VolumeRenderer::DataItem* dataItem) const { /* Get pointer to our own data item: */ DataItem* myDataItem=static_cast<DataItem*>(dataItem); if(myDataItem->setParameters) { /* Set the OpenGL texturing parameters: */ glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_BASE_LEVEL,0); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAX_LEVEL,0); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_R,GL_CLAMP); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAG_FILTER,interpolationMode); glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MIN_FILTER,interpolationMode); } /* Upload a color map only if necessary: */ if(myDataItem->renderingPath==PalettedTexture&&myDataItem->uploadColorMap) { /* Set the texture's color map: */ #ifdef __SGI_IRIX__ glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #else glColorTableEXT(GL_TEXTURE_3D,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors()); #endif } if(myDataItem->uploadData) { /* Determine the texture's format: */ GLenum internalFormat=GL_INTENSITY8; GLenum uploadFormat=GL_LUMINANCE; #ifndef __SGI_IRIX__ if(myDataItem->renderingPath==PalettedTexture) { internalFormat=GL_COLOR_INDEX8_EXT; uploadFormat=GL_COLOR_INDEX; } #endif /* Upload the texture block: */ glPixelStorei(GL_UNPACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_SKIP_PIXELS,0); glPixelStorei(GL_UNPACK_ROW_LENGTH,0); // increments[1]); // Seems to be a bug in OpenGL - consistent across SGI/nVidia platforms glPixelStorei(GL_UNPACK_SKIP_ROWS,0); glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,0); // increments[0]); glPixelStorei(GL_UNPACK_SKIP_IMAGES,0); #ifdef __SGI_IRIX__ glTexImage3D(GL_TEXTURE_3D,0,internalFormat,textureSize[2],textureSize[1],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,values); #else glTexImage3DEXT(GL_TEXTURE_3D,0,internalFormat,textureSize[2],textureSize[1],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,0); glTexSubImage3DEXT(GL_TEXTURE_3D,0,0,0,0,size[2],size[1],size[0],uploadFormat,GL_UNSIGNED_BYTE,values); #endif } }
/* Context activation is done by the caller. */ static void wined3d_volume_allocate_texture(const struct wined3d_volume *volume, const struct wined3d_context *context, BOOL srgb) { const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_format *format = volume->resource.format; GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, volume->texture_level, srgb ? format->glGammaInternal : format->glInternal, volume->resource.width, volume->resource.height, volume->resource.depth, 0, format->glFormat, format->glType, NULL)); checkGLcall("glTexImage3D"); }
/* COUNT = 38 */ void crPackTestTexImage3DEXT(void) { int i; GLubyte pixels[100000];/* VECP2 */ for ( i = 0; i < 38; i++) { if (verbose) crDebug("glTexImage3DEXT( %s )",TexImage3DEXT_tab[i].prgstr); glTexImage3DEXT( TexImage3DEXT_tab[i].TexImage3DEXT_target, TexImage3DEXT_tab[i].TexImage3DEXT_level, TexImage3DEXT_tab[i].TexImage3DEXT_internalFormat, TexImage3DEXT_tab[i].TexImage3DEXT_width, TexImage3DEXT_tab[i].TexImage3DEXT_height, TexImage3DEXT_tab[i].TexImage3DEXT_depth, TexImage3DEXT_tab[i].TexImage3DEXT_border, TexImage3DEXT_tab[i].TexImage3DEXT_format, TexImage3DEXT_tab[i].TexImage3DEXT_type, pixels /* VECS2 */ ); if(errChk) printError("gl(TexImage3DEXT)"); } }
GLuint init3DNoiseTexture(){ std::cout << "Criando tetxura 3D" << std::endl; make3DNoiseTexture(); glGenTextures(1, &noise3DTexName); glBindTexture(GL_TEXTURE_3D, noise3DTexName); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage3DEXT(GL_TEXTURE_3D, 0, GL_RGBA, noise3DTexSize, noise3DTexSize, noise3DTexSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, noise3DTexPtr); return noise3DTexName; }
//load 1 byte volume void vRenderer::loadTexture3D(unsigned char *tex, int sx, int sy, int sz) { glEnable(GL_TEXTURE_3D); glBindTexture(GL_TEXTURE_3D, myVolume->texName); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); #ifdef _WIN32 glTexImage3DEXT(GL_TEXTURE_3D, 0, GL_ALPHA8, sx, sy, sz, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex); #else glTexImage3D(GL_TEXTURE_3D, 0, GL_ALPHA8, sx, sy, sz, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tex); #endif GlErr("vRenderer", "loadTexture3D"); glDisable(GL_TEXTURE_3D); }
/* Context activation is done by the caller. */ void volume_load(const struct wined3d_volume *volume, struct wined3d_context *context, UINT level, BOOL srgb_mode) { const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_format *format = volume->resource.format; TRACE("volume %p, context %p, level %u, srgb %#x, format %s (%#x).\n", volume, context, level, srgb_mode, debug_d3dformat(format->id), format->id); volume_bind_and_dirtify(volume, context); GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, level, format->glInternal, volume->resource.width, volume->resource.height, volume->resource.depth, 0, format->glFormat, format->glType, volume->resource.allocatedMemory)); checkGLcall("glTexImage3D"); /* When adding code releasing volume->resource.allocatedMemory to save * data keep in mind that GL_UNPACK_CLIENT_STORAGE_APPLE is enabled by * default if supported(GL_APPLE_client_storage). Thus do not release * volume->resource.allocatedMemory if GL_APPLE_client_storage is * supported. */ }
/* use pixel path to remap 3D texture data */ void remaptex(void) { int i, size; GLfloat *map; glPixelTransferi(GL_MAP_COLOR, GL_TRUE); glGetIntegerv(GL_MAX_PIXEL_MAP_TABLE, &size); map = (GLfloat *)malloc(sizeof(GLfloat) * size); for(i = 0; i < size;i++) { map[i] = (GLfloat)i/(size - 1); if(((GLfloat)i/size > minboost) && ((GLfloat)i/size < minboost + boostwid)) { map[i] *= boost; } else map[i] /= boost; } glPixelMapfv(GL_PIXEL_MAP_R_TO_R, size, map); glPixelMapfv(GL_PIXEL_MAP_G_TO_G, size, map); glPixelMapfv(GL_PIXEL_MAP_B_TO_B, size, map); glPixelMapfv(GL_PIXEL_MAP_A_TO_A, size, map); #ifdef GL_EXT_texture3D glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_LUMINANCE_ALPHA, texwid, texht, texdepth, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex3ddata); #endif glPixelTransferi(GL_MAP_COLOR, GL_FALSE); free(map); CHECK_ERROR("OpenGL Error in remaptex()"); }
void OpenGLTexture::updateHardwareTexture( dim::vector3di Size, const u32 PixelSize, const void* ImageBuffer, s32 Level) { if (Type_ != TEXTURE_BUFFER) TBO_.detachBuffer(); switch (Type_) { case TEXTURE_1D: case TEXTURE_1D_RW: { /* Create 1D texture image */ glTexImage1D( GL_TEXTURE_1D, Level, GLInternalFormat_, Size.X, 0, GLFormat_, GLType_, ImageBuffer ); } break; case TEXTURE_1D_ARRAY: case TEXTURE_2D: case TEXTURE_RECTANGLE: case TEXTURE_2D_RW: case TEXTURE_1D_ARRAY_RW: { /* Create 2D texture image */ glTexImage2D( GLDimension_, Level, GLInternalFormat_, Size.X, Size.Y, 0, GLFormat_, GLType_, ImageBuffer ); } break; case TEXTURE_2D_ARRAY: case TEXTURE_CUBEMAP_ARRAY: case TEXTURE_3D: case TEXTURE_3D_RW: case TEXTURE_2D_ARRAY_RW: { /* Create 3D texture image */ glTexImage3DEXT( GLDimension_, Level, GLInternalFormat_, Size.X, Size.Y, Size.Z, 0, GLFormat_, GLType_, ImageBuffer ); } break; case TEXTURE_CUBEMAP: { /* Get buffer offsets */ const u32 OffsetSize = Size.X*Size.Y*PixelSize; const s8* Buffer = static_cast<const s8*>(ImageBuffer); for (s32 i = 0; i < 6; ++i) { /* Create 2D texture image for current cube-map face */ glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, Level, GLInternalFormat_, Size.X, Size.Y, 0, GLFormat_, GLType_, Buffer ); if (Buffer) Buffer += OffsetSize; } } break; case TEXTURE_BUFFER: { /* Attach texture buffer to TBO */ TBO_.attachBuffer( ImageBuffer, Size.X*Size.Y*Size.Z*PixelSize, getFormat(), getHardwareFormat() ); } break; default: io::Log::error("Unsupported texture dimension type for the OpenGL render system"); break; } /* Bind image texture for R/W access */ if (hasRWAccess()) { const GLenum GL3TexFormat = OpenGLRenderSystem::getGL3TexFormat(getHardwareFormat(), getFormat()); if (GL3TexFormat) { glBindImageTexture( 0, getTexID(), 0, GL_FALSE, 0, GL_WRITE_ONLY/*GL_READ_WRITE*/, GL3TexFormat ); } else io::Log::error("Unsupported GL3 texture format for R/W texture"); } }
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 ; }
main(int argc, char *argv[]) { int texcomps; static GLfloat splane[4] = {1.f/200.f, 0.f, 0.f, .5f}; static GLfloat rplane[4] = {0, 1.f/200.f, 0, .5f}; static GLfloat tplane[4] = {0, 0, 1.f/200.f, .5f}; static GLfloat lightpos[4] = {150., 150., 150., 1.f}; glutInit(&argc, argv); glutInitWindowSize(winWidth, winHeight); if(argc > 1) { char *args = argv[1]; GLboolean done = GL_FALSE; while(!done) { switch(*args) { case 's': /* single buffer */ printf("Single Buffered\n"); dblbuf = GL_FALSE; break; case '-': /* do nothing */ break; case 0: done = GL_TRUE; break; } args++; } } if(dblbuf) glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); else glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH); (void)glutCreateWindow("volume rendering demo"); glutDisplayFunc(redraw); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(motion); glutKeyboardFunc(key); /* Initialize OpenGL State */ /* draw a perspective scene */ #if 0 glMatrixMode(GL_PROJECTION); /* cube, 300 on a side */ glFrustum(-150., 150., -150., 150., 300., 600.); glMatrixMode(GL_MODELVIEW); /* look at scene from (0, 0, 450) */ gluLookAt(0., 0., 450., 0., 0., 0., 0., 1., 0.); #else glMatrixMode(GL_PROJECTION); /* cube, 300 on a side */ glOrtho(-150., 150., -150., 150., -150., 150.); glMatrixMode(GL_MODELVIEW); #endif glEnable(GL_DEPTH_TEST); #ifdef GL_EXT_texture3D glEnable(GL_TEXTURE_3D_EXT); #endif glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, splane); glTexGenfv(GL_T, GL_OBJECT_PLANE, tplane); glTexGenfv(GL_R, GL_OBJECT_PLANE, rplane); #ifdef GL_EXT_texture3D /* to avoid boundary problems */ glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R_EXT, GL_CLAMP); #endif glEnable(GL_CLIP_PLANE0); glEnable(GL_CLIP_PLANE1); glEnable(GL_CLIP_PLANE2); glEnable(GL_CLIP_PLANE3); glEnable(GL_CLIP_PLANE4); glEnable(GL_CLIP_PLANE5); glDisable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, lightpos); tex3ddata = loadtex3d(&texwid, &texht, &texdepth, &texcomps); slices = texht; #ifdef GL_EXT_texture3D glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_LUMINANCE_ALPHA, texwid, texht, texdepth, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex3ddata); #endif /* make a display list containing a sphere */ glNewList(SPHERE, GL_COMPILE); { static GLfloat lightpos[] = {150.f, 150.f, 150.f, 1.f}; static GLfloat material[] = {1.f, .5f, 1.f, 1.f}; GLUquadricObj *qobj = gluNewQuadric(); glPushAttrib(GL_LIGHTING_BIT); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, lightpos); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material); gluSphere(qobj, 20.f, 20, 20); gluDeleteQuadric(qobj); glPopAttrib(); } glEndList(); key('?', 0, 0); /* print usage message */ CHECK_ERROR("end of main"); if(!glutExtensionSupported("GL_EXT_texture3d")) { fprintf(stderr, "volume: requires OpenGL texture 3D extension to operate correctly.\n"); } hasBlendColor = glutExtensionSupported("GL_EXT_blend_color"); if(!hasBlendColor) { fprintf(stderr, "volume: needs OpenGL blend color extension to attenuate.\n"); } glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
//====================================================== load Ptex //================================================================ void TFWidgetRen::loadPtex() { if(gluvv.tf.numelts == 4){ glEnable(GL_TEXTURE_3D_EXT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_3D_EXT, gluvv.tf.ptextex); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage3DEXT(GL_TEXTURE_3D_EXT, //target 0, //mip level GL_RGBA, //internal format gluvv.tf.ptexsz[0], //width gluvv.tf.ptexsz[1], //height gluvv.tf.ptexsz[2], //depth 0, //border, never works GL_RGBA, //format GL_UNSIGNED_BYTE, //type gluvv.tf.ptex); //data TFWidgetRenGlErr("loading ptextex"); glDisable(GL_TEXTURE_3D_EXT); glEnable(GL_TEXTURE_3D_EXT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //NOTE::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // I dont think this is nessesary, but just to be sure.... // if it gets removed the parameters have to be set somewhere else // actualy, now I think that it IS important on the Octane2 platform glEnable(GL_PIXEL_TEXTURE_SGIS); glPixelTexGenParameteriSGIS(GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS, GL_PIXEL_GROUP_COLOR_SGIS); glPixelTexGenParameteriSGIS(GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS, GL_PIXEL_GROUP_COLOR_SGIS); // I dont think this has any effect either, try it with out binding glBindTexture(GL_TEXTURE_3D_EXT, gluvv.tf.ptexname); TFWidgetRenGlErr("GL_PIXEL_TEXTURE_SGIS"); //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R, GL_CLAMP); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage3DEXT(GL_TEXTURE_3D_EXT, //target 0, //mip level GL_RGBA, //internal format gluvv.tf.ptexsz[0], //width gluvv.tf.ptexsz[1], //height gluvv.tf.ptexsz[2], //depth 0, //border, never works GL_RGBA, //format GL_UNSIGNED_BYTE, //type gluvv.tf.ptex); //data glDisable(GL_PIXEL_TEXTURE_SGIS); glDisable(GL_TEXTURE_3D_EXT); TFWidgetRenGlErr("GL_PIXEL_TEXTURE_SGIS-post load"); if(!gluvv.tf.qnptexname) glGenTextures(1, &gluvv.tf.qnptexname); //quantized normals pixel texture } }