MCPcopy Create free account
hub / github.com/arrayfire/forge / image_impl

Method image_impl

src/backend/opengl/image_impl.cpp:41–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41image_impl::image_impl(const uint pWidth, const uint pHeight,
42 const forge::ChannelFormat pFormat, const forge::dtype pDataType)
43 : mWidth(pWidth), mHeight(pHeight), mFormat(pFormat),
44 mGLformat(ctype2gl(mFormat)), mGLiformat(ictype2gl(mFormat)),
45 mDataType(pDataType), mGLType(dtype2gl(mDataType)), mAlpha(1.0f),
46 mKeepARatio(true), mFormatSize(1), mPBOsize(1), mPBO(0), mTex(0),
47 mProgram(glsl::image_vs.c_str(), glsl::image_fs.c_str()),
48 mMatIndex(-1), mTexIndex(-1), mNumCIndex(-1),
49 mAlphaIndex(-1), mCMapLenIndex(-1), mCMapIndex(-1)
50{
51 CheckGL("Begin image_impl::image_impl");
52
53 mMatIndex = mProgram.getUniformLocation("matrix");
54 mCMapIndex = mProgram.getUniformBlockIndex("ColorMap");
55 mCMapLenIndex = mProgram.getUniformLocation("cmaplen");
56 mTexIndex = mProgram.getUniformLocation("tex");
57 mNumCIndex = mProgram.getUniformLocation("numcomps");
58 mAlphaIndex = mProgram.getUniformLocation("alpha");
59
60 // Initialize OpenGL Items
61 glGenTextures(1, &(mTex));
62 glBindTexture(GL_TEXTURE_2D, mTex);
63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, static_cast<GLint>(GL_CLAMP_TO_EDGE));
64 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, static_cast<GLint>(GL_CLAMP_TO_EDGE));
65 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(GL_NEAREST));
66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, static_cast<GLint>(GL_NEAREST));
67
68 glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(mGLiformat), mWidth, mHeight, 0, mGLformat, mGLType, NULL);
69
70 CheckGL("Before PBO Initialization");
71 glGenBuffers(1, &mPBO);
72 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
73 size_t typeSize = 0;
74 switch(mGLType) {
75 case GL_INT: typeSize = sizeof(int ); break;
76 case GL_UNSIGNED_INT: typeSize = sizeof(uint ); break;
77 case GL_SHORT: typeSize = sizeof(short ); break;
78 case GL_UNSIGNED_SHORT: typeSize = sizeof(ushort); break;
79 case GL_BYTE: typeSize = sizeof(char ); break;
80 case GL_UNSIGNED_BYTE: typeSize = sizeof(uchar ); break;
81 default: typeSize = sizeof(float); break;
82 }
83 switch(mFormat) {
84 case FG_GRAYSCALE: mFormatSize = 1; break;
85 case FG_RG: mFormatSize = 2; break;
86 case FG_RGB: mFormatSize = 3; break;
87 case FG_BGR: mFormatSize = 3; break;
88 case FG_RGBA: mFormatSize = 4; break;
89 case FG_BGRA: mFormatSize = 4; break;
90 default: mFormatSize = 1; break;
91 }
92 mPBOsize = mWidth * mHeight * mFormatSize * typeSize;
93 glBufferData(GL_PIXEL_UNPACK_BUFFER, mPBOsize, NULL, GL_STREAM_COPY);
94
95 glBindTexture(GL_TEXTURE_2D, 0);
96 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
97
98 CheckGL("End image_impl::image_impl");

Callers

nothing calls this directly

Calls 5

ctype2glFunction · 0.85
ictype2glFunction · 0.85
dtype2glFunction · 0.85
getUniformLocationMethod · 0.80
getUniformBlockIndexMethod · 0.80

Tested by

no test coverage detected