GithubHelp home page GithubHelp logo

raybon-lee / shadermanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simsaens/shadermanager

0.0 2.0 0.0 107 KB

A very simple OpenGL ES shader manager for Objective-C

Home Page: http://twolivesleft.com

Objective-C 100.00%

shadermanager's Introduction

ShaderManager

ShaderManager is a simple singleton and class designed to wrap the OpenGL ES shader API. It is intended to provide the simplest API possible to keep track of shader programs, their attributes and uniforms.

It is not intended to remove the need to interact with OpenGL directly, but as a convenient location to store and access shader data.

Defining a Shader

Shaders are defined as plist files (in addition to the regular vsh/fsh files). The plist is structured as follows:

Files
    -- array containing the vsh and fsh files to be compiled and linked
Attributes
    -- array of strings specifying each attribute in the shader
Uniforms
    -- array of strings specifying each uniform in the shader

Using a Shader

ShaderManager consists of a singleton class (ShaderManager) and shader class (Shader)

Loading a shader from a plist

[[ShaderManager sharedManager] createShader:@"MyShader" withFile:@"MyShader.plist"]

Note that the plist file is looked up in the main bundle. You can use the following method to load from an NSDictionary instead.

[[ShaderManager sharedManager] createShader:@"MyShader" withSettings:settingsDictionary]

Using a shader

[[ShaderManager sharedManager] useShader:@"MyShader"]

Getting the currently active shader

Shader *myShader = [[ShaderManager sharedManager] currentShader]

Setting attributes and uniforms on a shader

//Uses "MyShader" and returns its shader object
Shader *myShader = [[ShaderManager sharedManager] useShader:@"MyShader"];

//Setting a uniform
float translation = 10.0f;
glUniform1f( [myShader uniformLocation:@"translation"], translation );

GLuint positionAttribute = [myShader attributeHandle:@"position"];
glVertexAttribPointer( positionAttribute, 2, GL_FLOAT, 0, 0, vertices );
glEnableVertexAttribArray( positionAttribute );

Sample Project

The included sample project is simply Apple's OpenGL template modified to use ShaderManager.

shadermanager's People

Contributors

simsaens avatar

Watchers

 avatar  avatar

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.