本文整理汇总了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);
}
示例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());
}
}
示例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
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例7: loadImage
import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
/**
* Loads an image from a file. Supported formats are
* <ul>
* <li>JPEG baseline & 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;
}
示例8: loadImageFromMemory
import org.lwjgl.system.MemoryStack; //导入依赖的package包/类
/**
* Loads an image from a chunk of memory. Supported formats are
* <ul>
* <li>JPEG baseline & 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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
}