Giter VIP home page Giter VIP logo

ofxdxt's Introduction

ofxDXT

Compress ofPixels into DXT OpenGL textures. Texture compression can be very useful to fit more data into your GPU, but also to be able to stream texture data into your GPU faster.

DXT offers a 4:1 compression ratio.

This addon also allows you to save the compressed data to disk, and load it back. The format in which the data is not standard; usually you would save this data as a .DDS file, but I had to time to look into that, and I didnt really need it either. The file format itself is a 9 byte header followed by the raw data, which is great for realtime loading of textures.

How to Use

	//load a test PNG into ofPixels
	ofPixels pix;
	ofLoadImage(pix, "alphaTest.png");

	//create an ofxDXT::Data obj to store compressed texture
	ofxDXT::Data compressedPix;

	//compress RGBA pixels into DXT data
	ofxDXT::compressRgbaPixels(pix, compressedPix);

	ofTexture compressedTexture;
	//load this data into an ofTexture - this sets the right internal GL types
	ofxDXT::loadDataIntoTexture(compressedPix2, compressedTexture);

Required changes in Openframeworks

For ofTexture to play nice with DXT compressed textures, you will need to make some changes to OpenFrameworks's ofTexture class. Specifically, in the ofTexture::allocate() and ofTexture::loadData() methods.

See these changes here.

Basically, you need to use glCompressedTexImage2D() instead of glTexImage2D() to allocate the compressed DXT texture data, and glCompressedTexSubImage2D() instead of glTexSubImage2D(). Some other arguments need to be changed as well, so this changes handles that.

These changes will only apply when an ofTexture's glInternalFormat is set to GL_COMPRESSED_RGB_S3TC_DXT*_EXT, so it should not affect its normal usage.

Notes

DXT textures come with some constrains. They need to be GL_TEXTURE_2D (which the addon takes care of), and their sizes (width and height) need to be multiple of 4.

This is because the compression algorithm works on 4-pixel blocks. If you supply pixels that don't follow this constrain, the addon will "grow" your texture by up to 3 pixels in each dimension to comply. Those pixels will be transparent.

You can always find out the size of the texture after compression by querying the ofxDXT::Data with getWidth() and getHeight();

License

ofxDXT has been created by Oriol Ferrer Mesià and released under MIT license.

ofxDXT uses stb_dxt.h from the stb libs, which are public domain.

To Do

  • PR to OpenFramworks to support DXT?

ofxdxt's People

Contributors

armadillu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.