Esempio n. 1
0
        public virtual void draw()
        {
            try
            {
                //  if (levelScale) Matrix.ScaleM(mModelMatrix, 0, GlobalVar.levelScale, GlobalVar.levelScale, GlobalVar.levelScale);

                ShaderCompiller shader = ShaderManager.getShader(shaderName);

                GLES20.GlUseProgram(shader.program);


                int size = 4; // data count 2 for vec2 4 for vec4
                int b    = 0;
                int c    = 0;

                GLES20.GlEnableVertexAttribArray(ShaderManager.getShader(shaderName).attrib_vertex);
                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[0]);
                GLES20.GlVertexAttribPointer(ShaderManager.getShader(shaderName).attrib_vertex, size, GLES20.GlFloat, false, b, c);

                GLES20.GlEnableVertexAttribArray(ShaderManager.getShader(shaderName).normal);
                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[2]);
                GLES20.GlVertexAttribPointer(ShaderManager.getShader(shaderName).normal, size, GLES20.GlFloat, false, b, c);

                GLES20.GlUniform3f(ShaderManager.getShader(shaderName).lightPos, render.eyeX, render.eyeY, render.eyeZ);

                GLES20.GlUniformMatrix4fv(ShaderManager.getShader(shaderName).mMVMatrixHandle, 1, false, render._mViewMatrix, 0); //MV Matrix
                                                                                                                                  //Matrix.SetIdentityM(mMVPMatrix, 0);
                float[] mModetView = new float[16];
                Matrix.MultiplyMM(mModetView, 0, render._mViewMatrix, 0, mModelMatrix, 0);

                Matrix.MultiplyMM(mMVPMatrix, 0, render.mProjectionMatrix, 0, mModetView, 0);
                GLES20.GlUniformMatrix4fv(ShaderManager.getShader(shaderName).mMVPMatrixHandle, 1, false, mMVPMatrix, 0); //MVP Matrix

                if (textureResID != -1)
                {
                    GLES20.GlEnableVertexAttribArray(ShaderManager.getShader(shaderName).mTextureCoordinateHandle);
                    GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[1]);
                    int bsize = 2;
                    GLES20.GlVertexAttribPointer(ShaderManager.getShader(shaderName).mTextureCoordinateHandle, bsize, GLES20.GlFloat, false, b, c);

                    GLES20.GlActiveTexture(GLES20.GlTexture0);
                    GLES20.GlBindTexture(GLES20.GlTexture2d, TextureManager.getTextureHandle(context, textureResID));
                    GLES20.GlUniform1i(ShaderManager.getShader(shaderName).mTextureUniformHandle, 0);


                    GLES20.GlActiveTexture(GLES20.GlTexture1);
                    GLES20.GlBindTexture(GLES20.GlTexture2d, TextureManager.getTextureHandle(context, texture2ResID));
                    GLES20.GlUniform1i(ShaderManager.getShader(shaderName).mTextureUniformHandleF, 1);

                    GLES20.GlActiveTexture(GLES20.GlTexture2);
                    GLES20.GlBindTexture(GLES20.GlTexture2d, TextureManager.getTextureHandle(context, texture3ResID));
                    GLES20.GlUniform1i(ShaderManager.getShader(shaderName).mTextureUniformHandleS, 2);
                }

                GLES20.GlDrawArrays(GLES20.GlTriangles, 0, VBOManager.getSize(fileName));

                GLES20.GlUseProgram(0);
            }
            catch { }
        }
Esempio n. 2
0
        public static void addShader(Context context, String name)
        { // Quality 1, 0
            if (getShader(name) != null)
            {
                return;
            }

            String fileName = "";

            //Temporary not use LOW shaders
            fileName = name;

            ShaderCompiller shader = new ShaderCompiller(context, name, fileName);

            shaderItems.Add(shader);
        }