コード例 #1
0
ファイル: RenderManager.cs プロジェクト: DenisKirinACS/SeaBan
 public static void initShaders()
 {
     VBOManager.clearVBO();
     TextureManager.clearTextures();
     ShaderManager.clear();
     render.initShaders();
 }
コード例 #2
0
ファイル: SceneObject.cs プロジェクト: KirinDenis/SeaBan
        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 { }
        }
コード例 #3
0
ファイル: SceneObject.cs プロジェクト: KirinDenis/SeaBan
        //----------------------------------------------------------------------
        public virtual void loadFileToVBO(String fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            files.Add(fileName);
            int indexResult = VBOManager.getVBOIndex(fileName);

            if (indexResult == -1)
            {
                if (loadingBinModel(fileName))
                {
                    GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[0]);
                    GLES20.GlBufferData(GLES20.GlArrayBuffer, vertexBuffer.Capacity() * FLOAT_SIZE, vertexBuffer, GLES20.GlStaticDraw); // vbb.capacity()
                    vertexBuffer = null;

                    GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[2]);
                    GLES20.GlBufferData(GLES20.GlArrayBuffer, normalBuffer.Capacity() * FLOAT_SIZE, normalBuffer, GLES20.GlStaticDraw); // vbb.capacity()
                    normalBuffer = null;

                    GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[1]);
                    GLES20.GlBufferData(GLES20.GlArrayBuffer, textureBuffer.Capacity() * FLOAT_SIZE, textureBuffer, GLES20.GlStaticDraw); // vbb.capacity()
                    textureBuffer = null;
                    System.GC.Collect();
                }
            }
        }
コード例 #4
0
ファイル: RenderManager.cs プロジェクト: DenisKirinACS/SeaBan
 public static void createObjects()
 {
     TextureManager.clearTextures();
     ShaderManager.clear();
     VBOManager.clearVBO();
     render = new SceneRender();
     render.CreateObjects(1);
 }
