Giter VIP home page Giter VIP logo

glinterop's Introduction

GLInterop

GLInterop is a library that supports interoperable render target between GL texture, Metal texture and CVPixelBufferRef.

Features

Render Target

GLInterop provides variety render targets to cover most business needs.

RenderTarget GL Texture GL Framebuffer Metal Texture CVPixelBufferRef
GLIRenderTarget o x x o
GLIMetalRenderTarget o x o o
GLIFramebufferTextureRenderTarget o o x x
GLITextureRenderTarget o x x x

GLIRenderer

GLIRenderer is a lightweight encapsulation of GL Program, which provides the basic ability to call GL Program.

GLIRenderer provides an inputTextures array, an output that supports multiple rendering target types, a clearColor for clearing framebuffer, and a render method for actual rendering operations.

For the setting of the view port, GLIRenderer provides the following methods:

- (void)setViewPortWithContentMode:(UIViewContentMode)contentMode inputSize:(CGSize)inputSize;

For vertex attributes, GLIRenderer provides the following methods:

- (void)setVertexAttributeToBuffer:(NSString *)attribName bytes:(void *)bytes size:(size_t)size;
- (void)applyVertexAttributes;

For uniform, the following methods will store the uniform value, and will not be passed to GL until the applyUniforms method is executed.

- (void)setUniform:(NSString *)uniformName bytes:(void *)bytes;
- (void)setTexture:(NSString *)textureName texture:(GLuint)glTexture;

This allows you to do some preparations for your GL Program before the actual rendering starts, such as parameter default settings, or some built-in static image texture settings.

If you override the render method, then you need to call this method to pass the uniform and all textures to the GL shader:

- (void)applyUniforms;

In fact, if GLIRenderer only provides these methods, it will still make you feel inconvenient to use. For example, inputTextures will assume that the texture in the shader is named "inputTexture + Number", which will reduce the readability of the shader. And, inputTextures is an array, which means that you must collect all the textures needed for rendering at once, even if only one of them is changed in the next rendering.

Now, this version provides a new way, you only need to define the property that begin with uniform_ in the subclass of GLIRenderer, and you can get/set the uniform of texture / float / int type.

@property (nonatomic, strong) id <GLITexture> uniform_blurTexture;
@property (nonatomic) float uniform_intensity;
@property (nonatomic) int uniform_stride;

This code means that to set blueTexture, intensity and stride in the shader, you only need to define it without writing these implementations. Actually GLIRenderer will generate these uniform getters/setters at runtime.

There're variant renderers in this framework:

GLIBaseShapeRenderer

GLIBaseShapeRenderer is used to render GL primitives, like texture quad, points, lines and triangle strips.

GLIViewRenderer

GLIViewRenderer is used to render a GL texture to a renderable surface which conforms to GLIRenderableSurface protocol (eg. GLIView).

GLITransform

GLITransform can apply a transform to it's input texture and render it to a output which specific a given size. It can be used for resizing, cropping, flipping content etc.

Utils

  • GLIContext
  • GLITextureCache
  • GLIMetalTextureCache
  • GLIPixelBufferPool
  • GLITexture
  • GLISyncObject

GLIView

GLIView is a pure view which conforms to GLIRenderableSurface protocol to be a renderable surface. There're no GL API calls in its implementation, which can avoid context management problems.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 8.0 or later.

Installation

GLInterop is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'GLInterop'

Author

Qin Hong, [email protected]

License

GLInterop is available under the MIT license. See the LICENSE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.