public override void MakeTexture() { if (PrepDevice != null) { try { texture2d = PrepDevice.createTexture(); PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE); if (GetHipsFileExtention() == ".fits" && RenderContext.UseGlVersion2) { PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.R32F, (int)fitsImage.SizeX, (int)fitsImage.SizeY, 0, GL.RED, GL.FLOAT, fitsImage.dataUnit); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST); } else { ImageElement image = texture; PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, image); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_NEAREST); PrepDevice.generateMipmap(GL.TEXTURE_2D); } PrepDevice.bindTexture(GL.TEXTURE_2D, null); } catch { errored = true; } } }
public override bool CreateGeometry(RenderContext renderContext) { base.CreateGeometry(renderContext); if (GeometryCreated) { return(true); } if (dataset.WcsImage is FitsImage && RenderContext.UseGlVersion2) { FitsImage fitsImage = dataset.WcsImage as FitsImage; texture2d = PrepDevice.createTexture(); PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE); PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.R32F, (int)fitsImage.SizeX, (int)fitsImage.SizeY, 0, GL.RED, GL.FLOAT, fitsImage.dataUnit); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST); PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST); Width = fitsImage.SizeX; Height = fitsImage.SizeY; } else { WcsImage wcsImage = dataset.WcsImage as WcsImage; if (wcsImage != null) { Bitmap bmp = wcsImage.GetBitmap(); texture2d = bmp.GetTexture(); if (bmp.Height != wcsImage.SizeY) { PixelCenterY += bmp.Height - wcsImage.SizeY; } if (renderContext.gl != null) { Height = bmp.Height; Width = bmp.Width; } } else { Height = texture.NaturalHeight; Width = texture.NaturalWidth; } } GeometryCreated = true; for (int i = 0; i < 4; i++) { RenderTriangleLists[i] = new List <RenderTriangle>(); } ComputeMatrix(); double latMin = 0 + (ScaleY * (Height - PixelCenterY)); double latMax = 0 - (ScaleY * PixelCenterY); double lngMin = 0 + (ScaleX * PixelCenterX); double lngMax = 0 - (ScaleX * (Width - PixelCenterX)); TopLeft = GeoTo3dTan(latMin, lngMin); BottomRight = GeoTo3dTan(latMax, lngMax); TopRight = GeoTo3dTan(latMin, lngMax); BottomLeft = GeoTo3dTan(latMax, lngMin); Vector3d topCenter = Vector3d.Lerp(TopLeft, TopRight, .5f); Vector3d bottomCenter = Vector3d.Lerp(BottomLeft, BottomRight, .5f); Vector3d center = Vector3d.Lerp(topCenter, bottomCenter, .5f); Vector3d rightCenter = Vector3d.Lerp(TopRight, BottomRight, .5f); Vector3d leftCenter = Vector3d.Lerp(TopLeft, BottomLeft, .5f); if (renderContext.gl == null) { vertexList = new List <PositionTexture>(); vertexList.Add(PositionTexture.CreatePosSize(TopLeft, 0, 0, Width, Height)); vertexList.Add(PositionTexture.CreatePosSize(TopRight, 1, 0, Width, Height)); vertexList.Add(PositionTexture.CreatePosSize(BottomLeft, 0, 1, Width, Height)); vertexList.Add(PositionTexture.CreatePosSize(BottomRight, 1, 1, Width, Height)); childTriangleList = new List <Triangle>(); if (dataset.BottomsUp) { childTriangleList.Add(Triangle.Create(0, 1, 2)); childTriangleList.Add(Triangle.Create(2, 1, 3)); } else { childTriangleList.Add(Triangle.Create(0, 2, 1)); childTriangleList.Add(Triangle.Create(2, 3, 1)); } int count = 3; while (count-- > 1) { List <Triangle> newList = new List <Triangle>(); foreach (Triangle tri in childTriangleList) { tri.SubDivide(newList, vertexList); } childTriangleList = newList; } double miter = .6 / (Width / 256); foreach (Triangle tri in childTriangleList) { PositionTexture p1 = vertexList[tri.A]; PositionTexture p2 = vertexList[tri.B]; PositionTexture p3 = vertexList[tri.C]; RenderTriangleLists[0].Add(RenderTriangle.CreateWithMiter(p1, p2, p3, texture, Level, miter)); } } else { //process vertex list VertexBuffer = PrepDevice.createBuffer(); PrepDevice.bindBuffer(GL.ARRAY_BUFFER, VertexBuffer); Float32Array f32array = new Float32Array(9 * 5); float[] buffer = (float[])(object)f32array; int index = 0; index = AddVertex(buffer, index, PositionTexture.CreatePos(bottomCenter, .5, 1)); //0 index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomLeft, 0, 1)); //1 index = AddVertex(buffer, index, PositionTexture.CreatePos(BottomRight, 1, 1)); //2 index = AddVertex(buffer, index, PositionTexture.CreatePos(center, .5, .5)); //3 index = AddVertex(buffer, index, PositionTexture.CreatePos(leftCenter, 0, .5)); //4 index = AddVertex(buffer, index, PositionTexture.CreatePos(rightCenter, 1, .5)); //5 index = AddVertex(buffer, index, PositionTexture.CreatePos(topCenter, .5, 0)); //6 index = AddVertex(buffer, index, PositionTexture.CreatePos(TopLeft, 0, 0)); //7 index = AddVertex(buffer, index, PositionTexture.CreatePos(TopRight, 1, 0)); //8 PrepDevice.bufferData(GL.ARRAY_BUFFER, f32array, GL.STATIC_DRAW); // process index buffers for (int i = 0; i < 4; i++) { index = 0; TriangleCount = 2; Uint16Array ui16array = new Uint16Array(TriangleCount * 3); UInt16[] indexArray = (UInt16[])(object)ui16array; switch (i) { case 0: indexArray[index++] = 7; indexArray[index++] = 4; indexArray[index++] = 6; indexArray[index++] = 4; indexArray[index++] = 3; indexArray[index++] = 6; break; case 1: indexArray[index++] = 6; indexArray[index++] = 5; indexArray[index++] = 8; indexArray[index++] = 6; indexArray[index++] = 3; indexArray[index++] = 5; break; case 2: indexArray[index++] = 4; indexArray[index++] = 0; indexArray[index++] = 3; indexArray[index++] = 4; indexArray[index++] = 1; indexArray[index++] = 0; break; case 3: indexArray[index++] = 3; indexArray[index++] = 2; indexArray[index++] = 5; indexArray[index++] = 3; indexArray[index++] = 0; indexArray[index++] = 2; break; } IndexBuffers[i] = PrepDevice.createBuffer(); PrepDevice.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, IndexBuffers[i]); PrepDevice.bufferData(GL.ELEMENT_ARRAY_BUFFER, ui16array, GL.STATIC_DRAW); } } return(true); }