Caffe2 - C++ API
A deep learning, cross platform ML framework
GLPlainTexture.cc
1 
2 #include "GLPlainTexture.h"
3 #include "GLPBO.h"
4 
5 #include "caffe2/core/logging.h"
6 #include "caffe2/core/timer.h"
7 
8 #define half_float_supported (GLContext::getGLContext()->halfFloatTextureSupported())
9 
10 #define FIXED_TYPE(_t) (((_t).type != GL_HALF_FLOAT || half_float_supported) ? (_t) : GLTexture::FP16_COMPAT)
11 
12 GLPlainTexture::GLPlainTexture(
13  const Type& type, const void* input, GLsizei width, GLsizei height, bool use_padding, GLint filter, GLint wrap)
14  : GLTexture(FIXED_TYPE(type), width, height, use_padding, filter, wrap) {
15  // caffe2::Timer timer;
16  // timer.Start();
17  glGenTextures(1, &_textureId);
18  glBindTexture(GL_TEXTURE_2D, _textureId);
19  glTexImage2D(GL_TEXTURE_2D, 0, _type.internalFormat, _stride, _height, 0, _type.format, _type.type, input);
20 
21  gl_log(
22  GL_VERBOSE,
23  "GLPlainTexture() - allocated textureId %d, internalFormat: 0x%X, format: 0x%X, type: 0x%X\n",
24  _textureId,
25  _type.internalFormat,
26  _type.format,
27  _type.type);
28 
29  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _filter);
30  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _filter);
31 
32 #if GL_EXT_texture_border_clamp
33  GLfloat borderColor[] = {0.0f, 0.0f, 0.0f, 0.0f};
34  glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR_EXT, borderColor);
35  // Set the texture to use the border clamp wrapping mode.
36  _wrap = GL_CLAMP_TO_BORDER_EXT;
37 #endif
38 
39  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, _wrap);
40  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _wrap);
41 
42  glBindTexture(GL_TEXTURE_2D, 0);
43  // LOG(INFO) << "glTexImage2D takes " << timer.MilliSeconds() << " ms";
44 }
45 
46 GLPlainTexture::GLPlainTexture(
47  const Type& type, const GLuint textureID, GLsizei width, GLsizei height, bool use_padding, GLint filter, GLint wrap)
48  : GLTexture(FIXED_TYPE(type), width, height, use_padding, filter, wrap) {
49  _textureId = textureID;
50  isOwner = false;
51  gl_log(
52  GL_VERBOSE,
53  "GLPlainTexture() - wrapped textureId %d, internalFormat: 0x%X, format: 0x%X, type: 0x%X\n",
54  _textureId,
55  _type.internalFormat,
56  _type.format,
57  _type.type);
58 }