예제 #1
0
        public void Render()
        {
            GLConfig glConfig = AppConfig.GetService <GLConfig>();

            GL.UniformMatrix4(glConfig.ModelUniformLoc, false, ref ModelUniform);
            for (int i = 0; i < JointTransforms.Count; i++)
            {
                GL.UniformMatrix4(glConfig.JointTransformLocs[i], false, ref JointTransforms[i].Transform);
                GL.UniformMatrix4(glConfig.JointIDefaultTransformLocs[i], false, ref JointTransforms[i].IDefaultTransform);
            }
            GL.Uniform4(glConfig.AmbientCoefficientUniformLoc, ref AmbientCoeff);
            GL.Uniform4(glConfig.DiffuseCoefficientUniformLoc, ref DiffuseCoeff);
            GL.Uniform4(glConfig.SpecularCoefficientUniformLoc, ref SpecularCoeff);
            GL.Uniform1(glConfig.ShininessCoefficientUniformLoc, ShininessCoeff);

            GL.BindVertexArray(_vertexArrID);
            GL.EnableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.Position);
            GL.EnableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.Color);
            GL.EnableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.Normal);
            GL.EnableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.JointIndex);
            GL.EnableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.JointCoeff);

            GL.DrawElements(Indexing, IndicesCount, DrawElementsType.UnsignedInt, 0);

            GL.DisableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.Position);
            GL.DisableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.Color);
            GL.DisableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.Normal);
            GL.DisableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.JointIndex);
            GL.DisableVertexArrayAttrib(_vertexArrID, (int)GLConfig.VertexAttrib.JointCoeff);
            GL.BindVertexArray(0);
        }
예제 #2
0
        public void BufferData()
        {
            GLConfig     glConfig   = AppConfig.GetService <GLConfig>();
            List <float> bufferData = new List <float>();

            foreach (VertexData vertex in Vertices)
            {
                bufferData.AddRange(vertex.GetBufferData());
            }

            GL.BindVertexArray(_vertexArrID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, _vertexBufferID);
            GL.BufferData(BufferTarget.ArrayBuffer, bufferData.Count * VertexData.FloatByteCount, bufferData.ToArray(), BufferUsageHint.DynamicDraw);

            GL.VertexAttribPointer(glConfig.PositionAttrLoc, VertexData.PositionElementCount, VertexAttribPointerType.Float, false
                                   , VertexData.VertexByteCount, VertexData.PositionOffset);
            GL.VertexAttribPointer(glConfig.ColorAttrLoc, VertexData.ColorElementCount, VertexAttribPointerType.Float, false
                                   , VertexData.VertexByteCount, VertexData.ColorOffset);
            GL.VertexAttribPointer(glConfig.NormalVecAttrLoc, VertexData.NormalVecElementCount, VertexAttribPointerType.Float, false
                                   , VertexData.VertexByteCount, VertexData.NormalVecOffset);
            GL.VertexAttribPointer(glConfig.JointIndexAttrLoc, VertexData.JointIndexElementCount, VertexAttribPointerType.Int, false
                                   , VertexData.VertexByteCount, VertexData.JointIndexOffset);
            GL.VertexAttribPointer(glConfig.JointCoeffAttrLoc, VertexData.JointCoeffElementCount, VertexAttribPointerType.Float, false
                                   , VertexData.VertexByteCount, VertexData.JointCoeffOffset);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _indexBufferID);
            GL.BufferData(BufferTarget.ElementArrayBuffer, Indices.Count * sizeof(uint), Indices.ToArray(), BufferUsageHint.DynamicDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindVertexArray(0);

            IndicesCount = Indices.Count;
            Vertices.Clear();
            Indices.Clear();
        }
예제 #3
0
        public bool Activate()
        {
            GLConfig glConfig = AppConfig.GetService <GLConfig>();

            if (!_disposed)
            {
                GL.UseProgram(_programId);
                glConfig.ModelUniformLoc      = _modelUniformLoc;
                glConfig.ViewUniformLoc       = _viewUniformLoc;
                glConfig.ProjectionUniformLoc = _projectionUniformLoc;
                for (int i = 0; i < MAX_JOINTS; i++)
                {
                    glConfig.JointTransformLocs.Add(_jointTransformLocs[i]);
                }
                for (int i = 0; i < MAX_JOINTS; i++)
                {
                    glConfig.JointIDefaultTransformLocs.Add(_jointIDefaultTransformLocs[i]);
                }
                glConfig.AmbientCoefficientUniformLoc   = _ambientCoefficientUniformLoc;
                glConfig.DiffuseCoefficientUniformLoc   = _diffuseCoefficientUniformLoc;
                glConfig.SpecularCoefficientUniformLoc  = _specularCoefficientUniformLoc;
                glConfig.ShininessCoefficientUniformLoc = _shininessCoefficientUniformLoc;
                glConfig.LightColorUniformLoc           = _lightColorUniformLoc;
                glConfig.LightDirectionUniformLoc       = _lightDirectionUniformLoc;
                glConfig.PositionAttrLoc   = _positionAttrLoc;
                glConfig.ColorAttrLoc      = _colorAttrLoc;
                glConfig.NormalVecAttrLoc  = _normalVecAttrLoc;
                glConfig.JointIndexAttrLoc = _jointIndexAttrLoc;
                glConfig.JointCoeffAttrLoc = _jointCoeffAttrLoc;
                return(true);
            }
            return(false);
        }
예제 #4
0
        protected override void OnLoad(EventArgs args)
        {
            GLConfig glConfig = AppConfig.GetService <GLConfig>();

            glConfig.Initialize();
            glConfig.UpdateViewPort(0, 0, Width - WidthOff, Height - HeightOff);
            this.Resize     += OnResize;
            this.WindowState = FormWindowState.Maximized;
            Initialize();
            base.OnLoad(args);
        }
예제 #5
0
 private void CameraAttributeEventHandler(Camera sender, CameraAttributeEventArgs args)
 {
     if (Camera == sender)
     {
         Matrix4  projection = sender.GetProjection();
         GLConfig glConfig   = AppConfig.GetService <GLConfig>();
         GL.UniformMatrix4(glConfig.ProjectionUniformLoc, false, ref projection);
     }
     else
     {
         throw new InvalidCameraAttributeEventHandlerException();
     }
 }
예제 #6
0
 private void LightTransformEventHandler(Light sender, LightEventArgs args)
 {
     if (Light == sender)
     {
         GLConfig glConfig  = AppConfig.GetService <GLConfig>();
         Vector4  color     = new Vector4(Light.Color.R, Light.Color.G, Light.Color.B, Light.Color.A);
         Vector3  direction = new Vector3(Light.Direction.XComp, Light.Direction.YComp, Light.Direction.ZComp);
         GL.Uniform4(glConfig.LightColorUniformLoc, ref color);
         GL.Uniform3(glConfig.LightDirectionUniformLoc, ref direction);
     }
     else
     {
         throw new InvalidLightEventHandlerException();
     }
 }
예제 #7
0
 private void CameraTransformEventHandler(Transformable sender, TransformEventArgs args)
 {
     if (sender is Camera)
     {
         Camera camera = sender as Camera;
         if (camera == Camera)
         {
             Matrix4  view     = camera.GetView();
             GLConfig glConfig = AppConfig.GetService <GLConfig>();
             GL.UniformMatrix4(glConfig.ViewUniformLoc, false, ref view);
         }
         else
         {
             throw new InvalidTransformEventHandlerException();
         }
     }
     else
     {
         throw new InvalidTransformEventHandlerException();
     }
 }