MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
texture.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#include "ogl/texture.h"
11
13
14void
15Texture::upload (mve::ByteImage::ConstPtr image)
16{
17
18 GLint level = 0;
19 GLint int_format = GL_RGBA;
20 GLsizei w(image->width()), h(image->height()), c(image->channels());
21 GLint border = 0;
22
23 /* Set image properties. */
24 void* data = (void*)const_cast<uint8_t*>(image->get_data_pointer());
25 GLint type = GL_UNSIGNED_BYTE;
26 GLint format = GL_RGBA;
27 switch (c)
28 {
29 case 1: format = GL_RED; break;
30 case 2: format = GL_RG; break;
31 case 3: format = GL_RGB; break;
32 case 4: format = GL_RGBA; break;
33 default:
34 throw std::invalid_argument("Invalid amount of image channels");
35 }
36
37#if 0
38 std::cout << "Level: " << level << ", internal format: " << int_format
39 << ", size: " << w << "x" << h << ", format: " << format
40 << std::endl;
41#endif
42
43 this->bind();
44 glTexImage2D(GL_TEXTURE_2D, level, int_format, w, h,
45 border, format, type, data);
46 glGenerateMipmap(GL_TEXTURE_2D);
47}
48
std::shared_ptr< Image< T > const > ConstPtr
Definition image.h:43
#define OGL_NAMESPACE_END
Definition defines.h:14
#define OGL_NAMESPACE_BEGIN
Definition defines.h:13