Castle Game Engine: CastleGLCubeMaps

# Unit CastleGLCubeMaps
Description | Uses | Classes, Interfaces, Objects and Records | Functions and Procedures | Types | Constants | Variables
## Description OpenGL utilities for cube (environment) maps. ## Uses CastleVectors CastleCubeMaps CastleImages CastleDDS GL GLU CastleGLUtils CastleRenderingCamera CastleGLImages Castle3D ## Overview ### Functions and Procedures
`procedure SHVectorGLCapture( var SHVector: array of Single; const CapturePoint: TVector3Single; const Render: TCubeMapRenderSimpleFunction; const MapScreenX, MapScreenY: Integer; const ScaleColor: Single);`
`procedure GLCaptureCubeMapImages( const Images: TCubeMapImages; const CapturePoint: TVector3Single; const Render: TRenderFromViewFunction; const ProjectionNear, ProjectionFar: Single; const MapsOverlap: boolean; const MapScreenX, MapScreenY: Integer);`
`function GLCaptureCubeMapDDS( const Size: Cardinal; const CapturePoint: TVector3Single; const Render: TRenderFromViewFunction; const ProjectionNear, ProjectionFar: Single; const MapsOverlap: boolean; const MapScreenX, MapScreenY: Integer): TDDSImage;`
`procedure GLCaptureCubeMapTexture( const Tex: TGLuint; const Size: Cardinal; const CapturePoint: TVector3Single; const Render: TRenderFromViewFunction; const ProjectionNear, ProjectionFar: Single; RenderToTexture: TGLRenderToTexture);`
### Types
`TCubeMapRenderSimpleFunction = procedure (ForCubeMap: boolean);`
`TCubeMapImages = array [TCubeMapSide] of TCastleImage;`
## Description ### Functions and Procedures
`procedure SHVectorGLCapture( var SHVector: array of Single; const CapturePoint: TVector3Single; const Render: TCubeMapRenderSimpleFunction; const MapScreenX, MapScreenY: Integer; const ScaleColor: Single);`
Calculate spherical harmonics basis describing environment rendered by OpenGL. Environment is rendered by Render(true) callback, from the CapturePoint. It's rendered to color buffer, and captured as grayscale. Captured pixel value is just assumed to be the value of spherical function at this direction. It's also scaled by ScaleColor (since rendering to OpenGL catches values in 0..1 range, but SH vector can express values from any range). This changes glViewport, so be sure to reset glViewport to something normal after calling this. The maps will be drawn in the color buffer (from positions MapScreenX, Y), so will actually be visible (call this before glClear or such if you want to hide them).
`procedure GLCaptureCubeMapImages( const Images: TCubeMapImages; const CapturePoint: TVector3Single; const Render: TRenderFromViewFunction; const ProjectionNear, ProjectionFar: Single; const MapsOverlap: boolean; const MapScreenX, MapScreenY: Integer);`
Capture cube map by rendering environment from CapturePoint. Environment is rendered by Render callback that must honour camera described in RenderingCamera object. RenderingCamera.Target will be set to rtCubeMapEnvironment. RenderingCamera camera will be set to appropriate views from the CapturePoint. You should at least load RenderingCamera.Matrix to OpenGL modelview matrix before rendering your 3D scene. Scene is rendered to color buffer, captured as appropriate for Images classes (e.g. TGrayscaleImage, or TRGBImage). Cube map is recorded in six images provided in Images parameter. These must be already created TCastleImage instances with the exact same size. (But we do not require here the images to be square, or have power-of-two size, or honor GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB limit, as we do not initialize actual OpenGL cube map here. You can use generated images for any purpose.) This changes glViewport, so be sure to reset glViewport to something normal after calling this. ProjectionNear, ProjectionFar parameters will be used to set GL projection matrix. ProjectionFar may be equal to ZFarInfinity, as always. ###### Parameters MapsOverlap If `False` then the six maps will be drawn on non-overlapping locations in the color buffer, and will be shifted by MapScreenX, Y. This has two benefits: you can actually show the generated maps then (useful for debug purposes). And, more important, you can sometimes get away then with only one glClear before `GLCaptureCubeMapImages` (avoiding doing glClear in each Render). Otherwise (when NiceMapsLayout = `False`), then MapScreenX, Y will be ignored, and all images will be simply drawn in screen lower-left corner starting from (0, 0). The benefit is that this has the most chance of fitting into your window size.
`function GLCaptureCubeMapDDS( const Size: Cardinal; const CapturePoint: TVector3Single; const Render: TRenderFromViewFunction; const ProjectionNear, ProjectionFar: Single; const MapsOverlap: boolean; const MapScreenX, MapScreenY: Integer): TDDSImage;`
Capture cube map to DDS image by rendering environment from CapturePoint. See GLCaptureCubeMapImages for documentation, this works the same, but it creates TDDSImage instance containing all six images (oriented as appropriate for DDS).
`procedure GLCaptureCubeMapTexture( const Tex: TGLuint; const Size: Cardinal; const CapturePoint: TVector3Single; const Render: TRenderFromViewFunction; const ProjectionNear, ProjectionFar: Single; RenderToTexture: TGLRenderToTexture);`
Capture cube map to OpenGL cube map texture by rendering environment from CapturePoint. See GLCaptureCubeMapImages for documentation, this works the same, but it captures images to given OpenGL texture name Tex. Tex must already be created cube map texture (with OpenGL size and internal formats set), with square images of Size. This also means that Size must be a valid OpenGL cube map texture size, you can check it by GLImages.IsCubeMapTextureSized. This captures the cube map images to "zero" texture level. If you use mipmaps, it's your problem how to generate other texture levels — in the simplest case, call GenerateMipmap(GL_TEXTURE_CUBE_MAP). It uses RenderToTexture to render to the texture, so it will use framebuffer if available, and it's fast.
### Types
`TCubeMapRenderSimpleFunction = procedure (ForCubeMap: boolean);`
`TCubeMapImages = array [TCubeMapSide] of TCastleImage;`
Generated by PasDoc 0.13.0 on 2013-08-17 21:27:12