Beispiel #1
0
        public override void DisposeTexture(ICubismTexture itexture)
        {
            var texture = (CubismOpenGlNetTexture)itexture;

            texture.Dispose();
            Textures.Remove(texture);
        }
Beispiel #2
0
        public void DisposeTexture(ICubismTexture itexture)
        {
            var texture = (CubismAvaloniaTexture)itexture;

            texture.Dispose();
            Textures.Remove(texture);
        }
        unsafe public void DrawMask(ICubismTexture itexture, float[] vertex_buffer, float[] uv_buffer, short[] index_buffer, ICubismClippingMask iclipping_mask, Matrix4 clipping_matrix, bool use_culling)
        {
            var texture       = (CubismOpenTKTexture)itexture;
            var clipping_mask = (CubismOpenTKClippingMask)iclipping_mask;

            UseCulling = use_culling;

            var shader = ShaderManager.ShaderForDrawMask();

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, texture.TextureId);
            GL.Uniform1(shader.SamplerTexture0Location, 0);

            GL.EnableVertexAttribArray((uint)shader.AttributePositionLocation);

            fixed(float *ptr = vertex_buffer)
            GL.VertexAttribPointer((uint)shader.AttributePositionLocation, 2, VertexAttribPointerType.Float, false, sizeof(float) * 2, (IntPtr)ptr);

            GL.EnableVertexAttribArray((uint)shader.AttributeTexCoordLocation);

            fixed(float *ptr = uv_buffer)
            GL.VertexAttribPointer((uint)shader.AttributeTexCoordLocation, 2, VertexAttribPointerType.Float, false, sizeof(float) * 2, (IntPtr)ptr);

            GL.Uniform4(shader.UnifromChannelFlagLocation, 1.0f, 0.0f, 0.0f, 0.0f);
            GL.UniformMatrix4(shader.UniformClipMatrixLocation, false, ref clipping_matrix);
            GL.Uniform4(shader.UniformBaseColorLocation, -1.0f, -1.0f, 1.0f, 1.0f);

            fixed(short *ptr = index_buffer)
            GL.DrawElements(PrimitiveType.Triangles, index_buffer.Length, DrawElementsType.UnsignedShort, (IntPtr)ptr);
        }
        unsafe public void DrawMesh(ICubismTexture itexture, float[] vertex_buffer, float[] uv_buffer, short[] index_buffer, ICubismClippingMask iclipping_mask, Matrix4 clipping_matrix, BlendModeType blend_mode, bool use_culling, double opacity)
        {
            var  texture           = (CubismOpenTKTexture)itexture;
            var  clipping_mask     = iclipping_mask as CubismOpenTKClippingMask;
            bool use_clipping_mask = (clipping_mask != null);

            UseCulling = use_culling;
            BlendMode  = blend_mode;

            var shader = ShaderManager.ShaderForDrawMesh(use_clipping_mask, UsePremultipliedAlpha);

            GL.UseProgram(shader.ProgramId);

            GL.EnableVertexAttribArray((uint)shader.AttributePositionLocation);

            fixed(float *ptr = vertex_buffer)
            GL.VertexAttribPointer((uint)shader.AttributePositionLocation, 2, VertexAttribPointerType.Float, false, sizeof(float) * 2, (IntPtr)ptr);

            GL.EnableVertexAttribArray((uint)shader.AttributeTexCoordLocation);

            fixed(float *ptr = uv_buffer)
            GL.VertexAttribPointer((uint)shader.AttributeTexCoordLocation, 2, VertexAttribPointerType.Float, false, sizeof(float) * 2, (IntPtr)ptr);

            if (use_clipping_mask == true)
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                GL.BindTexture(TextureTarget.Texture2D, clipping_mask.TextureId);
                GL.Uniform1(shader.SamplerTexture1Location, 1);

                GL.UniformMatrix4(shader.UniformClipMatrixLocation, false, ref clipping_matrix);

                GL.Uniform4(shader.UnifromChannelFlagLocation, 1.0f, 0.0f, 0.0f, 0.0f);
            }
            else
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                GL.BindTexture(TextureTarget.Texture2D, 0);
            }

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, texture.TextureId);
            GL.Uniform1(shader.SamplerTexture0Location, 0);

            GL.UniformMatrix4(shader.UniformMatrixLocation, false, ref MvpMatrix);

            float[] color = new float[4];
            ModelColor.CopyTo(color, 0);
            color[3] *= (float)opacity;
            if (UsePremultipliedAlpha == true)
            {
                color[0] *= color[3];
                color[1] *= color[3];
                color[2] *= color[3];
            }
            GL.Uniform4(shader.UniformBaseColorLocation, color[0], color[1], color[2], color[3]);

            fixed(short *ptr = index_buffer)
            GL.DrawElements(PrimitiveType.Triangles, index_buffer.Length, DrawElementsType.UnsignedShort, (IntPtr)ptr);
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="renderer">描画に使用するレンダラー</param>
        /// <param name="asset">描画するモデルのアセット</param>
        public CubismRenderingManager(ICubismRenderer renderer, CubismAsset asset)
        {
            Renderer = renderer;
            Asset    = asset;
            Model    = Asset.Model;

            // モデルのテクスチャをレンダラーにコピーする
            RendererTextures = new ICubismTexture[Asset.TextureByteArrays.Length];
            for (int index = 0; index < Asset.TextureByteArrays.Length; index++)
            {
                RendererTextures[index] = Renderer.CreateTexture(Asset.TextureByteArrays[index]);
            }

            // 各DrawableでどのDrawableをクリッピングマスクとして使用するか調べ、
            // もし同じDrawableの組み合わせをマスクとして用いるDrawableがあればマスクを共有するようにする
            int drawable_count = Model.DrawableCount;
            List <CubismClippingContext> all_clipping_contexts = new List <CubismClippingContext>();

            DrawableClippingContexts = new CubismClippingContext[drawable_count];
            for (int index = 0; index < drawable_count; index++)
            {
                var drawable = Model.GetDrawable(index);
                if (drawable.ClippingMaskIndexes.Length <= 0)
                {
                    DrawableClippingContexts[index] = null;
                    continue;
                }
                CubismClippingContext new_clippling_context = null;
                int[] mask_indexes = drawable.ClippingMaskIndexes.Distinct().OrderBy(x => x).ToArray();
                foreach (var target in all_clipping_contexts)
                {
                    if (mask_indexes.SequenceEqual(target.ClippingIdList) == true)
                    {
                        new_clippling_context = target;
                        break;
                    }
                }
                if (new_clippling_context == null)
                {
                    // クリッピングマスクをレンダラーに作成する
                    new_clippling_context = new CubismClippingContext(Renderer.CreateClippingMask(), mask_indexes);
                    all_clipping_contexts.Add(new_clippling_context);
                }
                new_clippling_context.ClippedDrawableIndexList.Add(index);
                DrawableClippingContexts[index] = new_clippling_context;
            }
            AllClippingContexts = all_clipping_contexts.ToArray();
        }
