当前位置: 首页>>代码示例>>Java>>正文


Java MemoryStack类代码示例

本文整理汇总了Java中org.lwjgl.system.MemoryStack的典型用法代码示例。如果您正苦于以下问题:Java MemoryStack类的具体用法?Java MemoryStack怎么用?Java MemoryStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MemoryStack类属于org.lwjgl.system包,在下文中一共展示了MemoryStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadTexture

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
/**
 * Loads a texture from a file at the specified path.
 *
 * @param path - File path of the texture file.
 *
 * @return A Texture built from the specified file.
 */
public static Texture loadTexture(String path) {
    ByteBuffer image;
    int width;
    int height;

    try (MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer w = stack.mallocInt(1);
        IntBuffer h = stack.mallocInt(1);
        IntBuffer comp = stack.mallocInt(1);

        // Load image using the STB library
        stbi_set_flip_vertically_on_load(false);
        image = stbi_load(path, w, h, comp, 4);

        if (image == null) {
            throw new RuntimeException("Failed to load a texture file! " +
                    stbi_failure_reason());
        }

        width = w.get();
        height = h.get();
    }

    return createTexture(width, height, image);
}
 
开发者ID:brokenprogrammer,项目名称:Mass,代码行数:33,代码来源:Texture.java

示例2: updateViewPort

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
private void updateViewPort(ViewPort viewport)
{
	if (viewport == this.defaultViewPort)
	{
		//FIXME: This is a fix (hack?) for Mac's weird hack to scale windows for compatibility
		try (MemoryStack stack = MemoryStack.stackPush())
		{
			IntBuffer pWidth = stack.mallocInt(1);
			IntBuffer pHeight = stack.mallocInt(1);

			GLFW.glfwGetFramebufferSize(this.window.handle(), pWidth, pHeight);
			GL11.glViewport(0, 0, pWidth.get(0), pHeight.get(0));
		}
	}
	else
	{
		GL11.glViewport(viewport.getX(), viewport.getY(),
				viewport.getWidth(), viewport.getHeight());
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:21,代码来源:View.java

示例3: makeWindowCentered

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
public void makeWindowCentered()
{
	// Get the thread stack and push a new frame
	try (MemoryStack stack = MemoryStack.stackPush())
	{
		IntBuffer pWidth = stack.mallocInt(1); // int*
		IntBuffer pHeight = stack.mallocInt(1); // int*

		// Get the window size passed to glfwCreateWindow
		GLFW.glfwGetWindowSize(this.handle, pWidth, pHeight);

		this.width = pWidth.get(0);
		this.height = pHeight.get(0);

		// Get the resolution of the primary monitor
		GLFWVidMode vidmode = getCurrentVideoMode();

		// Center the window
		GLFW.glfwSetWindowPos(
				this.handle,
				this.x = ((vidmode.width() - this.width) / 2),
				this.y = ((vidmode.height() - this.height) / 2)
		);
	} // the stack frame is popped automatically
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:26,代码来源:Window.java

示例4: readVorbis

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
private ShortBuffer readVorbis(String resource, int bufferSize, STBVorbisInfo info) throws Exception {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        vorbis = Utils.ioResourceToByteBuffer(resource, bufferSize);
        IntBuffer error = stack.mallocInt(1);
        long decoder = stb_vorbis_open_memory(vorbis, error, null);
        if (decoder == NULL) {
            throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
        }

        stb_vorbis_get_info(decoder, info);

        int channels = info.channels();

        int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);

        pcm = MemoryUtil.memAllocShort(lengthSamples);

        pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels);
        stb_vorbis_close(decoder);

        return pcm;
    }
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:24,代码来源:SoundBuffer.java

示例5: Texture

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
public Texture(ByteBuffer image) {
	try (MemoryStack stack = MemoryStack.stackPush()) {
		IntBuffer w = stack.mallocInt(1);
           IntBuffer h = stack.mallocInt(1);
           IntBuffer avChannels = stack.mallocInt(1);

           ByteBuffer decodedImage = stbi_load_from_memory(image, w, h, avChannels, 4);

           this.width = w.get();
           this.height = h.get();

           this.id = glGenTextures();
           Loader.textures.add(id);
           glBindTexture(GL_TEXTURE_2D, this.id);

           glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

           glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
           glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
           glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, decodedImage);
           glGenerateMipmap(GL_TEXTURE_2D);
	}
}
 
开发者ID:nickclark2016,项目名称:JavaGraphicsEngine,代码行数:24,代码来源:Texture.java

示例6: create

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
public long create(GLCanvas canvas, GLData attribs, GLData effective) {
    Canvas dummycanvas = new Canvas(canvas.getParent(), checkStyle(canvas.getParent(), canvas.getStyle()));
    long context = 0L;
    MemoryStack stack = MemoryStack.stackGet(); int ptr = stack.getPointer();
    try {
        context = create(canvas.handle, dummycanvas.handle, attribs, effective);
    } catch (SWTException e) {
        stack.setPointer(ptr);
        SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH, e);
    }
    final long finalContext = context;
    dummycanvas.dispose();
    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Dispose:
                deleteContext(finalContext);
                break;
            }
        }
    };
    canvas.addListener(SWT.Dispose, listener);
    return context;
}
 
