blob: e503ab879e8601fccf618a7d7c6cabc386977cc9 [file] [log] [blame]
/*
* Copyright 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace o3d {
%[
The Texture class is a base class for image data used in texture mapping.
%]
[include="core/cross/texture_base.h"] class Texture : ParamObject {
%[
\var Format,
\li UNKNOWN_FORMAT
\li XRGB8
\li ARGB8
\li ABGR16F
\li R32F
\li ABGR32F
\li DXT1
\li DXT3
\li DXT5
The in-memory format of the texture bitmap.
NOTE: The R32F format is different on GL vs D3D. If you use it in a shader
you must only use the red channel. The green, blue and alpha channels are
undefined.
For example:
\code
...
// The texture sampler is used to access the texture bitmap in the fragment
// shader.
sampler texSampler0;
...
// input parameters for our vertex shader
struct PixelShaderInput {
float4 position : POSITION;
float2 texcoord : TEXCOORD0; // Texture coordinates
};
float4 pixelShaderFunction(PixelShaderInput input): COLOR {
// ** Use only valid channels. ** ---------+
// |
// V
return tex2D(texSampler0, input.texcoord).rrrr;
}
\endcode
@o3dparameter levels ParamInteger The number of mip levels in this texture.
[Read Only]
%]
enum Format {
UNKNOWN_FORMAT,
XRGB8,
ARGB8,
ABGR16F,
R32F,
ABGR32F,
DXT1,
DXT3,
DXT5
};
%[
The memory format used for storing the bitmap associated with the texture
object.
%]
[getter] Format format;
%[
The number of mipmap levels used by the texture.
%]
[getter] int levels;
%[
True of all the alpha values in the texture are 1.0
%]
[getter, getter, setter] bool alpha_is_one;
%[
Generates Mips.
\param source_level the mip to use as the source.
\param num_levels the number of mips from the source to generate.
%]
void GenerateMips(int source_level, int num_levels);
}; // Texture
%[
A class for 2D textures that defines the interface for getting
the dimensions of the texture, its memory format and number of mipmap levels.
@o3dparameter width ParamInteger The width of this texture in pixels.
[Read Only]
@o3dparameter height ParamInteger The height of this texture in pixels.
[Read Only]
%]
[include="core/cross/texture.h"] class Texture2D : Texture {
%[
The width of the texture, in texels.
%]
[getter] int width;
%[
The height of the texture, in texels.
%]
[getter] int height;
%[
Returns a RenderSurface object associated with a mip_level of a texture.
\param mip_level The mip-level of the surface to be returned.
\return The RenderSurface object.
%]
RenderSurface? GetRenderSurface(int mip_level);
%[
Returns a RenderSurface object associated with a mip_level of a texture.
\param mip_level The mip-level of the surface to be returned.
\param pack This parameter is no longer used. The surface exists as long as
the texture it came from exists.
\return The RenderSurface object.
%]
[userglue] RenderSurface? GetRenderSurface(int mip_level, Pack pack);
// TODO: Add Get, GetRect.
%[
Sets the values of the data stored in the texture.
It is not recommend that you call this for large textures but it is useful
for making simple ramps or noise textures for shaders.
NOTE: the number of values must equal the size of the texture * the number
of elements. In other words, for a XRGB8 texture there must be
width * height * 3 values. For an ARGB8, ABGR16F or ABGR32F texture there
must be width * height * 4 values. For an R32F texture there must be
width * height values.
NOTE: the order of channels is R G B for XRGB8 textures and R G B A
for ARGB8, ABGR16F and ABGR32F textures so for example for XRGB8 textures\n
\n
[1, 0, 0] = a red pixel\n
[0, 0, 1] = a blue pixel\n
\n
For ARGB8, ABGR16F, ABGR32F textures\n
\n
[1, 0, 0, 0] = a red pixel with zero alpha\n
[1, 0, 0, 1] = a red pixel with one alpha\n
[0, 0, 1, 1] = a blue pixel with one alpha\n
\param level the mip level to update.
\param values Values to be stored in the buffer.
%]
[nocpp, userglue]
void Set(int level, float[] values);
%[
Sets a rectangular area of values in a texture.
Does clipping. In other words if you pass in a 10x10 pixel array
and give it destination of (-5, -5) it will only use the bottom 5x5
pixels of the array you passed in to set the top 5x5 pixels of the
texture.
See o3d.Texture2D.set for details on formats.
\param level the mip level to update.
\param destination_x The x coordinate of the area in the texture to affect.
\param destination_y The y coordinate of the area in the texture to affect.
\param source_width The width of the area to effect. The height is
determined by the size of the array passed in.
\param values Values to be stored in the buffer.
\see o3d.Texture2D.set
%]
[nocpp, userglue]
void SetRect(int level,
int destination_x,
int destination_y,
int source_width,
float[] values);
%[
Gets a rectangular area of values from a texture.
See o3d.Texture2D.set for details on formats.
Can not be used for compressed textures.
\param level the mip level to get.
\param x The x coordinate of the area in the texture to retrieve.
\param y The y coordinate of the area in the texture to retrieve.
\param width The width of the area to retrieve.
\param height The height of the area to retrieve.
\return Array of pixel values.
%]
[nocpp, userglue]
float[] GetRect(int level,
int x,
int y,
int width,
int height);
%[
Sets the content of the texture to the content of the bitmap. The texture
and the bitmap must be the same dimensions and the same format.
\param bitmap The bitmap to copy data from.
%]
[userglue]
void SetFromBitmap(Bitmap bitmap);
[verbatim=cpp_glue] %{
void userglue_method_SetFromBitmap(o3d::Texture2D* self,
o3d::Bitmap* bitmap) {
self->SetFromBitmap(*bitmap);
}
o3d::RenderSurface* userglue_method_GetRenderSurface(o3d::Texture2D* self,
int mip_level,
o3d::Pack* pack) {
return self->GetRenderSurface(mip_level);
}
%}
%[
Copy pixels from source bitmap to certain mip level.
Scales if the width and height of source and dest do not match.
\param source_img The source bitmap.
\param source_mip which mip from the source to copy from.
\param source_x x-coordinate of the starting pixel in the source image.
\param source_y y-coordinate of the starting pixel in the source image.
\param source_width width of the source image to draw.
\param source_height Height of the source image to draw.
\param dest_mip on which mip level to draw to.
\param dest_x x-coordinate of the starting pixel in the destination texture.
\param dest_y y-coordinate of the starting pixel in the destination texture.
\param dest_width width of the dest image.
\param dest_height height of the dest image.
%]
[userglue]
void DrawImage(Bitmap source_img, int source_mip,
int source_x, int source_y,
int source_width, int source_height,
int dest_mip,
int dest_x, int dest_y,
int dest_width, int dest_height);
%[
Copy pixels from source canvas to certain mip level.
Scales if the width and height of source and dest do not match.
\param source_img The source canvas.
\param source_x x-coordinate of the starting pixel in the source image.
\param source_y y-coordinate of the starting pixel in the source image.
\param source_width width of the source image to draw.
\param source_height Height of the source image to draw.
\param dest_mip on which mip level to draw to.
\param dest_x x-coordinate of the starting pixel in the destination texture.
\param dest_y y-coordinate of the starting pixel in the destination texture.
\param dest_width width of the dest image.
\param dest_height height of the dest image.
%]
[userglue, include="core/cross/canvas.h"]
void DrawImage(Canvas source_img,
int source_x, int source_y,
int source_width, int source_height,
int dest_mip,
int dest_x, int dest_y,
int dest_width, int dest_height);
[verbatim=cpp_glue] %{
void userglue_method_DrawImage(
o3d::Texture2D* self,
o3d::Bitmap* source_img, int source_mip, int source_x, int source_y,
int source_width, int source_height,
int dest_mip,
int dest_x, int dest_y,
int dest_width, int dest_height) {
self->DrawImage(*source_img, source_mip, source_x, source_y,
source_width, source_height,
dest_mip, dest_x, dest_y,
dest_width, dest_height);
}
void userglue_method_DrawImage(
o3d::Texture2D* self,
o3d::Canvas* source_img, int source_x, int source_y,
int source_width, int source_height,
int dest_mip,
int dest_x, int dest_y,
int dest_width, int dest_height) {
self->DrawImage(*source_img, source_x, source_y,
source_width, source_height,
dest_mip, dest_x, dest_y,
dest_width, dest_height);
}
%}
}; // Texture2D
%[
TextureCUBE is a class for textures used for cube mapping. A cube texture
stores bitmaps for the 6 faces of a cube and is addressed via three texture
coordinates.
@o3dparameter edgeLength ParamInteger The length of any edge of this texture.
[Read Only]
%]
[include="core/cross/texture.h"] class TextureCUBE : Texture {
%[
\var CubeFace,
\li FACE_POSITIVE_X
\li FACE_NEGATIVE_X
\li FACE_POSITIVE_Y
\li FACE_NEGATIVE_Y
\li FACE_POSITIVE_Z
\li FACE_NEGATIVE_Z
The names of each of the six faces of a cube map texture.
%]
enum CubeFace {
FACE_POSITIVE_X,
FACE_NEGATIVE_X,
FACE_POSITIVE_Y,
FACE_NEGATIVE_Y,
FACE_POSITIVE_Z,
FACE_NEGATIVE_Z };
%[
The length of each edge of the cube, in texels.
%]
[field_access=private, getter] int edge_length;
%[
Returns a RenderSurface object associated with a given cube face and
mip_level of a texture.
\param face The cube face from which to extract the surface.
\param mip_level The mip-level of the surface to be returned.
\return The RenderSurface object.
%]
RenderSurface? GetRenderSurface(CubeFace face, int mip_level);
%[
Returns a RenderSurface object associated with a given cube face and
mip_level of a texture.
\param face The cube face from which to extract the surface.
\param mip_level The mip-level of the surface to be returned.
\param pack This parameter is no longer used. The surface exists as long as
the texture it came from exists.
\return The RenderSurface object.
%]
[userglue]
RenderSurface? GetRenderSurface(CubeFace face, int mip_level, Pack pack);
%[
Sets the values of the data stored in the texture.
It is not recommend that you call this for large textures but it is useful
for making simple ramps or noise textures for shaders.
See o3d.Texture2D.set for details on formats.
\param face the face to update.
\param level the mip level to update.
\param values Values to be stored in the buffer.
%]
[nocpp, userglue]
void Set(CubeFace face, int level, float[] values);
%[
Sets a rectangular area of values in a texture.
Does clipping. In other words if you pass in a 10x10 pixel array
and give it destination of (-5, -5) it will only use the bottom 5x5
pixels of the array you passed in to set the top 5x5 pixels of the
texture.
See o3d.Texture2D.set for details on formats.
\param face the face to update.
\param level the mip level to update.
\param destination_x The x coordinate of the area in the texture to affect.
\param destination_y The y coordinate of the area in the texture to affect.
\param source_width The width of the area to effect. The height is
determined by the size of the array passed in.
\param values Values to be stored in the buffer.
\see o3d.Texture2D.set
%]
[nocpp, userglue]
void SetRect(CubeFace face,
int level,
int destination_x,
int destination_y,
int source_width,
float[] values);
%[
Gets a rectangular area of values from a texture.
See o3d.Texture2D.set for details on formats.
Can not be used for compressed textures.
\param face the face to get.
\param level the mip level to get.
\param x The x coordinate of the area in the texture to retrieve.
\param y The y coordinate of the area in the texture to retrieve.
\param width The width of the area to retrieve.
\param height The height of the area to retrieve.
\return Array of pixel values.
%]
[nocpp, userglue]
float[] GetRect(CubeFace face,
int level,
int x,
int y,
int width,
int height);
%[
Sets the content of a face of the texture to the content of the bitmap. The
texture and the bitmap must be the same dimensions and the same format.
\param face The face to set.
\param bitmap The bitmap to copy data from.
%]
[userglue]
void SetFromBitmap(CubeFace face, Bitmap bitmap);
[verbatim=cpp_glue] %{
void userglue_method_SetFromBitmap(o3d::TextureCUBE* self,
o3d::TextureCUBE::CubeFace face,
o3d::Bitmap* bitmap) {
self->SetFromBitmap(face, *bitmap);
}
%}
%[
Copy pixels from source bitmap to certain face and mip level.
Scales if the width and height of source and dest do not match.
\param source_img The source bitmap.
\param source_mip which mip of the source to copy from.
\param source_x x-coordinate of the starting pixel in the source image.
\param source_y y-coordinate of the starting pixel in the source image.
\param source_width width of the source image to draw.
\param source_height Height of the source image to draw.
\param face on which face to draw on.
\param dest_mip on which mip level to draw on.
\param dest_x x-coordinate of the starting pixel in the destination texture.
\param dest_y y-coordinate of the starting pixel in the destination texture.
\param dest_width width of the destination image.
\param dest_height height of the destination image.
%]
[userglue]
void DrawImage(Bitmap source_img, int source_mip, int source_x, int source_y,
int source_width, int source_height,
CubeFace face, int dest_mip,
int dest_x, int dest_y,
int dest_width, int dest_height);
%[
Copy pixels from source canvas to certain face and mip level.
Scales if the width and height of source and dest do not match.
\param source_img The source canvas.
\param source_x x-coordinate of the starting pixel in the source image.
\param source_y y-coordinate of the starting pixel in the source image.
\param source_width width of the source image to draw.
\param source_height Height of the source image to draw.
\param face on which face to draw on.
\param dest_mip on which mip level to draw on.
\param dest_x x-coordinate of the starting pixel in the destination texture.
\param dest_y y-coordinate of the starting pixel in the destination texture.
\param dest_width width of the destination image.
\param dest_height height of the destination image.
%]
[userglue, include="core/cross/canvas.h"]
void DrawImage(Canvas source_img, int source_x, int source_y,
int source_width, int source_height,
CubeFace face, int dest_mip,
int dest_x, int dest_y,
int dest_width, int dest_height);
[verbatim=cpp_glue] %{
void userglue_method_DrawImage(
o3d::TextureCUBE* self,
o3d::Bitmap* source_img, int source_mip, int source_x, int source_y,
int source_width, int source_height,
o3d::TextureCUBE::CubeFace dest_face, int dest_mip,
int dest_x, int dest_y,
int dest_width, int dest_height) {
self->DrawImage(*source_img, source_mip, source_x, source_y,
source_width, source_height,
dest_face, dest_mip,
dest_x, dest_y,
dest_width, dest_height);
}
void userglue_method_DrawImage(
o3d::TextureCUBE* self,
o3d::Canvas* source_img, int source_x, int source_y,
int source_width, int source_height,
o3d::TextureCUBE::CubeFace dest_face, int dest_mip,
int dest_x, int dest_y,
int dest_width, int dest_height) {
self->DrawImage(*source_img, source_x, source_y,
source_width, source_height,
dest_face, dest_mip,
dest_x, dest_y,
dest_width, dest_height);
}
o3d::RenderSurface* userglue_method_GetRenderSurface(
o3d::TextureCUBE* self,
o3d::TextureCUBE::CubeFace face,
int mip_level,
o3d::Pack* pack) {
return self->GetRenderSurface(face, mip_level);
}
%}
}; // TextureCUBE
} // namespace o3d