示例#1
0
 public void GetTextureDataCube(
     IGLTexture texture,
     SurfaceFormat format,
     int size,
     CubeMapFace cubeMapFace,
     int level,
     int subX,
     int subY,
     int subW,
     int subH,
     IntPtr data,
     int startIndex,
     int elementCount,
     int elementSizeInBytes
     )
 {
     ForceToMainThread(() =>
     {
         GLDevice.GetTextureDataCube(
             texture,
             format,
             size,
             cubeMapFace,
             level,
             subX,
             subY,
             subW,
             subH,
             data,
             startIndex,
             elementCount,
             elementSizeInBytes
             );
     });             // End ForceToMainThread
 }
示例#2
0
 public void SetTextureData2D(
     IGLTexture texture,
     SurfaceFormat format,
     int x,
     int y,
     int w,
     int h,
     int level,
     IntPtr data,
     int dataLength
     )
 {
     ForceToMainThread(() =>
     {
         GLDevice.SetTextureData2D(
             texture,
             format,
             x,
             y,
             w,
             h,
             level,
             data,
             dataLength
             );
     });             // End ForceToMainThread
 }
示例#3
0
 public void GetTextureData3D(
     IGLTexture texture,
     SurfaceFormat format,
     int left,
     int top,
     int front,
     int right,
     int bottom,
     int back,
     int level,
     IntPtr data,
     int startIndex,
     int elementCount,
     int elementSizeInBytes
     )
 {
     ForceToMainThread(() =>
     {
         GLDevice.GetTextureData3D(
             texture,
             format,
             left,
             top,
             front,
             right,
             bottom,
             back,
             level,
             data,
             startIndex,
             elementCount,
             elementSizeInBytes
             );
     });             // End ForceToMainThread
 }
示例#4
0
 public void SetTextureData3D(
     IGLTexture texture,
     SurfaceFormat format,
     int level,
     int left,
     int top,
     int right,
     int bottom,
     int front,
     int back,
     IntPtr data,
     int dataLength
     )
 {
     ForceToMainThread(() =>
     {
         GLDevice.SetTextureData3D(
             texture,
             format,
             level,
             left,
             top,
             right,
             bottom,
             front,
             back,
             data,
             dataLength
             );
     });             // End ForceToMainThread
 }
示例#5
0
 public void SetTextureDataCube(
     IGLTexture texture,
     SurfaceFormat format,
     int xOffset,
     int yOffset,
     int width,
     int height,
     CubeMapFace cubeMapFace,
     int level,
     IntPtr data,
     int dataLength
     )
 {
     ForceToMainThread(() =>
     {
         GLDevice.SetTextureDataCube(
             texture,
             format,
             xOffset,
             yOffset,
             width,
             height,
             cubeMapFace,
             level,
             data,
             dataLength
             );
     });             // End ForceToMainThread
 }
