Пример #1
0
        public unsafe void Submit(byte viewId, Program program, Matrix4x4 *transform, RenderStateGroup renderStateGroup, IUniformGroup uniforms, Texture texture, Uniform textureSampler)
        {
            foreach (var group in groups)
            {
                if (uniforms != null)
                {
                    uniforms.SubmitPerDrawUniforms();
                }

                if (texture != null)
                {
                    Bgfx.SetTexture(0, textureSampler, texture);
                }

                Bgfx.SetTransform((float *)transform);
                Bgfx.SetIndexBuffer(group.IndexBuffer);
                Bgfx.SetVertexBuffer(0, group.VertexBuffer);
                Bgfx.SetRenderState(renderStateGroup.State, (int)renderStateGroup.BlendFactorRgba);
                Bgfx.SetStencil(renderStateGroup.FrontFace, renderStateGroup.BackFace);
                Bgfx.Submit(viewId, program);
            }
        }
Пример #2
0
        public static Matrix4x4 *RotationEulerInverse(Vector3 rotation, Matrix4x4 *result)
        {
            float sinX = MathF.Sin(rotation.X), sinY = MathF.Sin(rotation.Y), sinZ = MathF.Sin(rotation.Z);
            float cosX = MathF.Cos(rotation.X), cosY = MathF.Cos(rotation.Y), cosZ = MathF.Cos(rotation.Z);
            float sinXsinY = sinX * sinY;
            float cosXcosZ = cosX * cosZ;
            float cosXsinZ = cosX * sinZ;

            //!xelpmoc yllaer s'tI
            result->M11 = cosZ * cosY;
            result->M21 = sinZ * cosY;
            result->M31 = -sinY;
            result->M12 = -cosXsinZ + cosZ * sinXsinY;
            result->M22 = cosXcosZ + sinZ * sinXsinY;
            result->M32 = cosY * sinX;
            result->M13 = cosXcosZ * sinY + sinX * sinZ;
            result->M23 = -cosZ * sinX + cosXsinZ * sinY;
            result->M33 = cosY * cosX;
            result->M14 = 0; result->M24 = 0; result->M34 = 0;
            result->M41 = 0; result->M42 = 0; result->M43 = 0; result->M44 = 1;
            return(result);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// <paramref name="result"/> must differ from <paramref name="transform"/> and <paramref name="matrix"/>, otherwise invoke <see cref="Mul(Matrix4x4*, Matrix4x4*)"/> instead
        /// </summary>
        public static Matrix4x4 *Mul(Matrix4x4 *transform, Matrix4x4 *matrix, Matrix4x4 *result)
        {
            result->M11 = transform->M11 * matrix->M11 + transform->M21 * matrix->M12 + transform->M31 * matrix->M13 + transform->M41 * matrix->M14;
            result->M12 = transform->M12 * matrix->M11 + transform->M22 * matrix->M12 + transform->M32 * matrix->M13 + transform->M42 * matrix->M14;
            result->M13 = transform->M13 * matrix->M11 + transform->M23 * matrix->M12 + transform->M33 * matrix->M13 + transform->M43 * matrix->M14;
            result->M14 = transform->M14 * matrix->M11 + transform->M24 * matrix->M12 + transform->M34 * matrix->M13 + transform->M44 * matrix->M14;

            result->M21 = transform->M11 * matrix->M21 + transform->M21 * matrix->M22 + transform->M31 * matrix->M23 + transform->M41 * matrix->M24;
            result->M22 = transform->M12 * matrix->M21 + transform->M22 * matrix->M22 + transform->M32 * matrix->M23 + transform->M42 * matrix->M24;
            result->M23 = transform->M13 * matrix->M21 + transform->M23 * matrix->M22 + transform->M33 * matrix->M23 + transform->M43 * matrix->M24;
            result->M24 = transform->M14 * matrix->M21 + transform->M24 * matrix->M22 + transform->M34 * matrix->M23 + transform->M44 * matrix->M24;

            result->M31 = transform->M11 * matrix->M31 + transform->M21 * matrix->M32 + transform->M31 * matrix->M33 + transform->M41 * matrix->M34;
            result->M32 = transform->M12 * matrix->M31 + transform->M22 * matrix->M32 + transform->M32 * matrix->M33 + transform->M42 * matrix->M34;
            result->M33 = transform->M13 * matrix->M31 + transform->M23 * matrix->M32 + transform->M33 * matrix->M33 + transform->M43 * matrix->M34;
            result->M34 = transform->M14 * matrix->M31 + transform->M24 * matrix->M32 + transform->M34 * matrix->M33 + transform->M44 * matrix->M34;

            result->M41 = transform->M11 * matrix->M41 + transform->M21 * matrix->M42 + transform->M31 * matrix->M43 + transform->M41 * matrix->M44;
            result->M42 = transform->M12 * matrix->M41 + transform->M22 * matrix->M42 + transform->M32 * matrix->M43 + transform->M42 * matrix->M44;
            result->M43 = transform->M13 * matrix->M41 + transform->M23 * matrix->M42 + transform->M33 * matrix->M43 + transform->M43 * matrix->M44;
            result->M44 = transform->M14 * matrix->M41 + transform->M24 * matrix->M42 + transform->M34 * matrix->M43 + transform->M44 * matrix->M44;
            return(result);
        }
Пример #5
0
 public unsafe void Submit(byte viewId, Program program, Matrix4x4 *transform, RenderStateGroup renderStateGroup, IUniformGroup uniforms)
 {
     Submit(viewId, program, transform, renderStateGroup, uniforms, null, default(Uniform));
 }
Пример #6
0
 public unsafe void SetPropertyMatrix4(string name, bool transpose, Matrix4x4 *value)
 {
     OGL.UniformMatrix4(GetLocation(name), 1, transpose, value->M11);
 }
Пример #7
0
 static Transform()
 {
     TRANSLATION_MATRIX_TEMP = AllocPermanant <Matrix4x4>(3);
     ROTATION_MATRIX_TEMP    = TRANSLATION_MATRIX_TEMP + 1;
     SCALE_MATRIX_TEMP       = ROTATION_MATRIX_TEMP + 1;
 }
Пример #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);
        }
