MCPcopy Create free account
hub / github.com/DaedalusX64/daedalus / SetData

Method SetData

Source/SysGL/Graphics/NativeTextureGL.cpp:270–386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268
269
270void CNativeTexture::SetData( void * data, void * palette )
271{
272 // It's pretty gross that we don't pass this in, or better yet, provide a way for
273 // the caller to write directly to our buffers instead of setting the data.
274 size_t data_len = GetBytesRequired();
275 memcpy(mpData, data, data_len);
276
277 if (mTextureFormat == TexFmt_CI4_8888)
278 {
279 memcpy(mpPalette, palette, kPalette4BytesRequired);
280 }
281 else if (mTextureFormat == TexFmt_CI8_8888)
282 {
283 memcpy(mpPalette, palette, kPalette8BytesRequired);
284 }
285
286 if (HasData())
287 {
288 glBindTexture( GL_TEXTURE_2D, mTextureId );
289 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
290
291 switch (mTextureFormat)
292 {
293 case TexFmt_5650:
294 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
295 mCorrectedWidth, mCorrectedHeight,
296 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, data );
297 break;
298 case TexFmt_5551:
299 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
300 mCorrectedWidth, mCorrectedHeight,
301 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, data );
302 break;
303 case TexFmt_4444:
304 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
305 mCorrectedWidth, mCorrectedHeight,
306 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, data );
307
308 break;
309 case TexFmt_8888:
310 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
311 mCorrectedWidth, mCorrectedHeight,
312 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data );
313
314 break;
315 case TexFmt_CI4_8888:
316 {
317 // Convert palletised texture to non-palletised. This is wsteful - we should avoid generating these updated for OSX.
318 const NativePfCI44 * pix_ptr = static_cast< const NativePfCI44 * >( data );
319 const NativePf8888 * pal_ptr = static_cast< const NativePf8888 * >( palette );
320
321 NativePf8888 * out = static_cast<NativePf8888 *>( malloc(mCorrectedWidth * mCorrectedHeight * sizeof(NativePf8888)) );
322 NativePf8888 * out_ptr = out;
323
324 u32 pitch = GetStride();
325
326 for (u32 y = 0; y < mCorrectedHeight; ++y)
327 {

Callers 2

UpdateTextureFunction · 0.45
LoadPngFunction · 0.45

Calls 3

GetIdxAMethod · 0.80
GetIdxBMethod · 0.80

Tested by

no test coverage detected