public void DisposeClippingMask(ICubismClippingMask iclipping_mask) { var clipping_mask = (CubismAvaloniaClippingMask)iclipping_mask; clipping_mask.Dispose(); ClippingMasks.Remove(clipping_mask); }
public override void DisposeClippingMask(ICubismClippingMask iclipping_mask) { var clipping_mask = (CubismOpenGlNetClippingMask)iclipping_mask; clipping_mask.Dispose(); ClippingMasks.Remove(clipping_mask); }
public void StartDrawingMask(ICubismClippingMask iclipping_mask) { var clipping_mask = (CubismAvaloniaClippingMask)iclipping_mask; gl.Viewport(0, 0, clipping_mask.Width, clipping_mask.Height); gl.BindFramebuffer(GL_FRAMEBUFFER, clipping_mask.FrameBufferId); gl.ClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.Clear(GL_COLOR_BUFFER_BIT); var shader = ShaderManager.ShaderForDrawMask(); gl.UseProgram(shader.ProgramId); gl.BlendFuncSeparate(/*BlendingFactorSrc.Zero*/ 0, GL_ONE_MINUS_SRC_COLOR, /*BlendingFactorSrc.Zero*/ 0, GL_ONE_MINUS_SRC_ALPHA); }
public void StartDrawingMask(ICubismClippingMask iclipping_mask) { var clipping_mask = (CubismOpenTKClippingMask)iclipping_mask; GL.Viewport(0, 0, clipping_mask.Width, clipping_mask.Height); GL.BindFramebuffer(FramebufferTarget.Framebuffer, clipping_mask.FrameBufferId); GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f); GL.Clear(ClearBufferMask.ColorBufferBit); var shader = ShaderManager.ShaderForDrawMask(); GL.UseProgram(shader.ProgramId); GL.BlendFuncSeparate(BlendingFactorSrc.Zero, BlendingFactorDest.OneMinusSrcColor, BlendingFactorSrc.Zero, BlendingFactorDest.OneMinusSrcAlpha); }
/// <summary> /// レンダラーでモデルを描画する。 /// </summary> public void Draw(Matrix4x4 mvp_matrix) { try { // 描画を開始する Renderer.StartDrawingModel(Asset.ModelColor, mvp_matrix); // クリッピングマスクを描画する SetupClippingMasks(); // Drawableの描画順を取得し、描画する順番にインデックスを並べ替えたリストを作成する int drawable_count = Model.DrawableCount; var drawable_render_order = Model.GetDrawableRenderOrders(); int[] reordered_drawable_indexes = new int[drawable_count]; for (int index = 0; index < drawable_count; index++) { reordered_drawable_indexes[drawable_render_order[index]] = index; } // 指定された順番通りにDrawableを描画していく foreach (int drawable_index in reordered_drawable_indexes) { var drawable = Model.GetDrawable(drawable_index); if (drawable.Visible == false) { // Drawableは非表示なので描画しない continue; } // メッシュを描画する var texture = RendererTextures[drawable.TextureIndex]; float[] vertex_buffer = drawable.VertexBuffer; float[] uv_buffer = drawable.UvBuffer; short[] index_buffer = drawable.IndexBuffer; CubismClippingContext clipping_context = DrawableClippingContexts[drawable_index]; ICubismClippingMask clipping_mask = (clipping_context != null) ? clipping_context.Target : null; Matrix4x4 clipping_matrix = (clipping_context != null) ? clipping_context.MatrixForDraw : Matrix4x4.Identity; Renderer.DrawMesh(texture, vertex_buffer, uv_buffer, index_buffer, clipping_mask, clipping_matrix, drawable.BlendMode, drawable.UseCulling, drawable.IsInvertedMask, drawable.Opacity); } } finally { Renderer.EndDrawingModel(); } }
public override void StartDrawingMask(ICubismClippingMask iclipping_mask) { // クリッピングマスクをレンダリング先に設定し、ビューポートを全体にする var clipping_mask = (CubismOpenGlNetClippingMask)iclipping_mask; Gl.Viewport(0, 0, clipping_mask.Width, clipping_mask.Height); Gl.BindFramebuffer(FramebufferTarget.Framebuffer, clipping_mask.FrameBufferId); // フレームバッファをクリアする Gl.ClearColor(1.0f, 1.0f, 1.0f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit); // マスクの描画用のシェーダーを設定する var shader = ShaderManager.ShaderForDrawMask(); Gl.UseProgram(shader.ProgramId); // ブレンドモードを設定する Gl.BlendFuncSeparate(BlendingFactor.Zero, BlendingFactor.OneMinusSrcColor, BlendingFactor.Zero, BlendingFactor.OneMinusSrcAlpha); }
public override void EndDrawingMask(ICubismClippingMask iclipping_mask) { // レンダリング先とビューポートをオリジナルのものに戻す State.RestoreFrameBuffer(); State.RestoreViewport(); }
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); }
public void EndDrawingMask(ICubismClippingMask iclipping_mask) { State.RestoreFrameBuffer(); State.RestoreViewport(); }
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); }
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="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);
public CubismClippingContext(ICubismClippingMask target, int[] clipping_drawable_indices) { Target = target; ClippingIdList = clipping_drawable_indices; }
/// <summary> /// クリッピングマスクを破棄する。 /// </summary> /// <param name="clipping_mask">破棄するクリッピングマスク</param> public abstract void DisposeClippingMask(ICubismClippingMask clipping_mask);
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(); }
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); }
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(); }
/// <summary> /// クリッピングマスクの描画が終了した際に呼ばれる。 /// </summary> public virtual void EndDrawingMask(ICubismClippingMask clipping_mask) { }
/// <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);