Пример #9
0
 public static Matrix4x4 *Divide(Matrix4x4 *matrix, float scalar, Matrix4x4 *result)
 {
     return(Mul(matrix, 1f / scalar, result));
 }
Пример #10
0
 public static Vector4 *Mul(Matrix4x4 *transform, Vector4 *vector)
 {
     *VECTOR4_TEMP = *vector;
     Mul(transform, VECTOR4_TEMP, vector);
     return(vector);
 }
Пример #11
0
 public static Matrix4x4 *Mul(Matrix4x4 *transform, Matrix4x4 *matrix)
 {
     *MATRIX_TEMP = *matrix;
     Mul(transform, MATRIX_TEMP, matrix);
     return(matrix);
 }
Пример #12
0
        /// <summary>
        /// Positive X oriented, Y is <paramref name="width"/>,Z is <paramref name="height"/>
        /// </summary>
        public static Matrix4x4 *Orthographic(float width, float height, float near, float far, Matrix4x4 *result)
        {
            float scaleX = 2f / (far - near);

            result->M11 = scaleX; result->M21 = 0; result->M31 = 0; result->M41 = -(near + far) * .5f * scaleX;
            result->M12 = 0; result->M22 = 2f / width; result->M32 = 0; result->M42 = 0;
            result->M13 = 0; result->M23 = 0; result->M33 = 2f / height; result->M43 = 0;
            result->M14 = 0; result->M24 = 0; result->M34 = 0; result->M44 = 1;
            return(result);
        }
Пример #13
0
 public static Matrix4x4 *Scale(Vector3 scale, Matrix4x4 *result)
 {
     return(Scale(scale.X, scale.Y, scale.Z, result));
 }
Пример #14
0
 static Matrix4x4()
 {
     MATRIX_TEMP     = AllocPermanant <Matrix4x4>(2);
     VECTOR4_TEMP    = AllocPermanant <Vector4>();
     ARITHMETIC_TEMP = MATRIX_TEMP + 1;
 }