mirror of https://github.com/bjornbytes/lovr.git
Opaque Texture;
This commit is contained in:
parent
b045d42782
commit
52d4f7e520
|
@ -32,7 +32,7 @@ void lovrCanvasSetAttachments(Canvas* canvas, Attachment* attachments, uint32_t
|
|||
lovrAssert(!hasDepthBuffer || width == canvas->width, "Texture width of %d does not match Canvas width (%d)", width, canvas->width);
|
||||
lovrAssert(!hasDepthBuffer || height == canvas->height, "Texture height of %d does not match Canvas height (%d)", height, canvas->height);
|
||||
#ifndef __ANDROID__ // On multiview canvases, the multisample settings can be different
|
||||
lovrAssert(texture->msaa == canvas->flags.msaa, "Texture MSAA does not match Canvas MSAA");
|
||||
lovrAssert(lovrTextureGetMSAA(texture) == canvas->flags.msaa, "Texture MSAA does not match Canvas MSAA");
|
||||
#endif
|
||||
lovrRetain(texture);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,27 @@ struct Buffer {
|
|||
uint8_t incoherent;
|
||||
};
|
||||
|
||||
struct Texture {
|
||||
GLuint id;
|
||||
GLuint msaaId;
|
||||
GLenum target;
|
||||
TextureType type;
|
||||
TextureFormat format;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t depth;
|
||||
uint32_t mipmapCount;
|
||||
CompareMode compareMode;
|
||||
TextureFilter filter;
|
||||
TextureWrap wrap;
|
||||
uint32_t msaa;
|
||||
bool srgb;
|
||||
bool mipmaps;
|
||||
bool allocated;
|
||||
bool native;
|
||||
uint8_t incoherent;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
BARRIER_BLOCK,
|
||||
BARRIER_UNIFORM_TEXTURE,
|
||||
|
@ -1442,7 +1463,8 @@ const GpuStats* lovrGpuGetStats() {
|
|||
|
||||
// Texture
|
||||
|
||||
Texture* lovrTextureInit(Texture* texture, TextureType type, TextureData** slices, uint32_t sliceCount, bool srgb, bool mipmaps, uint32_t msaa) {
|
||||
Texture* lovrTextureCreate(TextureType type, TextureData** slices, uint32_t sliceCount, bool srgb, bool mipmaps, uint32_t msaa) {
|
||||
Texture* texture = lovrAlloc(Texture);
|
||||
state.stats.textureCount++;
|
||||
texture->type = type;
|
||||
texture->srgb = srgb;
|
||||
|
@ -1470,7 +1492,8 @@ Texture* lovrTextureInit(Texture* texture, TextureType type, TextureData** slice
|
|||
return texture;
|
||||
}
|
||||
|
||||
Texture* lovrTextureInitFromHandle(Texture* texture, uint32_t handle, TextureType type, uint32_t depth) {
|
||||
Texture* lovrTextureCreateFromHandle(uint32_t handle, TextureType type, uint32_t depth) {
|
||||
Texture* texture = lovrAlloc(Texture);
|
||||
state.stats.textureCount++;
|
||||
texture->type = type;
|
||||
texture->id = handle;
|
||||
|
@ -1637,6 +1660,46 @@ void lovrTextureReplacePixels(Texture* texture, TextureData* textureData, uint32
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t lovrTextureGetWidth(Texture* texture, uint32_t mipmap) {
|
||||
return MAX(texture->width >> mipmap, 1);
|
||||
}
|
||||
|
||||
uint32_t lovrTextureGetHeight(Texture* texture, uint32_t mipmap) {
|
||||
return MAX(texture->height >> mipmap, 1);
|
||||
}
|
||||
|
||||
uint32_t lovrTextureGetDepth(Texture* texture, uint32_t mipmap) {
|
||||
return texture->type == TEXTURE_VOLUME ? MAX(texture->depth >> mipmap, 1) : texture->depth;
|
||||
}
|
||||
|
||||
uint32_t lovrTextureGetMipmapCount(Texture* texture) {
|
||||
return texture->mipmapCount;
|
||||
}
|
||||
|
||||
uint32_t lovrTextureGetMSAA(Texture* texture) {
|
||||
return texture->msaa;
|
||||
}
|
||||
|
||||
TextureType lovrTextureGetType(Texture* texture) {
|
||||
return texture->type;
|
||||
}
|
||||
|
||||
TextureFormat lovrTextureGetFormat(Texture* texture) {
|
||||
return texture->format;
|
||||
}
|
||||
|
||||
CompareMode lovrTextureGetCompareMode(Texture* texture) {
|
||||
return texture->compareMode;
|
||||
}
|
||||
|
||||
TextureFilter lovrTextureGetFilter(Texture* texture) {
|
||||
return texture->filter;
|
||||
}
|
||||
|
||||
TextureWrap lovrTextureGetWrap(Texture* texture) {
|
||||
return texture->wrap;
|
||||
}
|
||||
|
||||
void lovrTextureSetCompareMode(Texture* texture, CompareMode compareMode) {
|
||||
if (texture->compareMode != compareMode) {
|
||||
lovrGraphicsFlush();
|
||||
|
|
|
@ -23,10 +23,3 @@
|
|||
|
||||
#define GPU_SHADER_FIELDS \
|
||||
uint32_t program;
|
||||
|
||||
#define GPU_TEXTURE_FIELDS \
|
||||
bool native; \
|
||||
uint8_t incoherent; \
|
||||
GLuint id; \
|
||||
GLuint msaaId; \
|
||||
GLenum target;
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
#include "graphics/texture.h"
|
||||
|
||||
uint32_t lovrTextureGetWidth(Texture* texture, uint32_t mipmap) {
|
||||
return MAX(texture->width >> mipmap, 1);
|
||||
}
|
||||
|
||||
uint32_t lovrTextureGetHeight(Texture* texture, uint32_t mipmap) {
|
||||
return MAX(texture->height >> mipmap, 1);
|
||||
}
|
||||
|
||||
uint32_t lovrTextureGetDepth(Texture* texture, uint32_t mipmap) {
|
||||
return texture->type == TEXTURE_VOLUME ? MAX(texture->depth >> mipmap, 1) : texture->depth;
|
||||
}
|
||||
|
||||
uint32_t lovrTextureGetMipmapCount(Texture* texture) {
|
||||
return texture->mipmapCount;
|
||||
}
|
||||
|
||||
TextureType lovrTextureGetType(Texture* texture) {
|
||||
return texture->type;
|
||||
}
|
||||
|
||||
TextureFormat lovrTextureGetFormat(Texture* texture) {
|
||||
return texture->format;
|
||||
}
|
||||
|
||||
CompareMode lovrTextureGetCompareMode(Texture* texture) {
|
||||
return texture->compareMode;
|
||||
}
|
||||
|
||||
TextureFilter lovrTextureGetFilter(Texture* texture) {
|
||||
return texture->filter;
|
||||
}
|
||||
|
||||
TextureWrap lovrTextureGetWrap(Texture* texture) {
|
||||
return texture->wrap;
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
#include "data/textureData.h"
|
||||
#include "graphics/graphics.h"
|
||||
#include "graphics/opengl.h"
|
||||
#include "data/modelData.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -15,27 +14,9 @@ typedef enum {
|
|||
TEXTURE_VOLUME
|
||||
} TextureType;
|
||||
|
||||
typedef struct Texture {
|
||||
TextureType type;
|
||||
TextureFormat format;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t depth;
|
||||
uint32_t mipmapCount;
|
||||
CompareMode compareMode;
|
||||
TextureFilter filter;
|
||||
TextureWrap wrap;
|
||||
uint32_t msaa;
|
||||
bool srgb;
|
||||
bool mipmaps;
|
||||
bool allocated;
|
||||
GPU_TEXTURE_FIELDS
|
||||
} Texture;
|
||||
|
||||
Texture* lovrTextureInit(Texture* texture, TextureType type, struct TextureData** slices, uint32_t sliceCount, bool srgb, bool mipmaps, uint32_t msaa);
|
||||
Texture* lovrTextureInitFromHandle(Texture* texture, uint32_t handle, TextureType type, uint32_t depth);
|
||||
#define lovrTextureCreate(...) lovrTextureInit(lovrAlloc(Texture), __VA_ARGS__)
|
||||
#define lovrTextureCreateFromHandle(...) lovrTextureInitFromHandle(lovrAlloc(Texture), __VA_ARGS__)
|
||||
typedef struct Texture Texture;
|
||||
Texture* lovrTextureCreate(TextureType type, struct TextureData** slices, uint32_t sliceCount, bool srgb, bool mipmaps, uint32_t msaa);
|
||||
Texture* lovrTextureCreateFromHandle(uint32_t handle, TextureType type, uint32_t depth);
|
||||
void lovrTextureDestroy(void* ref);
|
||||
void lovrTextureAllocate(Texture* texture, uint32_t width, uint32_t height, uint32_t depth, TextureFormat format);
|
||||
void lovrTextureReplacePixels(Texture* texture, struct TextureData* data, uint32_t x, uint32_t y, uint32_t slice, uint32_t mipmap);
|
||||
|
|
|
@ -203,7 +203,7 @@ static struct {
|
|||
XrCompositionLayerProjectionView layerViews[2];
|
||||
XrFrameState frameState;
|
||||
Canvas* canvas;
|
||||
Texture textures[MAX_IMAGES];
|
||||
Texture* textures[MAX_IMAGES];
|
||||
uint32_t imageCount;
|
||||
uint32_t msaa;
|
||||
uint32_t width;
|
||||
|
@ -394,7 +394,7 @@ static bool openxr_init(float offset, uint32_t msaa) {
|
|||
XR_INIT(xrEnumerateSwapchainImages(state.swapchain, MAX_IMAGES, &state.imageCount, (XrSwapchainImageBaseHeader*) images));
|
||||
|
||||
for (uint32_t i = 0; i < state.imageCount; i++) {
|
||||
lovrTextureInitFromHandle(&state.textures[i], images[i].image, TEXTURE_2D, 1);
|
||||
state.textures[i] = lovrTextureCreateFromHandle(images[i].image, TEXTURE_2D, 1);
|
||||
}
|
||||
|
||||
// Pre-init composition layer
|
||||
|
@ -425,7 +425,7 @@ static bool openxr_init(float offset, uint32_t msaa) {
|
|||
static void openxr_destroy() {
|
||||
lovrRelease(Canvas, state.canvas);
|
||||
for (uint32_t i = 0; i < state.imageCount; i++) {
|
||||
lovrRelease(Texture, &state.textures[i]);
|
||||
lovrRelease(Texture, state.textures[i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MAX_ACTIONS; i++) {
|
||||
|
@ -721,7 +721,7 @@ static void openxr_renderTo(void (*callback)(void*), void* userdata) {
|
|||
mat4_invert(camera.viewMatrix[eye]);
|
||||
}
|
||||
|
||||
lovrCanvasSetAttachments(state.canvas, &(Attachment) { &state.textures[imageIndex], 0, 0 }, 1);
|
||||
lovrCanvasSetAttachments(state.canvas, &(Attachment) { state.textures[imageIndex], 0, 0 }, 1);
|
||||
lovrGraphicsSetCamera(&camera, true);
|
||||
callback(userdata);
|
||||
lovrGraphicsSetCamera(NULL, false);
|
||||
|
|
Loading…
Reference in New Issue