开发者ID:httpdigest,项目名称:lwjgl3-swt,代码行数:25,代码来源:PlatformWin32GLCanvas.java

示例7: loadImage

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
/**
 * Loads an image from a file. Supported formats are
 * <ul>
 * <li>JPEG baseline &amp; progressive (12 bpc/arithmetic not supported, same as stock IJG lib</li>
 * <li>PNG 1/2/4/8-bit-per-channel (16 bpc not supported)</li>
 * <li>TGA (not sure what subset, if a subset)</li>
 * <li>BMP non-1bpp, non-RLE</li>
 * <li>PSD (composited view only, no extra channels, 8/16 bit-per-channel)</li>
 * <li>GIF (*comp always reports as 4-channel)</li>
 * <li>HDR (radiance rgbE format)</li>
 * <li>PIC (Softimage PIC)</li>
 * <li>PNM (PPM and PGM binary only)</li>
 * </ul>
 * @param path path to the file
 * @return {@link ImageData} with info about the image
 * @see org.lwjgl.stb.STBImage STBImage, image decoder
 */
public static ImageData loadImage(final File path) {
    ImageData data = new ImageData();
    try(MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer x = stack.ints(0),
                  y = stack.ints(0),
               comp = stack.ints(0);
        data.data = org.lwjgl.stb.STBImage.stbi_load(path.getAbsolutePath(), x, y, comp, 0);
        if(data.data == null) throw new RuntimeException(org.lwjgl.stb.STBImage.stbi_failure_reason());
        data.width = x.get();
        data.height = y.get();
        data.components = comp.get();
        data.clear = o -> {
            org.lwjgl.stb.STBImage.stbi_image_free(o.data);
            return null;
        };
    }
    return data;
}
 
开发者ID:melchor629,项目名称:Java-GLEngine,代码行数:36,代码来源:ImageIO.java

示例8: loadImageFromMemory

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
/**
 * Loads an image from a chunk of memory. Supported formats are
 * <ul>
 * <li>JPEG baseline &amp; progressive (12 bpc/arithmetic not supported, same as stock IJG lib</li>
 * <li>PNG 1/2/4/8-bit-per-channel (16 bpc not supported)</li>
 * <li>TGA (not sure what subset, if a subset)</li>
 * <li>BMP non-1bpp, non-RLE</li>
 * <li>PSD (composited view only, no extra channels, 8/16 bit-per-channel)</li>
 * <li>GIF (*comp always reports as 4-channel)</li>
 * <li>HDR (radiance rgbE format)</li>
 * <li>PIC (Softimage PIC)</li>
 * <li>PNM (PPM and PGM binary only)</li>
 * </ul>
 * @param buff the chunk of memory
 * @return {@link ImageData} with info about the image
 * @see org.lwjgl.stb.STBImage STBImage, image decoder
 */
public static ImageData loadImageFromMemory(final ByteBuffer buff) {
    ImageData data = new ImageData();
    try(MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer x = stack.ints(0),
                  y = stack.ints(0),
               comp = stack.ints(0);
        data.data = org.lwjgl.stb.STBImage.stbi_load_from_memory(buff, x, y, comp, 0);
        if(data.data == null) throw new RuntimeException(org.lwjgl.stb.STBImage.stbi_failure_reason());
        data.width = x.get();
        data.height = y.get();
        data.components = comp.get();
        data.clear = o -> {
            org.lwjgl.stb.STBImage.stbi_image_free(o.data);
            return null;
        };
    }
    return data;
}
 
开发者ID:melchor629,项目名称:Java-GLEngine,代码行数:36,代码来源:ImageIO.java

示例9: loadTexture

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
/**
 * Load texture from file.
 *
 * @param path File path of the texture
 *
 * @return Texture from specified file
 */
public static Texture loadTexture(String path) {
    ByteBuffer image;
    int width, height;
    try (MemoryStack stack = MemoryStack.stackPush()) {
        /* Prepare image buffers */
        IntBuffer w = stack.mallocInt(1);
        IntBuffer h = stack.mallocInt(1);
        IntBuffer comp = stack.mallocInt(1);

        /* Load image */
        stbi_set_flip_vertically_on_load(true);
        image = stbi_load(path, w, h, comp, 4);
        if (image == null) {
            throw new RuntimeException("Failed to load a texture file!"
                                       + System.lineSeparator() + stbi_failure_reason());
        }

        /* Get width and height of image */
        width = w.get();
        height = h.get();
    }

    return createTexture(width, height, image);
}
 
开发者ID:SilverTiger,项目名称:lwjgl3-tutorial,代码行数:32,代码来源:Texture.java

示例10: setUniform

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
/**
 * Sets the uniform variable at the specified location.
 *
 * @param location - Uniform location.
 * @param value - Value to set at the specified location.
 */
public void setUniform(String location, Matrix4f value) {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        FloatBuffer floatBuffer = stack.mallocFloat(4*4);
        value.get(floatBuffer);
        glUniformMatrix4fv(uniformLocations.get(location), false, floatBuffer);
    }
}
 
