#pragma region CPL License
/*
Nuclex Native Framework
Copyright (C) 2002-2013 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#pragma endregion // CPL License
#ifndef NUCLEX_GRAPHICS_RASTERIZATION_TEXTURE2_H
#define NUCLEX_GRAPHICS_RASTERIZATION_TEXTURE2_H
#include "Texture.h"
#include "../Rectangle.h"
namespace Nuclex { namespace Graphics { namespace Rasterization {
// ------------------------------------------------------------------------------------------- //
///Two-dimensional texture typically mapped onto polygons
class Texture2 : public Texture {
/// Initializes a new texture with the specified size
/// Width of the texture in pixels
/// Height of the texture in pixels
/// Memory layout the texture's pixels will use
/// How the texture is going to be used
public: NUCLEX_GRAPHICS_API Texture2(
std::size_t width, std::size_t height,
PixelFormat::Enum pixelFormat,
Usage::Enum usage = Usage::Immutable
);
/// Initializes a texture by copying an existing texture
/// Existing texture that will be copied
public: NUCLEX_GRAPHICS_API Texture2(const Texture2 &other);
/// Destroys the texture
public: NUCLEX_GRAPHICS_API virtual ~Texture2();
/// Returns the capacity of the buffer in bytes
/// The number of bytes that fit in the buffer
public: NUCLEX_GRAPHICS_API std::size_t GetSizeInBytes() const {
return this->SizeInBytes;
}
/// Erases the contents of the texture
public: NUCLEX_GRAPHICS_API virtual void Clear();
/// Counts the number of dimensions the texture has
/// The texture's number of dimensions
public: NUCLEX_GRAPHICS_API virtual std::size_t CountDimensions() const {
return 2;
}
/// Retrieves the length of one of the texture's dimensions
///
/// Index of the dimension whose length will be returned
///
/// The length of the specified dimension
public: NUCLEX_GRAPHICS_API virtual std::size_t GetLength(
std::size_t dimensionIndex
) const;
/// Retrieves the width of the texture in pixels
/// The texture's width in pixels
public: NUCLEX_GRAPHICS_API std::size_t GetWidth() const { return this->width; }
/// Retrieves the height of the texture in pixels
/// The texture's height in pixels
public: NUCLEX_GRAPHICS_API std::size_t GetHeight() const { return this->height; }
/// Reads the specified region of the texture
/// Region of the texture that will be read
/// Address at which the texture's pixels will be deposited
/// Bytes required to get from one line to the next
public: NUCLEX_GRAPHICS_API void Read(
const Rectangle ®ion, void *target, std::size_t targetStride
);
/// Write the specified pixels into the texture
/// Region of the texture the pixels will be written to
/// Pixels that will be written into the texture
/// Bytes required to get from one line to the next
public: NUCLEX_GRAPHICS_API void Write(
const Rectangle ®ion, const void *source, std::size_t sourceStride
);
/// Accesses the memory used by the texture
/// The memory storing the texture's pixels
public: NUCLEX_GRAPHICS_API const std::uint8_t *AccessMemory() const {
return this->Pixels;
}
/// Accesses the memory used by the texture
/// The memory storing the texture's pixels
public: NUCLEX_GRAPHICS_API std::uint8_t *AccessMemory() {
return this->Pixels;
}
/// Marks the specified region of the texture as dirty
/// Region that will be marked as dirty
public: NUCLEX_GRAPHICS_API void MarkDirty(const Rectangle ®ion);
/// Copies the contents of another buffer into this buffer
/// Other buffer whose contents will be copied
/// A reference to this buffer
public: NUCLEX_GRAPHICS_API Texture2 &operator =(const Texture2 &other);
/// Verifies that the region to be read or written is in order
/// Region that will be verified
///
/// Regions must not leave the texture and compressed pixel formats may
/// require them to be aligned to compressed blocks (for example, in BC3 each
/// 16 bytes describe a 4x4 pixel region, so the region coordinates need to be
/// a multiple of 4 on both axes).
///
private: void verifyRegion(const Rectangle ®ion) const;
/// Width of the texture in pixels
protected: const std::size_t width;
/// Height of the texture in pixels
protected: const std::size_t height;
};
// ------------------------------------------------------------------------------------------- //
}}} // namespace Nuclex::Graphics::Rasterization
#endif // NUCLEX_GRAPHICS_RASTERIZATION_TEXTURE2_H