示例#6
0
 public void GetTextureData2D(
     IGLTexture texture,
     SurfaceFormat format,
     int width,
     int height,
     int level,
     int subX,
     int subY,
     int subW,
     int subH,
     IntPtr data,
     int startIndex,
     int elementCount,
     int elementSizeInBytes
     )
 {
     ForceToMainThread(() =>
     {
         GLDevice.GetTextureData2D(
             texture,
             format,
             width,
             height,
             level,
             subX,
             subY,
             subW,
             subH,
             data,
             startIndex,
             elementCount,
             elementSizeInBytes
             );
     });             // End ForceToMainThread
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="tex">Texture to use for sprite</param>
        /// <param name="maxsize">Maximum size of sprite</param>
        /// <param name="scale">Scalar for sprite vs disatance</param>
        public GLPointSpriteShader(IGLTexture tex, float maxsize = 120, float scale = 80) : base()
        {
            StartAction = (a, m) =>
            {
                tex.Bind(4);
            };

            CompileLink(vert, frag: frag, vertexconstvars: new object[] { "maxsize", maxsize, "scale", scale });
        }
示例#8
0
        public IGLTexture CreateTextureCube(
            SurfaceFormat format,
            int size,
            int levelCount
            )
        {
            IGLTexture result = null;

            ForceToMainThread(() =>
            {
                result = GLDevice.CreateTextureCube(
                    format,
                    size,
                    levelCount
                    );
            });             // End ForceToMainThread
            return(result);
        }
示例#9
0
        public IGLTexture CreateTexture2D(
            SurfaceFormat format,
            int width,
            int height,
            int levelCount
            )
        {
            IGLTexture result = null;

            ForceToMainThread(() =>
            {
                result = GLDevice.CreateTexture2D(
                    format,
                    width,
                    height,
                    levelCount
                    );
            });             // End ForceToMainThread
            return(result);
        }
示例#10
0
        public IGLRenderbuffer GenRenderbuffer(
            int width,
            int height,
            SurfaceFormat format,
            int multiSampleCount,
            IGLTexture texture
            )
        {
            IGLRenderbuffer result = null;

            ForceToMainThread(() =>
            {
                result = GLDevice.GenRenderbuffer(
                    width,
                    height,
                    format,
                    multiSampleCount,
                    texture
                    );
            });             // End ForceToMainThread
            return(result);
        }
示例#11
0
		public void SetTextureData2D(
			IGLTexture texture,
			SurfaceFormat format,
			int x,
			int y,
			int w,
			int h,
			int level,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		) {
#if !DISABLE_THREADING
			ForceToMainThread(() => {
#endif
			BindTexture(texture);

			GLenum glFormat = XNAToGL.TextureFormat[(int) format];
			if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
			{
				/* Note that we're using glInternalFormat, not glFormat.
				 * In this case, they should actually be the same thing,
				 * but we use glFormat somewhat differently for
				 * compressed textures.
				 * -flibit
				 */
				glCompressedTexSubImage2D(
					GLenum.GL_TEXTURE_2D,
					level,
					x,
					y,
					w,
					h,
					XNAToGL.TextureInternalFormat[(int) format],
					elementCount * elementSizeInBytes,
					data + (startIndex * elementSizeInBytes)
				);
			}
			else
			{
				// Set pixel alignment to match texel size in bytes
				int packSize = Texture.GetFormatSize(format);
				if (packSize != 4)
				{
					glPixelStorei(
						GLenum.GL_UNPACK_ALIGNMENT,
						packSize
					);
				}

				glTexSubImage2D(
					GLenum.GL_TEXTURE_2D,
					level,
					x,
					y,
					w,
					h,
					glFormat,
					XNAToGL.TextureDataType[(int) format],
					data + (startIndex * elementSizeInBytes)
				);

				// Keep this state sane -flibit
				if (packSize != 4)
				{
					glPixelStorei(
						GLenum.GL_UNPACK_ALIGNMENT,
						4
					);
				}
			}

#if !DISABLE_THREADING
			});
#endif
		}
示例#12
0
        public void GetTextureData3D(
			IGLTexture texture,
			SurfaceFormat format,
			int left,
			int top,
			int front,
			int right,
			int bottom,
			int back,
			int level,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		)
        {
            throw new NotImplementedException();
        }
示例#13
0
        /// <summary>
        /// Attempts to read the texture data directly from the FBO using glReadPixels
        /// </summary>
        /// <typeparam name="T">Texture data type</typeparam>
        /// <param name="texture">The texture to read from</param>
        /// <param name="width">The texture width</param>
        /// <param name="height">The texture height</param>
        /// <param name="level">The texture level</param>
        /// <param name="data">The texture data array</param>
        /// <param name="rect">The portion of the image to read from</param>
        /// <returns>True if we successfully read the texture data</returns>
        private bool ReadTargetIfApplicable(
			IGLTexture texture,
			int width,
			int height,
			int level,
			IntPtr data,
			Rectangle? rect
		)
        {
            bool texUnbound = (	currentDrawBuffers != 1 ||
                        currentAttachments[0] != (texture as OpenGLTexture).Handle	);
            if (texUnbound)
            {
                return false;
            }

            int x;
            int y;
            int w;
            int h;
            if (rect.HasValue)
            {
                x = rect.Value.X;
                y = rect.Value.Y;
                w = rect.Value.Width;
                h = rect.Value.Height;
            }
            else
            {
                x = 0;
                y = 0;
                w = width;
                h = height;
            }

            uint prevReadBuffer = currentReadFramebuffer;
            BindReadFramebuffer(targetFramebuffer);

            /* glReadPixels should be faster than reading
             * back from the render target if we are already bound.
             */
            glReadPixels(
                x,
                y,
                w,
                h,
                GLenum.GL_RGBA, // FIXME: Assumption!
                GLenum.GL_UNSIGNED_BYTE,
                data
            );

            BindReadFramebuffer(prevReadBuffer);
            return true;
        }
示例#14
0
		/// <summary>
		/// Attempts to read the texture data directly from the FBO using glReadPixels
		/// </summary>
		/// <typeparam name="T">Texture data type</typeparam>
		/// <param name="texture">The texture to read from</param>
		/// <param name="width">The texture width</param>
		/// <param name="height">The texture height</param>
		/// <param name="level">The texture level</param>
		/// <param name="data">The texture data array</param>
		/// <param name="rect">The portion of the image to read from</param>
		/// <returns>True if we successfully read the texture data</returns>
		private bool ReadTargetIfApplicable(
			IGLTexture texture,
			int width,
			int height,
			int level,
			IntPtr data,
			Rectangle? rect
		) {
			bool texUnbound = (	currentDrawBuffers != 1 ||
						currentAttachments[0] != (texture as OpenGLTexture).Handle	);
			if (texUnbound && !useES2)
			{
				return false;
			}

			int x;
			int y;
			int w;
			int h;
			if (rect.HasValue)
			{
				x = rect.Value.X;
				y = rect.Value.Y;
				w = rect.Value.Width;
				h = rect.Value.Height;
			}
			else
			{
				x = 0;
				y = 0;
				w = width;
				h = height;
			}

			uint prevReadBuffer = currentReadFramebuffer;
			uint prevWriteBuffer = currentDrawFramebuffer;
			if (texUnbound)
			{
				BindFramebuffer(resolveFramebufferRead);
				glFramebufferTexture2D(
					GLenum.GL_FRAMEBUFFER,
					GLenum.GL_COLOR_ATTACHMENT0,
					GLenum.GL_TEXTURE_2D,
					(texture as OpenGLTexture).Handle,
					level
				);
			}
			else
			{
				BindReadFramebuffer(targetFramebuffer);
			}

			/* glReadPixels should be faster than reading
			 * back from the render target if we are already bound.
			 */
			glReadPixels(
				x,
				y,
				w,
				h,
				GLenum.GL_RGBA, // FIXME: Assumption!
				GLenum.GL_UNSIGNED_BYTE,
				data
			);

			if (texUnbound)
			{
				if (prevReadBuffer == prevWriteBuffer)
				{
					BindFramebuffer(prevReadBuffer);
				}
				else
				{
					BindReadFramebuffer(prevReadBuffer);
					BindDrawFramebuffer(prevWriteBuffer);
				}
			}
			else
			{
				BindReadFramebuffer(prevReadBuffer);
			}
			return true;
		}
示例#15
0
        public void GetTextureData2D(
			IGLTexture texture,
			SurfaceFormat format,
			int width,
			int height,
			int level,
			Rectangle? rect,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		)
        {
            #if !DISABLE_THREADING
            ForceToMainThread(() => {
            #endif

            if (ReadTargetIfApplicable(
                texture,
                width,
                height,
                level,
                data,
                rect
            )) {
                return;
            }

            int x, y, w, h;
            if (rect == null)
            {
                x = 0;
                y = 0;
                w = width;
                h = height;
            }
            else
            {
                x = rect.Value.X;
                y = rect.Value.Y;
                w = rect.Value.Width;
                h = rect.Value.Height;
            }

            glGetTextureSubImage(
                (texture as OpenGLTexture).Handle,
                level,
                x,
                y,
                0,
                w,
                h,
                1,
                XNAToGL.TextureFormat[(int) format],
                XNAToGL.TextureDataType[(int) format],
                elementCount * elementSizeInBytes,
                data
            );

            #if !DISABLE_THREADING
            });
            #endif
        }
示例#16
0
		private void BindTexture(IGLTexture texture)
		{
			OpenGLTexture tex = texture as OpenGLTexture;
			if (tex.Target != Textures[0].Target)
			{
				glBindTexture(Textures[0].Target, 0);
			}
			if (tex != Textures[0])
			{
				glBindTexture(
					tex.Target,
					tex.Handle
				);
			}
			Textures[0] = tex;
		}
示例#17
0
		public void SetTextureDataCube(
			IGLTexture texture,
			SurfaceFormat format,
			int xOffset,
			int yOffset,
			int width,
			int height,
			CubeMapFace cubeMapFace,
			int level,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		) {
#if !DISABLE_THREADING
			ForceToMainThread(() => {
#endif
			BindTexture(texture);

			GLenum glFormat = XNAToGL.TextureFormat[(int) format];
			if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
			{
				/* Note that we're using glInternalFormat, not glFormat.
				 * In this case, they should actually be the same thing,
				 * but we use glFormat somewhat differently for
				 * compressed textures.
				 * -flibit
				 */
				glCompressedTexSubImage2D(
					GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
					level,
					xOffset,
					yOffset,
					width,
					height,
					XNAToGL.TextureInternalFormat[(int) format],
					elementCount * elementSizeInBytes,
					data + (startIndex * elementSizeInBytes)
				);
			}
			else
			{
				glTexSubImage2D(
					GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
					level,
					xOffset,
					yOffset,
					width,
					height,
					glFormat,
					XNAToGL.TextureDataType[(int) format],
					data + (startIndex * elementSizeInBytes)
				);
			}

#if !DISABLE_THREADING
			});
#endif
		}
示例#18
0
        public void GetTextureDataCube(
			IGLTexture texture,
			SurfaceFormat format,
			int size,
			CubeMapFace cubeMapFace,
			int level,
			Rectangle? rect,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		)
        {
            #if !DISABLE_THREADING
            ForceToMainThread(() => {
            #endif

            int x, y, w, h;
            if (rect == null)
            {
                x = 0;
                y = 0;
                w = size;
                h = size;
            }
            else
            {
                x = rect.Value.X;
                y = rect.Value.Y;
                w = rect.Value.Width;
                h = rect.Value.Height;
            }

            glGetTextureSubImage(
                (texture as OpenGLTexture).Handle,
                level,
                x,
                y,
                (int) cubeMapFace,
                w,
                h,
                1,
                XNAToGL.TextureFormat[(int) format],
                XNAToGL.TextureDataType[(int) format],
                elementCount * elementSizeInBytes,
                data
            );

            #if !DISABLE_THREADING
            });
            #endif
        }
示例#19
0
        // Add existing items. Name can be null and will get a unique name

        /// <summary> Add this type with an optional name </summary>
        public IGLTexture Add(IGLTexture disp, string name = null)
        {
            System.Diagnostics.Debug.Assert(!items.ContainsValue(disp));
            items.Add(EnsureName(name), disp);
            return(disp);
        }
        /// <summary>
        /// Create from waveform objects items to paint
        /// May use multiple creates on the same GLWaveFormObject object
        /// Ignore objects without materials or vertexes
        /// </summary>
        /// <param name="objects">List of waveform objects</param>
        /// <param name="worldpos">World position to offset objects to </param>
        /// <param name="rotationradians">Rotation to apply </param>
        /// <param name="scale">Scaling of objects</param>
        /// <returns>true if successfully created, else false if a material is not found</returns>

        public bool Create(List <GLWaveformObject> objects, Vector3 worldpos, Vector3 rotationradians, float scale = 1.0f)
        {
            if (objects == null)
            {
                return(false);
            }

            GLBuffer      vert = null;
            GLRenderState rts  = GLRenderState.Tri();
            bool          okay = false;

            foreach (var obj in objects)
            {
                if (obj.Material.HasChars() && obj.Vertices.Vertices.Count > 0)
                {
                    if (vert == null)
                    {
                        vert = items.NewBuffer();
                        vert.AllocateFill(obj.Vertices.Vertices.ToArray(), obj.Vertices.TextureVertices2.ToArray());    // store all vertices and textures into
                    }

                    bool textured = obj.Indices.TextureIndices.Count > 0;

                    string name = obj.ObjectName != null ? obj.ObjectName : obj.GroupName; // name to use for texture/colour

                    if (textured)                                                          // using textures need texture indicies
                    {
                        IGLTexture tex = items.Contains(obj.Material) ? items.Tex(obj.Material) : null;

                        if (tex == null)
                        {
                            return(false);
                        }

                        if (shadertexture == null)
                        {
                            shadertexture = new GLTexturedShaderObjectTranslation();
                            items.Add(shadertexture);
                        }

                        obj.Indices.RefactorVertexIndicesIntoTriangles();

                        var ri = GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Triangles, rts, vert, vert.Positions[0], vert.Positions[1], 0,
                                                                       new GLRenderDataTranslationRotationTexture(tex, worldpos, rotationradians, scale)); // renderable item pointing to vert for vertexes

                        ri.CreateElementIndex(items.NewBuffer(), obj.Indices.VertexIndices.ToArray(), 0);                                                  // using the refactored indexes, create an index table and use

                        rlist.Add(shadertexture, name, ri);
                        okay = true;
                    }
                    else
                    {                   // use the name as a colour.
                        Color c = Color.FromName(obj.Material);

                        if (c.A == 0 && c.R == 0 && c.G == 0 && c.B == 0)
                        {
                            if (DefaultColor != Color.Transparent)
                            {
                                c = DefaultColor;
                            }
                            else
                            {
                                return(false);
                            }
                        }

                        if (shadercolor == null)
                        {
                            shadercolor = new GLUniformColorShaderObjectTranslation();
                            items.Add(shadercolor);
                        }

                        obj.Indices.RefactorVertexIndicesIntoTriangles();

                        var ri = GLRenderableItem.CreateVector4(items, PrimitiveType.Triangles, rts, vert, 0, 0, new GLRenderDataTranslationRotationColor(c, worldpos, rotationradians, scale)); // renderable item pointing to vert for vertexes
                        ri.CreateElementIndex(items.NewBuffer(), obj.Indices.VertexIndices.ToArray(), 0);                                                                                        // using the refactored indexes, create an index table and use

                        rlist.Add(shadercolor, name, ri);
                        okay = true;
                    }
                }
            }

            return(okay);
        }
