3. introducing PVRTools

本文介绍了如何通过封装简化Shader的管理和使用,包括将顶点和片段Shader注册到内存文件系统中,以及如何从源文件和二进制文件加载Shader。此外,还探讨了图片资源的加载方法,并简要提及了3D打印文本的功能。

从这一节开始,对shader进行了封装.


项目中加入了FragShader.cpp
这个shader程序跟FragShader.fsh是一样的。它会加入到MemoryFileSystem中去。
// File data
static const char _FragShader_fsh[] =
    "uniform sampler2D  sTexture;/r/n"
    "/r/n"
    "varying mediump vec2  TexCoord;/r/n"
    "/r/n"
    "void main()/r/n"
    "{/r/n"
    "    gl_FragColor = texture2D(sTexture, TexCoord);/r/n"
    "}/r/n";

// Register FragShader.fsh in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_FragShader_fsh("FragShader.fsh", _FragShader_fsh, 137);

首先是vert/frag shader都以文件的形式出现:
// Source and binary shaders
const char c_szFragShaderSrcFile[]    = "FragShader.fsh";
const char c_szFragShaderBinFile[]    = "FragShader.fsc";
const char c_szVertShaderSrcFile[]    = "VertShader.vsh";
const char c_szVertShaderBinFile[]    = "VertShader.vsc";

CPVRTResourceFile VertexShaderSrcFile(c_szVertShaderSrcFile);
CPVRTResourceFile VertexShaderBinFile(c_szVertShaderBinFile);

CPVRTResourceFile的构造函数会先去MemoryFileSystem中找,如果找不到,则再从硬盘上读这个文件。

接下来则把shader字符串形式的源程序读成shader程序,编译:
PVRTShaderLoadBinaryFromMemory   对bin file
PVRTShaderLoadSourceFromMemory   对source file

上面一切都可以用下面这个函数更方便的实现
PVRTShaderLoadFromFile

对图片资源也进行了封装:
PVRTTextureLoadFromPVR(c_szTextureFile, &m_uiTexture)


另外仍然是传递unifor/attribute/varyings之类的参数,然后drawarray.



这个程序中还使用了CPVRTPrint3D
设置屏幕宽高,是否旋转
m_Print3D.SetTextures(0, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate
打字
m_Print3D.Print3D(8.0f, 30.0f, 1.5f, 0xFFAA4040, "example");
这部分就没有细究了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值