开发者ID:brokenprogrammer,项目名称:Mass,代码行数:14,代码来源:ShaderProgram.java

示例11: setUniform

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
public void setUniform(String uniformName, Matrix4fc matrix)
{
	try (MemoryStack stack = MemoryStack.stackPush())
	{
		FloatBuffer fb = stack.mallocFloat(16);
		matrix.get(fb);
		GL20.glUniformMatrix4fv(this.findUniformLocation(uniformName), false, fb);
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:10,代码来源:Program.java

示例12: apply

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
@Override
public void apply(Program program, Matrix4fc value)
{
	int location = program.findUniformLocation(this.getName());
	try (MemoryStack stack = MemoryStack.stackPush())
	{
		FloatBuffer fb = stack.mallocFloat(16);
		value.get(fb);
		GL20.glUniformMatrix4fv(location, false, fb);
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:12,代码来源:PropertyMat4.java

示例13: setUniform

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
public void setUniform(String uniformName, Matrix4f value) {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        // Dump the matrix into a float buffer
        FloatBuffer fb = stack.mallocFloat(16);
        value.get(fb);
        glUniformMatrix4fv(uniforms.get(uniformName), false, fb);
    }
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:9,代码来源:ShaderProgram.java

示例14: create

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
public long create(Canvas canvas, VKData data) throws AWTException {
    MemoryStack stack = MemoryStack.stackGet();
    int ptr = stack.getPointer();
    JAWTDrawingSurface ds = JAWT_GetDrawingSurface(awt.GetDrawingSurface(), canvas);
    try {
        int lock = JAWT_DrawingSurface_Lock(ds.Lock(), ds);
        if ((lock & JAWT_LOCK_ERROR) != 0)
            throw new AWTException("JAWT_DrawingSurface_Lock() failed");
        try {
            JAWTDrawingSurfaceInfo dsi = JAWT_DrawingSurface_GetDrawingSurfaceInfo(ds.GetDrawingSurfaceInfo(), ds);
            try {
                JAWTWin32DrawingSurfaceInfo dsiWin = JAWTWin32DrawingSurfaceInfo.create(dsi.platformInfo());
                long hwnd = dsiWin.hwnd();
                VkWin32SurfaceCreateInfoKHR sci = VkWin32SurfaceCreateInfoKHR.callocStack(stack)
                        .sType(VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR)
                        .hinstance(WinBase.GetModuleHandle((ByteBuffer) null))
                        .hwnd(hwnd);
                long surfaceAddr = stack.nmalloc(8, 8);
                int err = nvkCreateWin32SurfaceKHR(data.instance, sci.address(), 0L, surfaceAddr);
                long surface = MemoryUtil.memGetLong(surfaceAddr);
                stack.setPointer(ptr);
                if (err != VK_SUCCESS) {
                    throw new AWTException("Calling vkCreateWin32SurfaceKHR failed with error: " + err);
                }
                return surface;
            } finally {
                JAWT_DrawingSurface_FreeDrawingSurfaceInfo(ds.FreeDrawingSurfaceInfo(), dsi);
            }
        } finally {
            JAWT_DrawingSurface_Unlock(ds.Unlock(), ds);
        }
    } finally {
        JAWT_FreeDrawingSurface(awt.FreeDrawingSurface(), ds);
    }
}
 
开发者ID:httpdigest,项目名称:lwjgl3-awt,代码行数:36,代码来源:PlatformWin32VKCanvas.java

示例15: openMultipleDialog

import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
@Override
public List<File> openMultipleDialog(String title, String defaultPath,
        String[] filterPatterns, String filterDescription) {
    String result = null;
    
    //fix file path characters
    if (Utils.isWindows()) {
        defaultPath = defaultPath.replace("/", "\\");
    } else {
        defaultPath = defaultPath.replace("\\", "/");
    }
    if (filterPatterns != null && filterPatterns.length > 0) {
        try (MemoryStack stack = stackPush()) {
            PointerBuffer pointerBuffer = stack.mallocPointer(filterPatterns.length);

            for (String filterPattern : filterPatterns) {
                pointerBuffer.put(stack.UTF8(filterPattern));
            }
            
            pointerBuffer.flip();
            result = org.lwjgl.util.tinyfd.TinyFileDialogs.tinyfd_openFileDialog(title, defaultPath, pointerBuffer, filterDescription, true);
        }
    } else {
        result = org.lwjgl.util.tinyfd.TinyFileDialogs.tinyfd_openFileDialog(title, defaultPath, null, filterDescription, true);
    }
    
    if (result != null) {
        String[] paths = result.split("\\|");
        ArrayList<File> returnValue = new ArrayList<>();
        for (String path : paths) {
            returnValue.add(new File(path));
        }
        return returnValue;
    } else {
        return null;
    }
}
 
开发者ID:raeleus,项目名称:skin-composer,代码行数:38,代码来源:DesktopLauncher.java


注:本文中的org.lwjgl.system.MemoryStack类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。