Commit c90b9ed4 authored by Tim Übelhör's avatar Tim Übelhör

templated rasterizer image.

fixed not implemented bug.
parent 4b6b9285
......@@ -29,7 +29,8 @@ public:
static const GLenum FORMAT = GL_RED;
static const GLenum TYPE = GL_FLOAT;
static const GLint INTERNAL_FORMAT = GL_R32F;
static const size_t PIXEL_SIZE = sizeof(GLfloat);
static const size_t CHANNELS = 1;
static const size_t PIXEL_SIZE = CHANNELS * sizeof(GLfloat);
private:
// where and how to render
......
......@@ -12,8 +12,9 @@ class Rasterizer
{
public:
/**
* Defines a header that is compatible to the OpenCV Mat_<float> constructor.
* Defines a header that is compatible to the OpenCV Mat_<T> constructor.
*/
template <typename T>
struct ImageHeader
{
/** height of the image */
......@@ -21,7 +22,7 @@ public:
/** width of the image */
size_t columns;
/** points to the first pixel of the image in the texture */
void *data;
T *data;
/** size in bytes of one row in the image */
size_t step;
};
......@@ -66,19 +67,36 @@ public:
* \param row of the view
* \param column of the view
* \param data pointer to the full texture
* \param pixel_size size of one pixel in bytes (sizeof(type) * n_channels)
* \param channels number of channels in the image
*/
ImageHeader get_image(size_t row, size_t column, void *data,
size_t pixel_size) const;
template <typename T>
ImageHeader<T> get_image(size_t row, size_t column, void *data,
size_t channels) const
{
auto xy = view_xy(row, column);
// all the rows above and the columns in front
ImageHeader<T> header;
header.data = static_cast<T *>(data) +
(xy.second * texture_width + xy.first) * channels;
header.columns = width;
header.rows = height;
header.step = texture_width * channels * sizeof(T);
return header;
}
/**
* Create metadata to read one view as image from the texture of all views.
* \param view get the image for this view
* \param data pointer to the full texture
* \param pixel_size size of one pixel in bytes (sizeof(type) * n_channels)
* \param channels number of channels in the image
*/
ImageHeader get_image(size_t view, void *data,
size_t pixel_size) const;
template <typename T>
ImageHeader<T> get_image(size_t view, void *data,
size_t channels) const
{
auto pos = view_position(view);
return get_image<T>(pos.first, pos.second, data, channels);
}
size_t get_views_per_row() const;
size_t get_views_per_column() const;
......
......@@ -56,7 +56,7 @@ void FrameBuffer::clear(float color, float depth, int stencil) const
deactivate();
}
static int get_max_size()
int FrameBuffer::get_max_size()
{
int max_rbo_size;
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &max_rbo_size);
......
......@@ -92,28 +92,6 @@ void Rasterizer::set_view_height(size_t height)
texture_height = views_per_column * height;
}
Rasterizer::ImageHeader Rasterizer::get_image(
size_t row, size_t column, void *data, size_t pixel_size) const
{
auto xy = view_xy(row, column);
// all the rows above and the columns in front
ImageHeader header;
// pixel size is in bytes so do arithmetics in bytes
header.data = static_cast<uint8_t *>(data) +
(xy.second * texture_width + xy.first) * pixel_size;
header.columns = width;
header.rows = height;
header.step = texture_width * pixel_size;
return header;
}
Rasterizer::ImageHeader Rasterizer::get_image(
size_t view, void *data, size_t pixel_size) const
{
auto pos = view_position(view);
return get_image(pos.first, pos.second, data, pixel_size);
}
std::pair<size_t, size_t> Rasterizer::view_position(size_t view) const
{
if (view > views_per_row * views_per_column)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment