Add deep color arg to ApplicationRun

This commit is contained in:
Jack Andersen 2018-01-15 20:29:43 -10:00
parent 41cfb56c36
commit 3d987b6dc9
11 changed files with 67 additions and 26 deletions

View File

@ -64,6 +64,7 @@ ApplicationRun(IApplication::EPlatformType platform,
std::string_view gfxApi = {},
uint32_t samples = 1,
uint32_t anisotropy = 1,
bool deepColor = false,
bool singleInstance=true);
extern IApplication* APP;
@ -76,6 +77,7 @@ ApplicationRun(IApplication::EPlatformType platform,
std::string_view gfxApi = {},
uint32_t samples = 1,
uint32_t anisotropy = 1,
bool deepColor = false,
bool singleInstance=true)
{
if (APP)
@ -84,7 +86,7 @@ ApplicationRun(IApplication::EPlatformType platform,
for (int i=1 ; i<argc ; ++i)
args.push_back(argv[i]);
return ApplicationRun(platform, cb, uniqueName, friendlyName, argv[0], args,
gfxApi, samples, anisotropy, singleInstance);
gfxApi, samples, anisotropy, deepColor, singleInstance);
}
}

View File

@ -34,9 +34,10 @@ public:
{
None = 0,
RGBA8 = 1, /* Default */
RGBA8_Z24 = 2,
RGBAF32 = 3,
RGBAF32_Z24 = 4
RGBA16 = 2,
RGBA8_Z24 = 3,
RGBAF32 = 4,
RGBAF32_Z24 = 5
};
virtual ~IGraphicsContext() {}

View File

@ -15,6 +15,7 @@ struct GLContext
{
uint32_t m_sampleCount = 1;
uint32_t m_anisotropy = 1;
bool m_deepColor = false;
};
class GLDataFactory : public IGraphicsDataFactory

View File

@ -444,10 +444,12 @@ class GLTextureR : public GraphicsDataNode<ITextureR>
size_t m_width = 0;
size_t m_height = 0;
size_t m_samples = 0;
GLenum m_colorFormat;
size_t m_colorBindCount;
size_t m_depthBindCount;
GLTextureR(const ObjToken<BaseGraphicsData>& parent, GLCommandQueue* q, size_t width, size_t height, size_t samples,
TextureClampMode clampMode, size_t colorBindCount, size_t depthBindCount);
GLTextureR(const ObjToken<BaseGraphicsData>& parent, GLCommandQueue* q, size_t width, size_t height,
size_t samples, GLenum colorFormat, TextureClampMode clampMode,
size_t colorBindCount, size_t depthBindCount);
public:
~GLTextureR()
{
@ -486,14 +488,14 @@ public:
if (m_samples > 1)
{
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_texs[0]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, GL_RGBA, width, height, GL_FALSE);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, m_colorFormat, width, height, GL_FALSE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_texs[1]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_samples, GL_DEPTH_COMPONENT24, width, height, GL_FALSE);
}
else
{
glBindTexture(GL_TEXTURE_2D, m_texs[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexImage2D(GL_TEXTURE_2D, 0, m_colorFormat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glBindTexture(GL_TEXTURE_2D, m_texs[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
@ -507,7 +509,7 @@ public:
if (m_bindTexs[0][i])
{
glBindTexture(GL_TEXTURE_2D, m_bindTexs[0][i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexImage2D(GL_TEXTURE_2D, 0, m_colorFormat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
}
}
@ -1639,9 +1641,10 @@ GLDataFactory::Context::newDynamicTexture(size_t width, size_t height, TextureFo
}
GLTextureR::GLTextureR(const ObjToken<BaseGraphicsData>& parent, GLCommandQueue* q, size_t width, size_t height,
size_t samples, TextureClampMode clampMode, size_t colorBindingCount, size_t depthBindingCount)
size_t samples, GLenum colorFormat, TextureClampMode clampMode,
size_t colorBindingCount, size_t depthBindingCount)
: GraphicsDataNode<ITextureR>(parent), m_q(q), m_width(width), m_height(height), m_samples(samples),
m_colorBindCount(colorBindingCount), m_depthBindCount(depthBindingCount)
m_colorFormat(colorFormat), m_colorBindCount(colorBindingCount), m_depthBindCount(depthBindingCount)
{
glGenTextures(2, m_texs);
if (colorBindingCount)
@ -1660,14 +1663,14 @@ GLTextureR::GLTextureR(const ObjToken<BaseGraphicsData>& parent, GLCommandQueue*
if (samples > 1)
{
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_texs[0]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA, width, height, GL_FALSE);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, colorFormat, width, height, GL_FALSE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_texs[1]);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_DEPTH_COMPONENT24, width, height, GL_FALSE);
}
else
{
glBindTexture(GL_TEXTURE_2D, m_texs[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexImage2D(GL_TEXTURE_2D, 0, colorFormat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glBindTexture(GL_TEXTURE_2D, m_texs[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
}
@ -1675,7 +1678,7 @@ GLTextureR::GLTextureR(const ObjToken<BaseGraphicsData>& parent, GLCommandQueue*
for (int i=0 ; i<colorBindingCount ; ++i)
{
glBindTexture(GL_TEXTURE_2D, m_bindTexs[0][i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexImage2D(GL_TEXTURE_2D, 0, colorFormat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
SetClampMode(GL_TEXTURE_2D, clampMode);
@ -1698,7 +1701,8 @@ GLDataFactory::Context::newRenderTexture(size_t width, size_t height, TextureCla
{
GLDataFactoryImpl& factory = static_cast<GLDataFactoryImpl&>(m_parent);
GLCommandQueue* q = static_cast<GLCommandQueue*>(factory.m_parent->getCommandQueue());
ObjToken<ITextureR> retval(new GLTextureR(m_data, q, width, height, factory.m_glCtx->m_sampleCount, clampMode,
ObjToken<ITextureR> retval(new GLTextureR(m_data, q, width, height, factory.m_glCtx->m_sampleCount,
factory.m_glCtx->m_deepColor ? GL_RGBA16 : GL_RGBA8, clampMode,
colorBindingCount, depthBindingCount));
q->resizeRenderTexture(retval, width, height);
return retval;

View File

@ -490,7 +490,7 @@ class MetalTextureR : public GraphicsDataNode<ITextureR>
@autoreleasepool
{
MTLTextureDescriptor* desc =
[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:ctx->m_pixelFormat
width:m_width height:m_height
mipmapped:NO];
desc.storageMode = MTLStorageModePrivate;
@ -521,7 +521,7 @@ class MetalTextureR : public GraphicsDataNode<ITextureR>
desc.usage = MTLTextureUsageShaderRead;
if (m_colorBindCount)
{
desc.pixelFormat = MTLPixelFormatBGRA8Unorm;
desc.pixelFormat = ctx->m_pixelFormat;
for (int i=0 ; i<m_colorBindCount ; ++i)
{
m_colorBindTex[i] = [ctx->m_dev newTextureWithDescriptor:desc];
@ -799,7 +799,7 @@ class MetalShaderPipeline : public GraphicsDataNode<IShaderPipeline>
desc.fragmentFunction = m_frag.get().m_shader;
desc.vertexDescriptor = vtxFmt.cast<MetalVertexFormat>()->m_vdesc;
desc.sampleCount = targetSamples;
desc.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm;
desc.colorAttachments[0].pixelFormat = ctx->m_pixelFormat;
desc.colorAttachments[0].writeMask = (colorWrite ? COLOR_WRITE_MASK : 0) |
(alphaWrite ? MTLColorWriteMaskAlpha : 0);
desc.colorAttachments[0].blendingEnabled = dstFac != BlendFactor::Zero;

View File

@ -67,7 +67,8 @@ public:
const std::vector<SystemString>& args,
std::string_view gfxApi,
uint32_t samples,
uint32_t anisotropy)
uint32_t anisotropy,
bool deepColor)
: m_callback(callback),
m_uniqueName(uniqueName),
m_friendlyName(friendlyName),
@ -76,8 +77,10 @@ public:
{
m_metalCtx.m_sampleCount = samples;
m_metalCtx.m_anisotropy = anisotropy;
m_metalCtx.m_pixelFormat = deepColor ? MTLPixelFormatRGBA16Float : MTLPixelFormatBGRA8Unorm;
m_glCtx.m_sampleCount = samples;
m_glCtx.m_anisotropy = anisotropy;
m_glCtx.m_deepColor = deepColor;
[[NSApplication sharedApplication] setActivationPolicy:NSApplicationActivationPolicyRegular];
@ -228,6 +231,7 @@ int ApplicationRun(IApplication::EPlatformType platform,
std::string_view gfxApi,
uint32_t samples,
uint32_t anisotropy,
bool deepColor,
bool singleInstance)
{
std::string thrName = std::string(friendlyName) + " Main Thread";
@ -240,7 +244,8 @@ int ApplicationRun(IApplication::EPlatformType platform,
platform != IApplication::EPlatformType::Auto)
return 1;
/* Never deallocated to ensure window destructors have access */
APP = new ApplicationCocoa(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy);
APP = new ApplicationCocoa(cb, uniqueName, friendlyName, pname, args,
gfxApi, samples, anisotropy, deepColor);
}
[NSApp run];
ApplicationCocoa* appCocoa = static_cast<ApplicationCocoa*>(APP);

View File

@ -30,6 +30,7 @@ struct MetalContext
std::unordered_map<IWindow*, Window> m_windows;
uint32_t m_sampleCount = 1;
uint32_t m_anisotropy = 1;
MTLPixelFormat m_pixelFormat = MTLPixelFormatBGRA8Unorm;
};
}

View File

@ -42,6 +42,16 @@ static const NSOpenGLPixelFormatAttribute PF_RGBA8_ATTRS[] =
0, 0
};
static const NSOpenGLPixelFormatAttribute PF_RGBA16_ATTRS[] =
{
NSOpenGLPFAAccelerated,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 48,
NSOpenGLPFAAlphaSize, 16,
0, 0
};
static const NSOpenGLPixelFormatAttribute PF_RGBA8_Z24_ATTRS[] =
{
NSOpenGLPFAAccelerated,
@ -80,6 +90,7 @@ static const NSOpenGLPixelFormatAttribute* PF_TABLE[] =
{
NULL,
PF_RGBA8_ATTRS,
PF_RGBA16_ATTRS,
PF_RGBA8_Z24_ATTRS,
PF_RGBAF32_ATTRS,
PF_RGBAF32_Z24_ATTRS
@ -207,7 +218,8 @@ public:
GraphicsContextCocoaGL(EGraphicsAPI api, IWindow* parentWindow,
NSOpenGLContext* lastGLCtx, GLContext* glCtx)
: GraphicsContextCocoa(api, EPixelFormat::RGBA8, parentWindow),
: GraphicsContextCocoa(api, glCtx->m_deepColor ?
EPixelFormat::RGBA16 : EPixelFormat::RGBA8, parentWindow),
m_lastCtx(lastGLCtx), m_glCtx(glCtx)
{
m_dataFactory = _NewGLDataFactory(this, glCtx);
@ -365,7 +377,9 @@ public:
MetalContext* m_metalCtx;
GraphicsContextCocoaMetal(EGraphicsAPI api, IWindow* parentWindow, MetalContext* metalCtx)
: GraphicsContextCocoa(api, EPixelFormat::RGBA8, parentWindow),
: GraphicsContextCocoa(api,
(metalCtx->m_pixelFormat == MTLPixelFormatRGBA16Float) ?
EPixelFormat::RGBA16 : EPixelFormat::RGBA8, parentWindow),
m_parentWindow(parentWindow), m_metalCtx(metalCtx)
{
m_dataFactory = _NewMetalDataFactory(this, metalCtx);
@ -1229,7 +1243,8 @@ static boo::ESpecialKey translateKeycode(short code)
{
CAMetalLayer* layer = [CAMetalLayer new];
layer.device = m_ctx->m_dev;
layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
layer.pixelFormat = m_ctx->m_pixelFormat;
layer.colorspace = CGColorSpaceCreateDeviceRGB();
layer.framebufferOnly = NO;
return layer;
}

View File

@ -569,6 +569,7 @@ int ApplicationRun(IApplication::EPlatformType platform,
std::string_view gfxApi,
uint32_t samples,
uint32_t anisotropy,
bool deepColor,
bool singleInstance)
{
std::string thrName = WCSTMBS(friendlyName.data()) + " Main Thread";

View File

@ -61,6 +61,7 @@ int ApplicationRun(IApplication::EPlatformType platform,
std::string_view gfxApi,
uint32_t samples,
uint32_t anisotropy,
bool deepColor,
bool singleInstance)
{
std::string thrName = std::string(friendlyName) + " Main Thread";

View File

@ -302,12 +302,21 @@ struct TestApplicationCallback : IApplicationCallback
float pos[3];
float uv[2];
};
/*
static const Vert quad[4] =
{
{{0.5,0.5},{1.0,1.0}},
{{-0.5,0.5},{0.0,1.0}},
{{0.5,-0.5},{1.0,0.0}},
{{-0.5,-0.5},{0.0,0.0}}
};
*/
static const Vert quad[4] =
{
{{1.0,1.0},{1.0,1.0}},
{{-1.0,1.0},{0.0,1.0}},
{{1.0,-1.0},{1.0,0.0}},
{{-1.0,-1.0},{0.0,0.0}}
};
auto vbo = ctx.newStaticBuffer(BufferUse::Vertex, quad, sizeof(Vert), 4);
@ -361,7 +370,8 @@ struct TestApplicationCallback : IApplicationCallback
"in vec2 out_uv;\n"
"void main()\n"
"{\n"
" out_frag = texture(tex, out_uv);\n"
" //out_frag = texture(tex, out_uv);\n"
" out_frag = vec4(out_uv.xy, 0.0, 1.0);\n"
"}\n";
static const char* texName = "tex";
@ -541,7 +551,7 @@ struct TestApplicationCallback : IApplicationCallback
gfxQ->setViewport(r);
gfxQ->setScissor(r);
float rgba[] = {std::max(0.f, sinf(frameIdx / 60.0)), std::max(0.f, cosf(frameIdx / 60.0)), 0.0, 1.0};
gfxQ->setClearColor(rgba);
//gfxQ->setClearColor(rgba);
gfxQ->clearTarget();
gfxQ->setShaderDataBinding(m_binding);
@ -596,7 +606,7 @@ int main(int argc, const boo::SystemChar** argv)
logvisor::RegisterConsoleLogger();
boo::TestApplicationCallback appCb;
int ret = ApplicationRun(boo::IApplication::EPlatformType::Auto,
appCb, _S("boo"), _S("boo"), argc, argv);
appCb, _S("boo"), _S("boo"), argc, argv, {}, 1, 1, false);
printf("IM DYING!!\n");
return ret;
}