示例#21
0
        public void CreateObjects(GLItemsList items, GLRenderProgramSortedList rObjects, GalacticMapping galmap, GLStorageBlock findbufferresults, bool depthtest)
        {
            this.galmap = galmap;

            // first gets the images and make a 2d array texture for them

            Bitmap[] images = galmap.RenderableMapTypes.Select(x => x.Image as Bitmap).ToArray();
            // 256 is defined normal size
            var        objtex   = new GLTexture2DArray(images, bmpmipmaplevels: 1, wantedmipmaplevels: 3, texturesize: new Size(256, 256), internalformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, alignment: ContentAlignment.BottomCenter);
            IGLTexture texarray = items.Add(objtex, "GalObjTex");

            // now build the shaders

            const int texbindingpoint = 1;
            var       vert            = new GLPLVertexScaleLookat(rotatetoviewer: dorotate, rotateelevation: doelevation, // a look at vertex shader
                                                                  autoscale: 500, autoscalemin: 1f, autoscalemax: 20f);   // below 500, 1f, above 500, scale up to 20x
            var tcs = new GLPLTesselationControl(40f);

            tes = new GLPLTesselationEvaluateSinewave(1f, 2f);                  // this uses the world position from the vertex scaler to position the image, w controls image + animation (b16)
            var frag = new GLPLFragmentShaderTexture2DDiscard(texbindingpoint); // binding - takes image pos from tes. imagepos < 0 means discard

            objectshader = new GLShaderPipeline(vert, tcs, tes, null, frag);
            items.Add(objectshader);

            objectshader.StartAction += (s, m) =>
            {
                texarray.Bind(texbindingpoint);   // bind tex array to, matching above
            };

            // now the RenderControl for the objects

            GLRenderState rt = GLRenderState.Patches(4);

            rt.DepthTest = depthtest;

            // create a quad and all entries of the renderable map objects, zero at this point, with a zero instance count. UpdateEnables will fill it in later
            // but we need to give it the maximum buffer length at this point

            const float objsize = 10.0f;        // size of object on screen

            ridisplay = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Patches, rt,
                                                              GLShapeObjectFactory.CreateQuadTriStrip(objsize, objsize), // quad2 4 vertexts
                                                              new Vector4[galmap.RenderableMapObjects.Length],           // world positions
                                                              ic: 0, seconddivisor: 1);

            modelworldbuffer = items.LastBuffer();
            int modelpos = modelworldbuffer.Positions[0];

            worldpos = modelworldbuffer.Positions[1];

            rObjects.Add(objectshader, "galmapobj", ridisplay);

            // add a find shader to look them up

            var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);

            findshader = items.NewShaderPipeline(null, vert, tcs, tes, geofind, null, null, null);


            // hook to modelworldbuffer, at modelpos and worldpos.  UpdateEnables will fill in instance count
            rifind = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Patches, GLRenderState.Patches(4), modelworldbuffer, modelpos, ridisplay.DrawCount,
                                                           modelworldbuffer, worldpos, null, ic: 0, seconddivisor: 1);

            GLStatics.Check();

            // Text renderer for the labels

            textrenderer = new GLBitmaps("bm-galmapobjects", rObjects, new Size(128, 40), depthtest: depthtest, cullface: false, textureformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8);
            items.Add(textrenderer);

            // now make the text up for all the objects above

            using (Font fnt = new Font("Arial", 8.5F))
            {
                using (StringFormat fmt = new StringFormat())
                {
                    fmt.Alignment = StringAlignment.Center;

                    var renderablegalmapobjects = galmap.RenderableMapObjects; // list of enabled entries

                    List <Vector3> posset = new List <Vector3>();

                    float offscale = objsize * (0.5f + (float)textrenderer.BitmapSize.Height / (float)textrenderer.BitmapSize.Width / 2);       // this is the nominal centre of the text bitmap, offset in Y to the object

                    for (int i = 0; i < renderablegalmapobjects.Length; i++)
                    {
                        var   o      = renderablegalmapobjects[i];
                        float offset = -offscale;

                        for (int j = 0; j < i; j++)     // look up previous ones and see if we labeled it before
                        {
                            var d1   = new Vector3(o.points[0].X, o.points[0].Y + offset, o.points[0].Z);
                            var d2   = posset[j];   // where it was placed.
                            var diff = d1 - d2;

                            if (diff.Length < offscale) // close
                            {
                                if (offset > 0)         // if offset is positive, flip below and increase again
                                {
                                    offset = -offset - offscale;
                                }
                                else
                                {
                                    offset *= -1;       // flip over top
                                }
                                // System.Diagnostics.Debug.WriteLine($"close {renderablegalmapobjects[i].name} {d1} to {renderablegalmapobjects[j].name} {d2} {diff} select {offset}");
                            }
                        }

                        Vector3 pos = new Vector3(o.points[0].X, o.points[0].Y + offset, o.points[0].Z);
                        posset.Add(pos);
                        //System.Diagnostics.Debug.WriteLine($"{renderablegalmapobjects[i].name} at {pos} {offset}");

                        textrenderer.Add(o.id, o.name, fnt,
                                         Color.White, Color.FromArgb(0, 255, 0, 255),
                                         pos,
                                         new Vector3(objsize, 0, 0), new Vector3(0, 0, 0), textformat: fmt, rotatetoviewer: dorotate, rotateelevation: doelevation,
                                         alphafadescalar: -100, alphafadepos: 500); // fade in, alpha = 0 at >500, 1 at 400
                    }
                }
            }

            UpdateEnables();      // fill in worldpos's and update instance count, taking into
        }