コード例 #5
0
ファイル: Circle.cs プロジェクト: KirinDenis/SeaBan
        public override void loadFileToVBO(String fileName)
        {
            if (fileName == "")
            {
                return;
            }
            files.Add(fileName);
            int indexResult = VBOManager.getVBOIndex(fileName);

            if (indexResult == -1)
            {
                List <float[]> vertexes  = new List <float[]>();
                List <float[]> normales  = new List <float[]>();
                List <float[]> textures  = new List <float[]>();
                float          alphaStep = (float)(2 * Math.PI) / steps;
                float          alpha     = 0;

                //front and back faces
                for (int i = 0; i < steps; i++)
                {
                    //triagle face
                    float[] v1 = new float[4]; //vertex 1
                    float[] v2 = new float[4]; //vertex 2
                    float[] v3 = new float[4]; //vertex 3

                    //top face
                    v1[0] = 0;      //x
                    v1[1] = 0;      //y
                    v1[2] = height; //z
                    v1[3] = 1;

                    v2[0] = radius * (float)Math.Sin(alpha);
                    v2[1] = radius * (float)Math.Cos(alpha);
                    v2[2] = height; //z
                    v2[3] = 1;

                    alpha += alphaStep;

                    v3[0] = radius * (float)Math.Sin(alpha);
                    v3[1] = radius * (float)Math.Cos(alpha);
                    v3[2] = height; //z
                    v3[3] = 1;

                    vertexes.Add(v1);
                    vertexes.Add(v2);
                    vertexes.Add(v3);

                    //normales
                    float[] normale = new float[4]; //vertex 1
                    normale[0] = -1;                //x
                    normale[1] = 0;                 //y
                    normale[2] = 0;                 //z
                    normale[3] = 1;

                    normales.Add(normale);
                    normales.Add(normale);
                    normales.Add(normale);

                    float[] t1 = new float[2];
                    float[] t2 = new float[2];
                    float[] t3 = new float[2];
                    t1[0] = 0.0f;
                    t1[1] = 0.0f;
                    t2[0] = 0.0f;
                    t2[1] = 0.0f;
                    t3[0] = 0.0f;
                    t3[1] = 0.0f;
                    textures.Add(t1);
                    textures.Add(t2);
                    textures.Add(t3);


                    //spin face (from top) -----------
                    float[] vS1 = new float[4]; //vertex 1
                    float[] vS2 = new float[4]; //vertex 2
                    float[] vS3 = new float[4]; //vertex 3
                    vS1[0] = radius * (float)Math.Sin(alpha);
                    vS1[1] = radius * (float)Math.Cos(alpha);
                    vS1[2] = 0; //z
                    vS1[3] = 1;
                    vS2    = v2;
                    vS3    = v3;
                    vertexes.Add(vS1);
                    vertexes.Add(vS2);
                    vertexes.Add(vS3);

                    normale = new float[4]; //vertex 1
                    normales.Add(normale);
                    normales.Add(normale);
                    normales.Add(normale);

                    //SPIN TEXTURE FACE
                    //Spin face texture -----------------------------------

                    t1 = new float[2];
                    t2 = new float[2];
                    t3 = new float[2];

                    t1[0] = coordToTexture(textureStep);
                    t1[1] = coordToTexture(textureStep * i);
                    t2[0] = coordToTexture(textureStep * 2);
                    t2[1] = coordToTexture(textureStep * i);
                    t3[0] = coordToTexture(textureStep);                   //texture x
                    t3[1] = coordToTexture(textureStep * i + textureStep); //texture y


                    textures.Add(t3);
                    textures.Add(t2);
                    textures.Add(t1);
                    //--------------------------------------------------------

                    //back face -------------------------------------
                    alpha -= alphaStep;
                    v1     = new float[4]; //vertex 1
                    v2     = new float[4]; //vertex 2
                    v3     = new float[4]; //vertex 3

                    //top face
                    v1[0] = 0; //x
                    v1[1] = 0; //y
                    v1[2] = 0; //z
                    v1[3] = 1;

                    v2[0] = radius * (float)Math.Sin(alpha);
                    v2[1] = radius * (float)Math.Cos(alpha);
                    v2[2] = 0; //z
                    v2[3] = 1;

                    alpha += alphaStep;

                    v3[0] = radius * (float)Math.Sin(alpha);
                    v3[1] = radius * (float)Math.Cos(alpha);
                    v3[2] = 0; //z
                    v3[3] = 1;

                    vertexes.Add(v1);
                    vertexes.Add(v2);
                    vertexes.Add(v3);

                    //normales
                    normale    = new float[4]; //vertex 1
                    normale[0] = -1;           //x
                    normale[1] = 0;            //y
                    normale[2] = 0;            //z
                    normale[3] = 1;

                    normales.Add(normale);
                    normales.Add(normale);
                    normales.Add(normale);

                    t1    = new float[2];
                    t2    = new float[2];
                    t3    = new float[2];
                    t1[0] = 0;
                    t1[1] = 0;
                    t2[0] = 0;
                    t2[1] = 0;
                    t3[0] = 0;
                    t3[1] = 0;
                    textures.Add(t1);
                    textures.Add(t2);
                    textures.Add(t3);


                    //spin face (from top) -----------
                    alpha -= alphaStep;
                    vS1    = new float[4]; //vertex 1
                    vS2    = new float[4]; //vertex 2
                    vS3    = new float[4]; //vertex 3
                    vS1[0] = radius * (float)Math.Sin(alpha);
                    vS1[1] = radius * (float)Math.Cos(alpha);
                    vS1[2] = height; //z
                    vS1[3] = 1;

                    vS2 = v2;
                    vS3 = v3;
                    vertexes.Add(vS1);
                    vertexes.Add(vS2);
                    vertexes.Add(vS3);

                    normale = new float[4]; //vertex 1
                    normales.Add(normale);
                    normales.Add(normale);
                    normales.Add(normale);

                    t1    = new float[2];
                    t2    = new float[2];
                    t3    = new float[2];
                    t1[0] = coordToTexture(textureStep * 2); //texture x
                    t1[1] = coordToTexture(textureStep * i); //texture y
                    t2[0] = coordToTexture(textureStep * 2);
                    t2[1] = coordToTexture(textureStep * i + textureStep);
                    t3[0] = coordToTexture(textureStep);
                    t3[1] = coordToTexture(textureStep * i + textureStep);
                    textures.Add(t1);
                    textures.Add(t2);
                    textures.Add(t3);

                    alpha += alphaStep;
                }

                long size = vertexes.Count;               //all faces (faces*4 = all vertex)

                float[] floatArray = new float[size * 4]; //4 float to one vertex, 3 vertex to one face  slow way
                for (int i = 0; i < vertexes.Count; i++)
                {
                    floatArray[i * 4 + 0] = vertexes[i][0];
                    floatArray[i * 4 + 1] = vertexes[i][1];
                    floatArray[i * 4 + 2] = vertexes[i][2];
                    floatArray[i * 4 + 3] = vertexes[i][3];
                }

                vertexBuffer = FloatBuffer.Allocate((int)size * 4); // float array to
                vertexBuffer.Put(floatArray, 0, (int)size * 4);
                vertexBuffer.Flip();

                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[0]);
                GLES20.GlBufferData(GLES20.GlArrayBuffer, vertexBuffer.Capacity() * FLOAT_SIZE, vertexBuffer, GLES20.GlStaticDraw); // vbb.capacity()
                vertexBuffer = null;
                floatArray   = null;

                //-----------------------------------------------------------------------
                floatArray = new float[size * 4]; //4 float to one vertex, 3 vertex to one face  slow way
                for (int i = 0; i < vertexes.Count; i++)
                {
                    floatArray[i * 4 + 0] = normales[i][0];
                    floatArray[i * 4 + 1] = normales[i][1];
                    floatArray[i * 4 + 2] = normales[i][2];
                    floatArray[i * 4 + 3] = normales[i][3];
                }
                normalBuffer = FloatBuffer.Allocate((int)size * 4);
                normalBuffer.Put(floatArray, 0, (int)size * 4);
                normalBuffer.Flip();

                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[2]);
                GLES20.GlBufferData(GLES20.GlArrayBuffer, normalBuffer.Capacity() * FLOAT_SIZE, normalBuffer, GLES20.GlStaticDraw); // vbb.capacity()
                normalBuffer = null;

                //-----------------------------------------------------------------------
                floatArray = new float[size * 2]; //2 float
                for (int i = 0; i < textures.Count; i++)
                {
                    floatArray[i * 2 + 0] = textures[i][0];
                    floatArray[i * 2 + 1] = textures[i][1];
                }
                textureBuffer = FloatBuffer.Allocate((int)size * 2);
                textureBuffer.Put(floatArray, 0, (int)size * 2);
                textureBuffer.Flip();

                GLES20.GlBindBuffer(GLES20.GlArrayBuffer, VBOManager.getVBO(fileName)[1]);
                GLES20.GlBufferData(GLES20.GlArrayBuffer, textureBuffer.Capacity() * FLOAT_SIZE, textureBuffer, GLES20.GlStaticDraw); // vbb.capacity()
                textureBuffer = null;

                VBOManager.setSize(fileName, (int)size);
            }
        }