Beispiel #6
0
        public override void DrawMask(ICubismTexture itexture, float[] vertex_buffer, float[] uv_buffer, short[] index_buffer, ICubismClippingMask iclipping_mask, Matrix clipping_matrix, bool use_culling)
        {
            var texture       = (CubismOpenGlNetTexture)itexture;
            var clipping_mask = (CubismOpenGlNetClippingMask)iclipping_mask;

            UseCulling = use_culling;

            var shader = ShaderManager.ShaderForDrawMask();

            // Drawableのテクスチャを設定する
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(TextureTarget.Texture2d, texture.TextureId);
            Gl.Uniform1(shader.SamplerTexture0Location, 0);

            // 頂点バッファを設定する
            Gl.EnableVertexAttribArray((uint)shader.AttributePositionLocation);
            GCHandle pinned_vertex_buffer = GCHandle.Alloc(vertex_buffer, GCHandleType.Pinned);

            Gl.VertexAttribPointer((uint)shader.AttributePositionLocation, 2, VertexAttribType.Float, false, sizeof(float) * 2, pinned_vertex_buffer.AddrOfPinnedObject());

            // UVバッファを設定する
            Gl.EnableVertexAttribArray((uint)shader.AttributeTexCoordLocation);
            GCHandle pinned_uv_buffer = GCHandle.Alloc(uv_buffer, GCHandleType.Pinned);

            Gl.VertexAttribPointer((uint)shader.AttributeTexCoordLocation, 2, VertexAttribType.Float, false, sizeof(float) * 2, pinned_uv_buffer.AddrOfPinnedObject());

            // その他のパラメータを設定する
            Gl.Uniform4(shader.UnifromChannelFlagLocation, 1.0f, 0.0f, 0.0f, 0.0f);
            Gl.UniformMatrix4(shader.UniformClipMatrixLocation, false, clipping_matrix.AsColumnMajorArray());
            Gl.Uniform4(shader.UniformBaseColorLocation, -1.0f, -1.0f, 1.0f, 1.0f);

            // 描画する
            GCHandle pinned_index_buffer = GCHandle.Alloc(index_buffer, GCHandleType.Pinned);

            Gl.DrawElements(PrimitiveType.Triangles, index_buffer.Length, DrawElementsType.UnsignedShort, pinned_index_buffer.AddrOfPinnedObject());

            // バッファのアドレスの固定を解除する
            pinned_vertex_buffer.Free();
            pinned_uv_buffer.Free();
            pinned_index_buffer.Free();
        }