示例#22
0
        public void GetTextureData3D(
			IGLTexture texture,
			SurfaceFormat format,
			int left,
			int top,
			int front,
			int right,
			int bottom,
			int back,
			int level,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		)
        {
            #if !DISABLE_THREADING
            ForceToMainThread(() => {
            #endif

            glGetTextureSubImage(
                (texture as OpenGLTexture).Handle,
                level,
                left,
                top,
                front,
                right - left,
                bottom - top,
                back - front,
                XNAToGL.TextureFormat[(int) format],
                XNAToGL.TextureDataType[(int) format],
                elementCount * elementSizeInBytes,
                data
            );

            #if !DISABLE_THREADING
            });
            #endif
        }
示例#23
0
		public void AddDisposeTexture(IGLTexture texture)
		{
			if (IsOnMainThread())
			{
				DeleteTexture(texture);
			}
			else
			{
				GCTextures.Enqueue(texture);
			}
		}
示例#24
0
 /// <summary>Constructor</summary>
 public GLRenderDataTranslationRotationTexture(IGLTexture tex, Vector3 p, float rx = 0, float ry = 0, float rz = 0, float scale = 1.0f) : base(p, rx, ry, rx, scale)
 {
     Texture = tex;
 }
示例#25
0
		public void SetTextureData3D(
			IGLTexture texture,
			SurfaceFormat format,
			int level,
			int left,
			int top,
			int right,
			int bottom,
			int front,
			int back,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		) {
#if !DISABLE_THREADING
			ForceToMainThread(() => {
#endif
			BindTexture(texture);

			glTexSubImage3D(
				GLenum.GL_TEXTURE_3D,
				level,
				left,
				top,
				front,
				right - left,
				bottom - top,
				back - front,
				XNAToGL.TextureFormat[(int) format],
				XNAToGL.TextureDataType[(int) format],
				data + (startIndex * elementSizeInBytes)
			);

#if !DISABLE_THREADING
			});
#endif
		}
