Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:16:28+00:00 2026-06-09T11:16:28+00:00

Or this code can be executed in a background thread safely? CGImageRef cgImage; CGContextRef

  • 0

Or this code can be executed in a background thread safely?

    CGImageRef cgImage;
    CGContextRef context;
    CGColorSpaceRef colorSpace;

    // Sets the CoreGraphic Image to work on it.
    cgImage = [uiImage CGImage];

    // Sets the image's size.
    _width = CGImageGetWidth(cgImage);
    _height = CGImageGetHeight(cgImage);

    // Extracts the pixel informations and place it into the data.
    colorSpace = CGColorSpaceCreateDeviceRGB();
    _data = malloc(_width * _height * 4);
    context = CGBitmapContextCreate(_data, _width, _height, 8, 4 * _width, colorSpace,
                                    kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGColorSpaceRelease(colorSpace);

    // Adjusts position and invert the image.
    // The OpenGL uses the image data upside-down compared commom image files.
    CGContextTranslateCTM(context, 0, _height);
    CGContextScaleCTM(context, 1.0, -1.0);

    // Clears and ReDraw the image into the context.
    CGContextClearRect(context, CGRectMake(0, 0, _width, _height));
    CGContextDrawImage(context, CGRectMake(0, 0, _width, _height), cgImage);

    // Releases the context.
    CGContextRelease(context);

How to acheive the same result, if not?

(My problem is that I can’t see my OpenGL textures based on the output buffer of this method, if it runs in the background)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:16:30+00:00Added an answer on June 9, 2026 at 11:16 am

    I think you might have trouble with running this code on a separate thread from GL’s like this. Even if it would work you might encounter half drawn images/textures. You could avoid this by creating a double buffer:
    Your “_data” should be allocated only once and should hold 2 raw image data buffers. Then just create 2 pointers defined as foreground and background buffer (void *fg = _data[0], void *bg = _data[1] to begin with). Now when your method collects data from CGImage to bg just swap the pointers (then void *fg = _data[1], void *bg = _data[0] or the other way around)
    Now your GL thread should fill your texture with data on fg (same thread as drawing).

    Also you might need some locking mechanisms:

    1. Before you push data to texture you should lock “buffer swap” and
      unlock it after the push.

    2. You will probably want to know if the
      buffer has been swapped and only push fg data to texture in such
      case.

    Also note that if you call GL methods on more then 1 thread you will have trouble in most cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to thread this below function so that the background form can continue
I would like to execute code sequentially in an NSOperation. This can be easily
Is there anyway this code can be refactored? The only difference is the order
The error shows this code can not rollback: class AddCountToTag < ActiveRecord::Migration def change
With this code I can download the file but I should know the file
With this code we can create a simple word document but I need to
From this code I can call bmwCars.CopyToDataTable() as I expected. var bmwCars = from
With this code I can check the caret position in a textarea in firefox:
I have this code which can display drop down in div tag of html.
I have this code ,now can anyone reply s what happens to the lock

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.