Beispiel #7
0
        unsafe public void DrawMask(ICubismTexture itexture, float[] vertex_buffer, float[] uv_buffer, short[] index_buffer, ICubismClippingMask iclipping_mask, Matrix4x4 clipping_matrix, bool use_culling, bool is_inverted_mask)
        {
            var texture       = (CubismAvaloniaTexture)itexture;
            var clipping_mask = (CubismAvaloniaClippingMask)iclipping_mask;

            UseCulling = use_culling;

            var shader = ShaderManager.ShaderForDrawMask();

            gl.ActiveTexture(GL_TEXTURE0);
            gl.BindTexture(GL_TEXTURE_2D, texture.TextureId);
            gl.Uniform1i(shader.SamplerTexture0Location, 0);

            gl.EnableVertexAttribArray(shader.AttributePositionLocation);
            gl.BindBuffer(GL_ARRAY_BUFFER, m_maskVertexBuf);

            fixed(float *ptr = vertex_buffer)
            gl.BufferData(GL_ARRAY_BUFFER, (IntPtr)(sizeof(float) * vertex_buffer.Length), (IntPtr)ptr, GL_STATIC_DRAW);

            gl.VertexAttribPointer(shader.AttributePositionLocation, 2, GL_FLOAT, 0, sizeof(float) * 2, IntPtr.Zero);

            gl.EnableVertexAttribArray(shader.AttributeTexCoordLocation);
            gl.BindBuffer(GL_ARRAY_BUFFER, m_maskUvBuf);

            fixed(float *ptr = uv_buffer)
            gl.BufferData(GL_ARRAY_BUFFER, (IntPtr)(sizeof(float) * uv_buffer.Length), (IntPtr)ptr, GL_STATIC_DRAW);

            gl.VertexAttribPointer(shader.AttributeTexCoordLocation, 2, GL_FLOAT, 0, 0, IntPtr.Zero);

            gl.Uniform4f(shader.UnifromChannelFlagLocation, 1.0f, 0.0f, 0.0f, 0.0f);
            Matrix4x4 *p = &clipping_matrix;

            gl.UniformMatrix4fv(shader.UniformClipMatrixLocation, 1, false, (float *)p);
            gl.Uniform4f(shader.UniformBaseColorLocation, -1.0f, -1.0f, 1.0f, 1.0f);

            fixed(short *ptr = index_buffer)
            gl.DrawElements(GL_TRIANGLES, index_buffer.Length, GL_UNSIGNED_SHORT, (IntPtr)ptr);
        }
Beispiel #8
0
        unsafe public void DrawMesh(ICubismTexture itexture, float[] vertex_buffer, float[] uv_buffer, short[] index_buffer, ICubismClippingMask iclipping_mask, Matrix4x4 clipping_matrix, BlendModeType blend_mode, bool use_culling, bool is_inverted_mask, double opacity)
        {
            var  texture           = (CubismAvaloniaTexture)itexture;
            var  clipping_mask     = iclipping_mask as CubismAvaloniaClippingMask;
            bool use_clipping_mask = (clipping_mask != null);

            UseCulling = use_culling;
            BlendMode  = blend_mode;

            var shader = ShaderManager.ShaderForDrawMesh(use_clipping_mask, UsePremultipliedAlpha);

            gl.UseProgram(shader.ProgramId);

            gl.EnableVertexAttribArray(shader.AttributePositionLocation);
            gl.BindBuffer(GL_ARRAY_BUFFER, m_meshVertexBuf);

            fixed(float *ptr = vertex_buffer)
            gl.BufferData(GL_ARRAY_BUFFER, (IntPtr)(sizeof(float) * vertex_buffer.Length), (IntPtr)ptr, GL_STATIC_DRAW);

            gl.VertexAttribPointer(shader.AttributePositionLocation, 2, GL_FLOAT, 0, sizeof(float) * 2, IntPtr.Zero);

            gl.EnableVertexAttribArray(shader.AttributeTexCoordLocation);
            gl.BindBuffer(GL_ARRAY_BUFFER, m_meshUvBuf);

            fixed(float *ptr = uv_buffer)
            gl.BufferData(GL_ARRAY_BUFFER, (IntPtr)(sizeof(float) * uv_buffer.Length), (IntPtr)ptr, GL_STATIC_DRAW);

            gl.VertexAttribPointer(shader.AttributeTexCoordLocation, 2, GL_FLOAT, 0, 0, IntPtr.Zero);


            if (use_clipping_mask == true)
            {
                gl.ActiveTexture(GL_TEXTURE1);
                gl.BindTexture(GL_TEXTURE_2D, clipping_mask.TextureId);
                gl.Uniform1i(shader.SamplerTexture1Location, 1);

                Matrix4x4 *p = &clipping_matrix;
                gl.UniformMatrix4fv(shader.UniformClipMatrixLocation, 1, false, (float *)p);

                gl.Uniform4f(shader.UnifromChannelFlagLocation, 1.0f, 0.0f, 0.0f, 0.0f);
            }
            else
            {
                gl.ActiveTexture(GL_TEXTURE1);
                gl.BindTexture(GL_TEXTURE_2D, 0);
            }

            gl.ActiveTexture(GL_TEXTURE0);
            gl.BindTexture(GL_TEXTURE_2D, texture.TextureId);
            gl.Uniform1i(shader.SamplerTexture0Location, 0);

            fixed(Matrix4x4 *pmvp = &MvpMatrix)
            {
                gl.UniformMatrix4fv(shader.UniformMatrixLocation, 1, false, (float *)pmvp);
            }

            float[] color = new float[4];
            ModelColor.CopyTo(color, 0);
            color[3] *= (float)opacity;
            if (UsePremultipliedAlpha == true)
            {
                color[0] *= color[3];
                color[1] *= color[3];
                color[2] *= color[3];
            }
            gl.Uniform4f(shader.UniformBaseColorLocation, color[0], color[1], color[2], color[3]);

            fixed(short *ptr = index_buffer)
            gl.DrawElements(GL_TRIANGLES, index_buffer.Length, GL_UNSIGNED_SHORT, (IntPtr)ptr);
        }
