Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force all loaded textures to 32bpp in GLKit #2165

Merged
merged 3 commits into from
Mar 6, 2017

Conversation

msft-Jeyaram
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram commented Mar 6, 2017

GLKit's implementation of GLKTexture only handled an image format of 32bpp properly (other formats e.g 8bpp indexed,etc) was not handled properly (the code was never exercised).

The root cause of this was that the earlier Cairo implementation treated every image as a 32bpp. Thus when we created an image with it's proper pixel format, GLKTexture code didn't know how to handle it and thus the errors were produced.

fixes #2150

The fix converts the images to 32bpp, since GLKTexture does not support any other format properly.
Eventually, GLKTexure needs to be re-written properly.

Current Stage:
image

image

image

image

image

image

…/creation via converting the images to the correct format
+ (GLKTextureInfo*)textureWithContentsOfFile:(NSString*)fname options:(NSDictionary*)opts error:(NSError**)err {
CGDataProviderRef provider = CGDataProviderCreateWithFilename([fname UTF8String]);
CGImageRef img = _CGImageCreateFromDataProvider(provider);
static inline CGImageRef __Create32bppPRGBAImageFromFile(NSString* fname) {
Copy link
Contributor

@rajsesh rajsesh Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_CGImageCreateFromFileWithFormat(name, format) and export it from CG? #Resolved

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need like we are bloating CG. we already have an internal method, and we keep on building on top of it for every case. #Resolved

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i'll go ahead and make that change #Resolved

Copy link
Contributor

@rajsesh rajsesh Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CG has 600+ apis :). What belongs there has to belong there... #Resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you do make this API, please perhaps call it _CGImageCreateFromFileWithWICFormat -- specifically, we need to differentiate it from the CGBitmapInfo/CGAlphaInfo APIs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it'll have to take a CFStringRef.

+ (GLKTextureInfo*)textureWithCGImage:(CGImageRef)image options:(NSDictionary*)opts error:(NSError**)err {
woc::StrongCF<CGImageRef> img = { woc::MakeStrongCF(_CGImageCreateCopyWithPixelFormat(image, GUID_WICPixelFormat32bppPRGBA)) };

if (!img) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no macro here?

+ (GLKTextureInfo*)textureWithContentsOfFile:(NSString*)fname options:(NSDictionary*)opts error:(NSError**)err {
CGDataProviderRef provider = CGDataProviderCreateWithFilename([fname UTF8String]);
CGImageRef img = _CGImageCreateFromDataProvider(provider);
static inline CGImageRef __Create32bppPRGBAImageFromFile(NSString* fname) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you do make this API, please perhaps call it _CGImageCreateFromFileWithWICFormat -- specifically, we need to differentiate it from the CGBitmapInfo/CGAlphaInfo APIs.

+ (GLKTextureInfo*)textureWithContentsOfFile:(NSString*)fname options:(NSDictionary*)opts error:(NSError**)err {
CGDataProviderRef provider = CGDataProviderCreateWithFilename([fname UTF8String]);
CGImageRef img = _CGImageCreateFromDataProvider(provider);
static inline CGImageRef __Create32bppPRGBAImageFromFile(NSString* fname) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it'll have to take a CFStringRef.

return nil;
}

CGDataProviderRelease(provider);
provider = CGImageGetDataProvider(img);
CGDataProviderRef provider = CGImageGetDataProvider(img);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are fixing this code, you might as well make it use _CGDataProviderGetBytes.

@DHowett-MSFT
Copy link

Also nit: When you merge this, please fix the name to be GLKit, not GLKKit

@DHowett-MSFT DHowett-MSFT changed the title GLKKit enabling proper texture loading Force all loaded textures to 32bpp in GLKit Mar 6, 2017
@DHowett-MSFT
Copy link

I have renamed this pull request. Please add "Fixes #2150."

@msft-Jeyaram
Copy link
Contributor Author

I think taking in char * would be fine, given that's what CGDataProviderCreateWithFilename takes not.
so no need for CFString

@DHowett-MSFT
Copy link

@msft-Jeyaram please do not do that. We have strong, expressive string types for a reason.

NSString is bridged directly to CFStringRef; unless you want to deal with UTF8<->UTF16 issues like #1875 and #1891 I would implore you to use CFString.

@msft-Jeyaram
Copy link
Contributor Author

fixes #2150


RETURN_NULL_IF(!fname);

woc::StrongCF<CGDataProviderRef> provider{ woc::MakeStrongCF(CGDataProviderCreateWithFilename(fname)) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: these can be "auto provider = "

NSData* data = (id)CGDataProviderCopyData(provider);
[data autorelease];
auto bytesIn = (unsigned char*)[data bytes];
unsigned char* bytesIn = static_cast<unsigned char*>(const_cast<void*>(_CGDataProviderGetData(CGImageGetDataProvider(img))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: a c-style cast from const void* -> char* should suffice

CGImageRef _CGImageCreateFromFileWithWICFormat(CFStringRef filename, WICPixelFormatGUID format) {
RETURN_NULL_IF(!filename);

std::vector<char> buffer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second look, we'd be better off here creating a CFURL from the filename and using CGDataProviderCreateWithURL, because that's what CGDataProviderCreateWithFilename goes through, and we get the added bonus of not creating an extra CFStringRef as well as cutting down on the length of this function quite a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here was me thinking it was the other way around.

Copy link
Contributor

@aballway aballway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😃

@msft-Jeyaram msft-Jeyaram merged commit 64fb51d into microsoft:develop Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ARM] [x86] GLKitComplex images are missing
5 participants