示例#26
0
 /// <summary>Constructor</summary>
 public GLRenderDataTranslationRotationTexture(IGLTexture tex, Vector3 p, Vector3 rotp, float scale = 1.0f) : base(p, rotp, scale)
 {
     Texture = tex;
 }
示例#27
0
		public void GetTextureDataCube(
			IGLTexture texture,
			SurfaceFormat format,
			int size,
			CubeMapFace cubeMapFace,
			int level,
			Rectangle? rect,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		) {
#if !DISABLE_THREADING
			ForceToMainThread(() => {
#endif

			BindTexture(texture);
			GLenum glFormat = XNAToGL.TextureFormat[(int) format];
			if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
			{
				throw new NotImplementedException("GetData, CompressedTexture");
			}
			else if (rect == null)
			{
				// Just throw the whole texture into the user array.
				glGetTexImage(
					GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
					0,
					glFormat,
					XNAToGL.TextureDataType[(int) format],
					data
				);
			}
			else
			{
				// Get the whole texture...
				IntPtr texData = Marshal.AllocHGlobal(size * size * elementSizeInBytes);
				glGetTexImage(
					GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
					0,
					glFormat,
					XNAToGL.TextureDataType[(int) format],
					texData
				);

				// Now, blit the rect region into the user array.
				Rectangle region = rect.Value;
				int curPixel = -1;
				for (int row = region.Y; row < region.Y + region.Height; row += 1)
				{
					for (int col = region.X; col < region.X + region.Width; col += 1)
					{
						curPixel += 1;
						if (curPixel < startIndex)
						{
							// If we're not at the start yet, just keep going...
							continue;
						}
						if (curPixel > elementCount)
						{
							// If we're past the end, we're done!
							return;
						}
						// FIXME: Can we copy via pitch instead, or something? -flibit
						memcpy(
							data + ((curPixel - startIndex) * elementSizeInBytes),
							texData + (((row * size) + col) * elementSizeInBytes),
							(IntPtr) elementSizeInBytes
						);
					}
				}
				Marshal.FreeHGlobal(texData);
			}

#if !DISABLE_THREADING
			});
#endif
		}