コード例 #6
0
ファイル: SceneObject.cs プロジェクト: KirinDenis/SeaBan
        public bool loadingBinModel(String fileName)
        {
            float[] floatArray;
            long    size;

            try
            {
                // Vertex
                vertexBuffer = null;
                System.GC.Collect();
                int          resourceId = context.Resources.GetIdentifier(fileName + "_vert", "raw", context.PackageName);
                Stream       fileIn     = context.Resources.OpenRawResource(resourceId) as Stream;
                MemoryStream m          = new MemoryStream();
                fileIn.CopyTo(m);
                size       = m.Length;
                floatArray = new float[size / 4];
                System.Buffer.BlockCopy(m.ToArray(), 0, floatArray, 0, (int)size);

                vertexBuffer = FloatBuffer.Allocate((int)size / 4); // float array to
                vertexBuffer.Put(floatArray, 0, (int)size / 4);
                vertexBuffer.Flip();

                VBOManager.setSize(fileName, vertexBuffer.Capacity() / 4); //is size of vertex count = 1 vertex 4 float x,y,z, 1
                floatArray = null;
                fileIn.Close();
                m.Close();
                //----------------------------------------------------------------------------------------------------

                normalBuffer = null;
                System.GC.Collect();
                resourceId = context.Resources.GetIdentifier(fileName + "_norm", "raw", context.PackageName);
                fileIn     = context.Resources.OpenRawResource(resourceId) as Stream;
                m          = new MemoryStream();
                fileIn.CopyTo(m);
                size       = m.Length;
                floatArray = new float[size / 4];
                System.Buffer.BlockCopy(m.ToArray(), 0, floatArray, 0, (int)size);

                normalBuffer = FloatBuffer.Allocate((int)size / 4); // float array to
                normalBuffer.Put(floatArray, 0, (int)size / 4);
                normalBuffer.Flip();

                floatArray = null;
                fileIn.Close();
                m.Close();
                //----------------------------------------------------------------------------------------------------
                textureBuffer = null;
                System.GC.Collect();
                resourceId = context.Resources.GetIdentifier(fileName + "_texture", "raw", context.PackageName);
                fileIn     = context.Resources.OpenRawResource(resourceId) as Stream;
                m          = new MemoryStream();
                fileIn.CopyTo(m);
                size       = m.Length;
                floatArray = new float[size / 4];
                System.Buffer.BlockCopy(m.ToArray(), 0, floatArray, 0, (int)size);

                textureBuffer = FloatBuffer.Allocate((int)size / 4); // float array to
                textureBuffer.Put(floatArray, 0, (int)size / 4);
                textureBuffer.Flip();

                floatArray = null;
                fileIn.Close();
                m.Close();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }