Esempio n. 1
0
/* Context activation is done by the caller. */
void wined3d_volume_upload_data(struct wined3d_volume *volume, const struct wined3d_context *context,
        const struct wined3d_bo_address *data)
{
    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, format %s (%#x).\n",
            volume, context, volume->texture_level, debug_d3dformat(format->id),
            format->id);


    if (data->buffer_object)
    {
        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, data->buffer_object));
        checkGLcall("glBindBufferARB");
    }

    GL_EXTCALL(glTexSubImage3DEXT(GL_TEXTURE_3D, volume->texture_level, 0, 0, 0,
            volume->resource.width, volume->resource.height, volume->resource.depth,
            format->glFormat, format->glType, data->addr));
    checkGLcall("glTexSubImage3D");

    if (data->buffer_object)
    {
        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
        checkGLcall("glBindBufferARB");
    }
}
void SingleChannelRaycaster::bindShader(const Raycaster::PTransform& pmv,const Raycaster::PTransform& mv,Raycaster::DataItem* dataItem) const
	{
	/* Call the base class method: */
	Raycaster::bindShader(pmv,mv,dataItem);
	
	/* Get a pointer to the data item: */
	DataItem* myDataItem=dynamic_cast<DataItem*>(dataItem);
	
	/* Bind the volume texture: */
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glBindTexture(GL_TEXTURE_3D,myDataItem->volumeTextureID);
	glUniform1iARB(myDataItem->volumeSamplerLoc,1);
	
	/* Check if the volume texture needs to be updated: */
	if(myDataItem->volumeTextureVersion!=dataVersion)
		{
		/* Upload the new volume data: */
		glTexSubImage3DEXT(GL_TEXTURE_3D,0,0,0,0,dataSize[0],dataSize[1],dataSize[2],GL_LUMINANCE,GL_UNSIGNED_BYTE,data);
		
		/* Mark the volume texture as up-to-date: */
		myDataItem->volumeTextureVersion=dataVersion;
		}
	
	/* Bind the color map texture: */
	glActiveTextureARB(GL_TEXTURE2_ARB);
	glBindTexture(GL_TEXTURE_1D,myDataItem->colorMapTextureID);
	glUniform1iARB(myDataItem->colorMapSamplerLoc,2);
	
	/* Create the stepsize-adjusted colormap with pre-multiplied alpha: */
	GLColorMap adjustedColorMap(*colorMap);
	adjustedColorMap.changeTransparency(stepSize*transparencyGamma);
	adjustedColorMap.premultiplyAlpha();
	glTexImage1D(GL_TEXTURE_1D,0,myDataItem->haveFloatTextures?GL_RGBA32F_ARB:GL_RGBA,256,0,GL_RGBA,GL_FLOAT,adjustedColorMap.getColors());
	}
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
		}
	}
Esempio n. 4
0
/* Context activation is done by the caller. */
void wined3d_volume_upload_data(struct wined3d_volume *volume, const struct wined3d_context *context,
        const struct wined3d_bo_address *data)
{
    const struct wined3d_gl_info *gl_info = context->gl_info;
    const struct wined3d_format *format = volume->resource.format;
    UINT width = volume->resource.width;
    UINT height = volume->resource.height;
    UINT depth = volume->resource.depth;
    BYTE *mem = data->addr;

    TRACE("volume %p, context %p, level %u, format %s (%#x).\n",
            volume, context, volume->texture_level, debug_d3dformat(format->id),
            format->id);

    if (format->convert)
    {
        UINT dst_row_pitch, dst_slice_pitch;
        UINT src_row_pitch, src_slice_pitch;
        UINT alignment = volume->resource.device->surface_alignment;

        if (data->buffer_object)
            ERR("Loading a converted volume from a PBO.\n");
        if (format->flags & WINED3DFMT_FLAG_BLOCKS)
            ERR("Converting a block-based format.\n");

        dst_row_pitch = width * format->conv_byte_count;
        dst_row_pitch = (dst_row_pitch + alignment - 1) & ~(alignment - 1);
        dst_slice_pitch = dst_row_pitch * height;

        wined3d_volume_get_pitch(volume, &src_row_pitch, &src_slice_pitch);

        mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch * depth);
        format->convert(data->addr, mem, src_row_pitch, src_slice_pitch,
                dst_row_pitch, dst_slice_pitch, width, height, depth);
    }

    if (data->buffer_object)
    {
        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, data->buffer_object));
        checkGLcall("glBindBufferARB");
    }

    GL_EXTCALL(glTexSubImage3DEXT(GL_TEXTURE_3D, volume->texture_level, 0, 0, 0,
            width, height, depth,
            format->glFormat, format->glType, mem));
    checkGLcall("glTexSubImage3D");

    if (data->buffer_object)
    {
        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
        checkGLcall("glBindBufferARB");
    }

    if (mem != data->addr)
        HeapFree(GetProcessHeap(), 0, mem);
}
void OpenGLTexture::updateHardwareTextureArea(
    const dim::vector3di &Pos, const dim::vector3di &Size, const void* ImageBuffer, s32 Level)
{
    switch (Type_)
    {
        case TEXTURE_1D:
        {
            glTexSubImage1D(
                GL_TEXTURE_1D, Level, Pos.X, Size.X, GLFormat_, GLType_, ImageBuffer
            );
        }
        break;
        
        case TEXTURE_1D_ARRAY:
        case TEXTURE_2D:
        case TEXTURE_RECTANGLE:
        {
            glTexSubImage2D(
                GLDimension_, Level, Pos.X, Pos.Y, Size.X, Size.Y, GLFormat_, GLType_, ImageBuffer
            );
        }
        break;
        
        case TEXTURE_2D_ARRAY:
        case TEXTURE_CUBEMAP_ARRAY:
        case TEXTURE_3D:
        {
            glTexSubImage3DEXT(
                GLDimension_, Level, Pos.X, Pos.Y, Pos.Z, Size.X, Size.Y, Size.Z, GLFormat_, GLType_, ImageBuffer
            );
        }
        break;
        
        case TEXTURE_CUBEMAP:
        {
            for (s32 i = 0; i < 6; ++i)
            {
                glTexSubImage2D(
                    GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, Level,
                    Pos.X, Pos.Y, Size.X, Size.Y, GLFormat_, GLType_, ImageBuffer
                );
            }
        }
        break;
        
        case TEXTURE_BUFFER:
            // ignore that here
            break;
        
        default:
            io::Log::error("Unsupported texture dimension type for the OpenGL render system");
            break;
    }
}