示例#28
0
 /// <summary>Constructor for a single texture</summary>
 public GLRenderDataTexture(IGLTexture tex, int bind = 1) : this(new IGLTexture[] { tex }, bind)
 {
 }
示例#29
0
		private void DeleteTexture(IGLTexture texture)
		{
			uint handle = (texture as OpenGLTexture).Handle;
			for (int i = 0; i < currentAttachments.Length; i += 1)
			{
				if (handle == currentAttachments[i])
				{
					// Force an attachment update, this no longer exists!
					currentAttachments[i] = uint.MaxValue;
				}
			}
			glDeleteTextures(1, ref handle);
		}
示例#30
0
 public void AddDisposeTexture(IGLTexture texture)
 {
     GCTextures.Enqueue(texture);
 }
        // Demonstrate buffer feedback AND geo shader add vertex/dump vertex

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.ZoomDistance = 100F;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            glwfc.BackColor = Color.FromArgb(0, 0, 60);
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(120f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 20.0f);
            };

            IGLTexture array2d = items.Add(new GLTexture2DArray(new Bitmap[] { Properties.Resources.mipmap, Properties.Resources.mipmap2,
                                                                               Properties.Resources.mipmap3, Properties.Resources.mipmap4 }, SizedInternalFormat.Rgba8, 9), "2DArray2");

            if (true)
            {
                items.Add(new GLMultipleTexturedBlended(false, 2), "ShaderPos");
                items.Shader("ShaderPos").StartAction += (s, m) =>
                {
                    array2d.Bind(1);
                };

                Vector4[] instancepositions = new Vector4[4];
                instancepositions[0] = new Vector4(-25, 0, -40, 0);      // last is image index..
                instancepositions[1] = new Vector4(-25, 0, 0, 0);
                instancepositions[2] = new Vector4(-25, 0, 40, 2);
                instancepositions[3] = new Vector4(-25, 0, 80, 2);

                GLRenderState rt = GLRenderState.Tri(cullface: false);
                rObjects.Add(items.Shader("ShaderPos"),
                             GLRenderableItem.CreateVector4Vector2Vector4(items, PrimitiveType.Triangles, rt,
                                                                          GLSphereObjectFactory.CreateTexturedSphereFromTriangles(3, 20.0f),
                                                                          instancepositions, ic: 4, separbuf: true
                                                                          ));
            }

            // Shader MAT

            if (true)
            {
                IGLProgramShader smat = items.Add(new GLMultipleTexturedBlended(true, 2), "ShaderMat");
                smat.StartAction += (s, m) =>
                {
                    array2d.Bind(1);
                };

                Matrix4[] pos2 = new Matrix4[3];
                pos2[0]     = Matrix4.CreateRotationY(-80f.Radians());
                pos2[0]    *= Matrix4.CreateTranslation(new Vector3(25, 0, -40));
                pos2[0].M44 = 0;        // this is the image number

                pos2[1]     = Matrix4.CreateRotationY(-70f.Radians());
                pos2[1]    *= Matrix4.CreateTranslation(new Vector3(25, 0, 0));
                pos2[1].M44 = 2;        // this is the image number

                pos2[2]     = Matrix4.CreateRotationZ(-60f.Radians());
                pos2[2]    *= Matrix4.CreateTranslation(new Vector3(25, 0, 40));
                pos2[2].M44 = 0;        // this is the image number

                GLRenderState rq = GLRenderState.Quads(cullface: false);
                rObjects.Add(items.Shader("ShaderMat"),
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(20.0f, 20.0f, new Vector3(-90f.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                          pos2, ic: 3, separbuf: false
                                                                          ));
            }

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // def binding of 0
        }
 public ShaderV2(IGLTexture t)
 {
     CompileLink(vertex: vcode, frag: fcode, geo: "#include TestOpenTk.Volumetrics.volumetricgeo6.glsl");
     StartAction += (a, m) => { t.Bind(1); };
 }