Beispiel #9
0
        public override void DrawMesh(ICubismTexture itexture, float[] vertex_buffer, float[] uv_buffer, short[] index_buffer, ICubismClippingMask iclipping_mask, Matrix clipping_matrix, BlendModeType blend_mode, bool use_culling, double opacity)
        {
            var  texture           = (CubismOpenGlNetTexture)itexture;
            var  clipping_mask     = iclipping_mask as CubismOpenGlNetClippingMask;
            bool use_clipping_mask = (clipping_mask != null);

            UseCulling = use_culling;
            BlendMode  = blend_mode;

            var shader = ShaderManager.ShaderForDrawMesh(use_clipping_mask, UsePremultipliedAlpha);

            Gl.UseProgram(shader.ProgramId);

            // 頂点バッファを設定する
            Gl.EnableVertexAttribArray((uint)shader.AttributePositionLocation);
            GCHandle pinned_vertex_buffer = GCHandle.Alloc(vertex_buffer, GCHandleType.Pinned);

            Gl.VertexAttribPointer((uint)shader.AttributePositionLocation, 2, VertexAttribType.Float, false, sizeof(float) * 2, pinned_vertex_buffer.AddrOfPinnedObject());

            // UVバッファを設定する
            Gl.EnableVertexAttribArray((uint)shader.AttributeTexCoordLocation);
            GCHandle pinned_uv_buffer = GCHandle.Alloc(uv_buffer, GCHandleType.Pinned);

            Gl.VertexAttribPointer((uint)shader.AttributeTexCoordLocation, 2, VertexAttribType.Float, false, sizeof(float) * 2, pinned_uv_buffer.AddrOfPinnedObject());

            if (use_clipping_mask == true)
            {
                Gl.ActiveTexture(TextureUnit.Texture1);
                Gl.BindTexture(TextureTarget.Texture2d, clipping_mask.TextureId);
                Gl.Uniform1(shader.SamplerTexture1Location, 1);

                // View座標をClippingContextの座標に変換するための行列を設定
                Gl.UniformMatrix4(shader.UniformClipMatrixLocation, false, clipping_matrix.AsColumnMajorArray());

                // 使用するカラーチャンネルを設定
                Gl.Uniform4(shader.UnifromChannelFlagLocation, 1.0f, 0.0f, 0.0f, 0.0f);
            }
            else
            {
                Gl.ActiveTexture(TextureUnit.Texture1);
                Gl.BindTexture(TextureTarget.Texture2d, 0);
            }

            //テクスチャ設定
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(TextureTarget.Texture2d, texture.TextureId);
            Gl.Uniform1(shader.SamplerTexture0Location, 0);

            // 座標変換
            Gl.UniformMatrix4(shader.UniformMatrixLocation, false, MvpMatrix.AsColumnMajorArray());

            // モデルの色を設定する
            float[] color = new float[4];
            ModelColor.CopyTo(color, 0);
            color[3] *= (float)opacity;
            if (UsePremultipliedAlpha == true)
            {
                color[0] *= color[3];
                color[1] *= color[3];
                color[2] *= color[3];
            }
            Gl.Uniform4(shader.UniformBaseColorLocation, color[0], color[1], color[2], color[3]);

            // 描画する
            GCHandle pinned_index_buffer = GCHandle.Alloc(index_buffer, GCHandleType.Pinned);

            Gl.DrawElements(PrimitiveType.Triangles, index_buffer.Length, DrawElementsType.UnsignedShort, pinned_index_buffer.AddrOfPinnedObject());

            // バッファのアドレスの固定を解除する
            pinned_vertex_buffer.Free();
            pinned_uv_buffer.Free();
            pinned_index_buffer.Free();
        }
Beispiel #10
0
 /// <summary>
 /// クリッピングマスクを描画する。
 /// 描画パラメータはフィールド値で事前に設定しておく。
 /// </summary>
 /// <param name="texture">テクスチャ</param>
 /// <param name="vertex_buffer">頂点バッファ</param>
 /// <param name="uv_buffer">UVバッファ</param>
 /// <param name="index_buffer">インデックスバッファ</param>
 /// <param name="clipping_mask">描画先のクリッピングマスク</param>
 /// <param name="clipping_matrix">クリッピングマスクの座標系へ座標変換するための行列</param>
 public abstract void DrawMask(ICubismTexture texture, float[] vertex_buffer, float[] uv_buffer, short[] index_buffer, ICubismClippingMask clipping_mask, Matrix clipping_matrix, bool use_culling);
Beispiel #11
0
 /// <summary>
 /// テクスチャを破棄する。
 /// </summary>
 /// <param name="texture">破棄するテクスチャ</param>
 public abstract void DisposeTexture(ICubismTexture texture);
Beispiel #12
0
 /// <summary>
 /// メッシュを描画する。
 /// 描画パラメータはフィールド値で事前に設定しておく。
 /// </summary>
 /// <param name="vertex_buffer">頂点バッファ</param>
 /// <param name="uv_buffer">UVバッファ</param>
 /// <param name="index_buffer">インデックスバッファ</param>
 /// <param name="texture">テクスチャ</param>
 /// <param name="clipping_mask">描画に使用するクリッピングマスク。マスクが使用されないときはnullが渡される。</param>
 /// <param name="clipping_matrix">クリッピングマスクの座標系へ座標変換するための行列</param>
 public abstract void DrawMesh(ICubismTexture texture, float[] vertex_buffer, float[] uv_buffer, short[] index_buffer, ICubismClippingMask clipping_mask, Matrix clipping_matrix, BlendModeType blend_mode, bool use_culling, double opacity);