MCPcopy Create free account
hub / github.com/ImageEngine/cortex / imagePrimitive

Method imagePrimitive

src/IECoreGL/AlphaTexture.cpp:145–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143
144
145IECoreImage::ImagePrimitivePtr AlphaTexture::imagePrimitive() const
146{
147 ScopedBinding binding( *this );
148
149 GLint width = 0;
150 GLint height = 0;
151 glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width );
152 glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height );
153
154 vector<float> data( width * height );
155
156 glGetTexImage( GL_TEXTURE_2D, 0, GL_ALPHA, GL_FLOAT, &data[0] );
157
158 FloatVectorDataPtr ad = new FloatVectorData();
159 vector<float> &a = ad->writable(); a.resize( width * height );
160
161 unsigned int i = 0;
162 for( int y=height-1; y>=0; y-- )
163 {
164 float *ra = &a[y*width];
165 for( int x=0; x<width; x++ )
166 {
167 ra[x] = data[i++];
168 }
169 }
170
171 Box2i imageExtents( V2i( 0, 0 ), V2i( width-1, height-1 ) );
172 IECoreImage::ImagePrimitivePtr image = new IECoreImage::ImagePrimitive( imageExtents, imageExtents );
173 image->channels["A"] = ad;
174
175 return image;
176}
177

Callers 1

testMethod · 0.95

Calls 2

writableMethod · 0.45
resizeMethod · 0.45

Tested by 1

testMethod · 0.76