ios – iPad纹理加载差异(32位与64位)

ios – iPad纹理加载差异(32位与64位),第1张

概述我正在绘图应用程序,我注意到32位iPad与64位iPad上加载纹理有显着差异. 这是32位iPad上绘制的纹理: 这是64位iPad上绘制的纹理: 64位是我想要的,但似乎也许是丢失一些数据? 我用这段代码创建一个默认的刷子纹理: UIGraphicsBeginImageContext(CGSizeMake(64, 64));CGContextRef defBrushTextureConte 我正在绘图应用程序,我注意到32位iPad与64位iPad上加载的纹理有显着差异.

这是32位iPad上绘制的纹理:

这是64位iPad上绘制的纹理:

64位是我想要的,但似乎也许是丢失一些数据?

我用这段代码创建一个默认的刷子纹理:

UIGraphicsBeginImageContext(CGSizeMake(64,64));CGContextRef defBrushTextureContext = UIGraphicsGetCurrentContext();UIGraphicsPushContext(defBrushTextureContext);size_t num_locations = 3;CGfloat locations[3] = { 0.0,0.8,1.0 };CGfloat components[12] = { 1.0,1.0,0.0 };CGcolorSpaceRef mycolorspace = CGcolorSpaceCreateDeviceRGB();CGGradIEntRef myGradIEnt = CGGradIEntCreateWithcolorComponents (mycolorspace,components,locations,num_locations);CGPoint myCentrePoint = CGPointMake(32,32);float myRadius = 20;CGGradIEntDrawingOptions options = kCGGradIEntDrawsBeforeStartLocation | kCGGradIEntDrawsAfterEndLocation;CGContextDrawRadialGradIEnt (UIGraphicsGetCurrentContext(),myGradIEnt,myCentrePoint,myRadius,options);CFRelease(myGradIEnt);CFRelease(mycolorspace);UIGraphicsPopContext();[self setBrushTexture:UIGraphicsGetimageFromCurrentimageContext()];UIGraphicsEndImageContext();

然后实际上设置这样的画笔纹理:

-(voID) setBrushTexture:(UIImage*)brushImage{// save our current texture.currentTexture = brushImage;// first,delete the old texture if neededif (brushTexture){    glDeleteTextures(1,&brushTexture);    brushTexture = 0;}// fetch the cgimage for us to draw into a textureCGImageRef brushCGImage = brushImage.CGImage;// Make sure the image existsif(brushCGImage) {    // Get the wIDth and height of the image    Glint wIDth = CGImageGetWIDth(brushCGImage);    Glint height = CGImageGetHeight(brushCGImage);    // Texture dimensions must be a power of 2. If you write an application that allows users to supply an image,// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2.    // Allocate  memory needed for the bitmap context    glubyte* brushData = (glubyte *) calloc(wIDth * height * 4,sizeof(glubyte));    // Use  the bitmatp creation function provIDed by the Core Graphics framework.    CGContextRef brushContext = CGBitmapContextCreate(brushData,wIDth,height,8,wIDth * 4,CGImageGetcolorSpace(brushCGImage),kCGImageAlphaPremultiplIEdLast);    // After you create the context,you can draw the  image to the context.    CGContextDrawImage(brushContext,CGRectMake(0.0,0.0,(CGfloat)wIDth,(CGfloat)height),brushCGImage);    // You don't need the context at this point,so you need to release it to avoID memory leaks.    CGContextRelease(brushContext);    // Use OpenGL ES to generate a name for the texture.    glGenTextures(1,&brushTexture);    // Bind the texture name.    glBindTexture(GL_TEXTURE_2D,brushTexture);    // Set the texture parameters to use a Minifying filter and a linear filer (weighted average)    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_liNEAR);    // Specify a 2D texture image,provIDing the a pointer to the image data in memory    glTexImage2D(GL_TEXTURE_2D,GL_RGBA,GL_UNSIGNED_BYTE,brushData);    // Release  the image data; it's no longer needed    free(brushData);}}

更新:

我已经将CGfloats更新为GLfloats,没有成功.也许这个渲染代码有问题吗?

if(frameBuffer){    // draw the stroke element    [self prepOpenGLStateForFBO:frameBuffer];    [self prepOpenGLBlendModeForcolor:element.color];    CheckGLError();}// find our screen scale so that we can convert from// points to pixelsGLfloat scale = self.contentScaleFactor;// fetch the vertex data from the elementstruct Vertex* vertexBuffer = [element generatedVertexArrayWithPrevIoUsElement:prevIoUsElement forScale:scale];gllinewidth(2);// if the element has any data,then draw itif(vertexBuffer){    glVertexPointer(2,GL_float,sizeof(struct Vertex),&vertexBuffer[0].position[0]);    glcolorPointer(4,&vertexBuffer[0].color[0]);    glTexCoordPointer(2,&vertexBuffer[0].Texture[0]);    glDrawArrays(GL_TRIANGLES,(Glint)[element numberOfSteps] * (Glint)[element numberOfVerticesPerStep]);    CheckGLError();}if(frameBuffer){    [self unprepOpenGLState];}

顶点结构如下:

struct Vertex{    GLfloat position[2];    // x,y position    GLfloat color [4];      // rgba color    GLfloat Texture[2];    // x,y texture coord};

更新:

这个问题实际上并不是32位,64位,而是与A7 GPU和GL驱动程序不同.我发现这是通过在64位iPad上运行32位构建和64位构建.纹理最终在应用程序的两个构建上看起来完全相同.

解决方法 我想你们检查两件事情.

>在OpenGL中检查Alpha混合逻辑(或选项).
检查与拖动速度成比例的插值逻辑.

似乎你没有第二个或没有效果,这是绘制应用程序所必需的

总结

以上是内存溢出为你收集整理的ios – iPad纹理加载差异(32位与64位)全部内容,希望文章能够帮你解决ios – iPad纹理加载差异(32位与64位)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1110204.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存