从这一节开始,对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");
这部分就没有细究了
3. introducing PVRTools
最新推荐文章于 2022-02-23 15:02:25 发布
本文介绍了如何通过封装简化Shader的管理和使用,包括将顶点和片段Shader注册到内存文件系统中,以及如何从源文件和二进制文件加载Shader。此外,还探讨了图片资源的加载方法,并简要提及了3D打印文本的功能。
526

被折叠的 条评论
为什么被折叠?



