Adding a simple test for output gamma.
This commit is contained in:
parent
a8adcf8408
commit
28e788a308
16
examples/rt-gamma-test/Makefile
Normal file
16
examples/rt-gamma-test/Makefile
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
TARGET = rt-gamma-test.img
|
||||||
|
|
||||||
|
APP_SOURCES = main.c
|
||||||
|
|
||||||
|
LIB_DIR = ../../lib
|
||||||
|
include $(LIB_DIR)/Makefile.rules
|
||||||
|
|
||||||
|
.PHONY: shaders
|
||||||
|
|
||||||
|
shaders: cube_vs.h cube_ps.h
|
||||||
|
|
||||||
|
cube_vs.h: cube.fx
|
||||||
|
wine fxc.exe /T vs_2_0 /E MyVertexShader /Fh cube_vs.h cube.fx
|
||||||
|
|
||||||
|
cube_ps.h: cube.fx
|
||||||
|
wine fxc.exe /T ps_2_0 /E MyPixelShader /Fh cube_ps.h cube.fx
|
36
examples/rt-gamma-test/cube.fx
Normal file
36
examples/rt-gamma-test/cube.fx
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
float4x4 matView, matProj;
|
||||||
|
|
||||||
|
struct VS_Input
|
||||||
|
{
|
||||||
|
float4 Pos : POSITION;
|
||||||
|
float4 Color : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VS_Output
|
||||||
|
{
|
||||||
|
float4 Pos : POSITION;
|
||||||
|
float4 Color : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
VS_Output
|
||||||
|
MyVertexShader(VS_Input Input)
|
||||||
|
{
|
||||||
|
VS_Output Output;
|
||||||
|
|
||||||
|
Output.Pos = mul(mul(Input.Pos, matView), matProj);
|
||||||
|
Output.Color = Input.Color;
|
||||||
|
|
||||||
|
return Output;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PS_Input
|
||||||
|
{
|
||||||
|
float4 Color : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
float4
|
||||||
|
MyPixelShader(PS_Input Input) : COLOR
|
||||||
|
{
|
||||||
|
return Input.Color;
|
||||||
|
}
|
21
examples/rt-gamma-test/cube_ps.h
Normal file
21
examples/rt-gamma-test/cube_ps.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#if 0
|
||||||
|
//
|
||||||
|
// Generated by Microsoft (R) D3DX9 Shader Compiler
|
||||||
|
//
|
||||||
|
// fxc /T ps_2_0 /E MyPixelShader /Fh cube_ps.h cube.fx
|
||||||
|
//
|
||||||
|
ps_2_0
|
||||||
|
dcl v0
|
||||||
|
mov oC0, v0
|
||||||
|
|
||||||
|
// approximately 1 instruction slot used
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const DWORD g_ps20_MyPixelShader[] =
|
||||||
|
{
|
||||||
|
0xffff0200, 0x0013fffe, 0x42415443, 0x0000001c, 0x00000023, 0xffff0200,
|
||||||
|
0x00000000, 0x00000000, 0x20000100, 0x0000001c, 0x325f7370, 0x4d00305f,
|
||||||
|
0x6f726369, 0x74666f73, 0x29522820, 0x44334420, 0x53203958, 0x65646168,
|
||||||
|
0x6f432072, 0x6c69706d, 0x00207265, 0x0200001f, 0x80000000, 0x900f0000,
|
||||||
|
0x02000001, 0x800f0800, 0x90e40000, 0x0000ffff
|
||||||
|
};
|
54
examples/rt-gamma-test/cube_vs.h
Normal file
54
examples/rt-gamma-test/cube_vs.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#if 0
|
||||||
|
//
|
||||||
|
// Generated by Microsoft (R) D3DX9 Shader Compiler
|
||||||
|
//
|
||||||
|
// fxc /T vs_2_0 /E MyVertexShader /Fh cube_vs.h cube.fx
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
//
|
||||||
|
// float4x4 matProj;
|
||||||
|
// float4x4 matView;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Registers:
|
||||||
|
//
|
||||||
|
// Name Reg Size
|
||||||
|
// ------------ ----- ----
|
||||||
|
// matView c0 4
|
||||||
|
// matProj c4 4
|
||||||
|
//
|
||||||
|
|
||||||
|
vs_2_0
|
||||||
|
dcl_position v0
|
||||||
|
dcl_color v1
|
||||||
|
dp4 r0.x, v0, c0
|
||||||
|
dp4 r0.y, v0, c1
|
||||||
|
dp4 r0.z, v0, c2
|
||||||
|
dp4 r0.w, v0, c3
|
||||||
|
dp4 oPos.x, r0, c4
|
||||||
|
dp4 oPos.y, r0, c5
|
||||||
|
dp4 oPos.z, r0, c6
|
||||||
|
dp4 oPos.w, r0, c7
|
||||||
|
mov oD0, v1
|
||||||
|
|
||||||
|
// approximately 9 instruction slots used
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const DWORD g_vs20_MyVertexShader[] =
|
||||||
|
{
|
||||||
|
0xfffe0200, 0x0025fffe, 0x42415443, 0x0000001c, 0x0000006b, 0xfffe0200,
|
||||||
|
0x00000002, 0x0000001c, 0x20000100, 0x00000064, 0x00000044, 0x00040002,
|
||||||
|
0x00000004, 0x0000004c, 0x00000000, 0x0000005c, 0x00000002, 0x00000004,
|
||||||
|
0x0000004c, 0x00000000, 0x5074616d, 0x006a6f72, 0x00030003, 0x00040004,
|
||||||
|
0x00000001, 0x00000000, 0x5674616d, 0x00776569, 0x325f7376, 0x4d00305f,
|
||||||
|
0x6f726369, 0x74666f73, 0x29522820, 0x44334420, 0x53203958, 0x65646168,
|
||||||
|
0x6f432072, 0x6c69706d, 0x00207265, 0x0200001f, 0x80000000, 0x900f0000,
|
||||||
|
0x0200001f, 0x8000000a, 0x900f0001, 0x03000009, 0x80010000, 0x90e40000,
|
||||||
|
0xa0e40000, 0x03000009, 0x80020000, 0x90e40000, 0xa0e40001, 0x03000009,
|
||||||
|
0x80040000, 0x90e40000, 0xa0e40002, 0x03000009, 0x80080000, 0x90e40000,
|
||||||
|
0xa0e40003, 0x03000009, 0xc0010000, 0x80e40000, 0xa0e40004, 0x03000009,
|
||||||
|
0xc0020000, 0x80e40000, 0xa0e40005, 0x03000009, 0xc0040000, 0x80e40000,
|
||||||
|
0xa0e40006, 0x03000009, 0xc0080000, 0x80e40000, 0xa0e40007, 0x02000001,
|
||||||
|
0xd00f0000, 0x90e40001, 0x0000ffff
|
||||||
|
};
|
204
examples/rt-gamma-test/main.c
Normal file
204
examples/rt-gamma-test/main.c
Normal file
|
@ -0,0 +1,204 @@
|
||||||
|
/*
|
||||||
|
* Test SVGA3D_RS_OUTPUTGAMMA.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008-2009 VMware, Inc. Licensed under the MIT
|
||||||
|
* License, please see the README.txt. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "svga3dutil.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
typedef uint32 DWORD;
|
||||||
|
#include "cube_vs.h"
|
||||||
|
#include "cube_ps.h"
|
||||||
|
|
||||||
|
#define MY_VSHADER_ID 0
|
||||||
|
#define MY_PSHADER_ID 0
|
||||||
|
|
||||||
|
#define CONST_MAT_VIEW 0
|
||||||
|
#define CONST_MAT_PROJ 4
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float position[3];
|
||||||
|
uint32 color;
|
||||||
|
} MyVertex;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cubes are drawn with a gradient from black to white.
|
||||||
|
*/
|
||||||
|
#define COLOR1 0x000000
|
||||||
|
#define COLOR2 0xFFFFFF
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This defines the grid spacing, as well as the total number of cubes we draw.
|
||||||
|
*/
|
||||||
|
#define GRID_STEP 2
|
||||||
|
#define GAMMA_STEP 0.1f
|
||||||
|
#define GRID_X_COUNT 5
|
||||||
|
#define GRID_Y_COUNT 5
|
||||||
|
|
||||||
|
static const MyVertex vertexData[] = {
|
||||||
|
{ {-1, -1, -1}, COLOR1 },
|
||||||
|
{ {-1, -1, 1}, COLOR1 },
|
||||||
|
{ {-1, 1, -1}, COLOR1 },
|
||||||
|
{ {-1, 1, 1}, COLOR1 },
|
||||||
|
{ { 1, -1, -1}, COLOR2 },
|
||||||
|
{ { 1, -1, 1}, COLOR2 },
|
||||||
|
{ { 1, 1, -1}, COLOR2 },
|
||||||
|
{ { 1, 1, 1}, COLOR2 },
|
||||||
|
};
|
||||||
|
|
||||||
|
#define QUAD(a,b,c,d) a, b, d, d, c, a
|
||||||
|
|
||||||
|
static const uint16 indexData[] = {
|
||||||
|
QUAD(0,1,2,3), // -X
|
||||||
|
QUAD(4,5,6,7), // +X
|
||||||
|
QUAD(0,1,4,5), // -Y
|
||||||
|
QUAD(2,3,6,7), // +Y
|
||||||
|
QUAD(0,2,4,6), // -Z
|
||||||
|
QUAD(1,3,5,7), // +Z
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef QUAD
|
||||||
|
|
||||||
|
const uint32 numTriangles = sizeof indexData / sizeof indexData[0] / 3;
|
||||||
|
uint32 vertexSid, indexSid;
|
||||||
|
Matrix perspectiveMat;
|
||||||
|
VMMousePacket lastMouseState;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* render --
|
||||||
|
*
|
||||||
|
* Set up common render state and matrices, then enter a loop
|
||||||
|
* drawing many cubes with individual draw commands.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
render(void)
|
||||||
|
{
|
||||||
|
SVGA3dRenderState *rs;
|
||||||
|
SVGA3dVertexDecl *decls;
|
||||||
|
SVGA3dPrimitiveRange *ranges;
|
||||||
|
static Matrix view, instance;
|
||||||
|
static uint32 frame = 0;
|
||||||
|
float x, y, gamma;
|
||||||
|
|
||||||
|
Matrix_Copy(view, gIdentityMatrix);
|
||||||
|
Matrix_Scale(view, 0.5, 0.5, 0.5, 1.0);
|
||||||
|
Matrix_RotateY(view, 30.0 * M_PI / 180.0);
|
||||||
|
Matrix_RotateX(view, ++frame * 0.001f);
|
||||||
|
Matrix_Translate(view, 0, 0, 15);
|
||||||
|
|
||||||
|
gamma = 0.f;
|
||||||
|
|
||||||
|
for (y = 0; y < GRID_Y_COUNT; y++) {
|
||||||
|
for (x = 0; x < GRID_X_COUNT; x++) {
|
||||||
|
float gamma = (x + y * GRID_X_COUNT) * GAMMA_STEP;
|
||||||
|
|
||||||
|
Matrix_Copy(instance, view);
|
||||||
|
Matrix_Translate(instance,
|
||||||
|
(x - GRID_X_COUNT / 2.0f + 0.5f) * GRID_STEP,
|
||||||
|
-(y - GRID_Y_COUNT / 2.0f + 0.5f) * GRID_STEP,
|
||||||
|
0);
|
||||||
|
|
||||||
|
SVGA3DUtil_SetShaderConstMatrix(CID, CONST_MAT_VIEW,
|
||||||
|
SVGA3D_SHADERTYPE_VS, instance);
|
||||||
|
|
||||||
|
SVGA3D_BeginSetRenderState(CID, &rs, 4);
|
||||||
|
{
|
||||||
|
rs[0].state = SVGA3D_RS_OUTPUTGAMMA;
|
||||||
|
rs[0].floatValue = gamma;
|
||||||
|
}
|
||||||
|
SVGA_FIFOCommitAll();
|
||||||
|
|
||||||
|
gamma += 0.1f;
|
||||||
|
|
||||||
|
SVGA3D_BeginDrawPrimitives(CID, &decls, 2, &ranges, 1);
|
||||||
|
{
|
||||||
|
decls[0].identity.type = SVGA3D_DECLTYPE_FLOAT3;
|
||||||
|
decls[0].identity.usage = SVGA3D_DECLUSAGE_POSITION;
|
||||||
|
decls[0].array.surfaceId = vertexSid;
|
||||||
|
decls[0].array.stride = sizeof(MyVertex);
|
||||||
|
decls[0].array.offset = offsetof(MyVertex, position);
|
||||||
|
|
||||||
|
decls[1].identity.type = SVGA3D_DECLTYPE_D3DCOLOR;
|
||||||
|
decls[1].identity.usage = SVGA3D_DECLUSAGE_COLOR;
|
||||||
|
decls[1].array.surfaceId = vertexSid;
|
||||||
|
decls[1].array.stride = sizeof(MyVertex);
|
||||||
|
decls[1].array.offset = offsetof(MyVertex, color);
|
||||||
|
|
||||||
|
ranges[0].primType = SVGA3D_PRIMITIVE_TRIANGLELIST;
|
||||||
|
ranges[0].primitiveCount = numTriangles;
|
||||||
|
ranges[0].indexArray.surfaceId = indexSid;
|
||||||
|
ranges[0].indexArray.stride = sizeof(uint16);
|
||||||
|
ranges[0].indexWidth = sizeof(uint16);
|
||||||
|
}
|
||||||
|
SVGA_FIFOCommitAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* main --
|
||||||
|
*
|
||||||
|
* Our example's entry point, invoked directly by the bootloader.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
SVGA3dRenderState *rs;
|
||||||
|
|
||||||
|
SVGA3DUtil_InitFullscreen(CID, 800, 600);
|
||||||
|
|
||||||
|
vertexSid = SVGA3DUtil_DefineStaticBuffer(vertexData, sizeof vertexData);
|
||||||
|
indexSid = SVGA3DUtil_DefineStaticBuffer(indexData, sizeof indexData);
|
||||||
|
|
||||||
|
SVGA3D_DefineShader(CID, MY_VSHADER_ID, SVGA3D_SHADERTYPE_VS,
|
||||||
|
g_vs20_MyVertexShader, sizeof g_vs20_MyVertexShader);
|
||||||
|
SVGA3D_DefineShader(CID, MY_PSHADER_ID, SVGA3D_SHADERTYPE_PS,
|
||||||
|
g_ps20_MyPixelShader, sizeof g_ps20_MyPixelShader);
|
||||||
|
|
||||||
|
Matrix_Perspective(perspectiveMat, 45.0f,
|
||||||
|
gSVGA.width / (float)gSVGA.height, 10.0f, 100.0f);
|
||||||
|
|
||||||
|
|
||||||
|
SVGA3D_SetTransform(CID, SVGA3D_TRANSFORM_WORLD, gIdentityMatrix);
|
||||||
|
SVGA3D_SetTransform(CID, SVGA3D_TRANSFORM_PROJECTION, perspectiveMat);
|
||||||
|
|
||||||
|
SVGA3D_SetShader(CID, SVGA3D_SHADERTYPE_VS, MY_VSHADER_ID);
|
||||||
|
SVGA3D_SetShader(CID, SVGA3D_SHADERTYPE_PS, MY_PSHADER_ID);
|
||||||
|
|
||||||
|
SVGA3DUtil_SetShaderConstMatrix(CID, CONST_MAT_PROJ,
|
||||||
|
SVGA3D_SHADERTYPE_VS, perspectiveMat);
|
||||||
|
|
||||||
|
SVGA3D_BeginSetRenderState(CID, &rs, 5);
|
||||||
|
{
|
||||||
|
rs[0].state = SVGA3D_RS_BLENDENABLE;
|
||||||
|
rs[0].uintValue = FALSE;
|
||||||
|
|
||||||
|
rs[1].state = SVGA3D_RS_ZENABLE;
|
||||||
|
rs[1].uintValue = TRUE;
|
||||||
|
|
||||||
|
rs[2].state = SVGA3D_RS_ZWRITEENABLE;
|
||||||
|
rs[2].uintValue = TRUE;
|
||||||
|
|
||||||
|
rs[3].state = SVGA3D_RS_ZFUNC;
|
||||||
|
rs[3].uintValue = SVGA3D_CMP_LESS;
|
||||||
|
|
||||||
|
rs[4].state = SVGA3D_RS_CULLMODE;
|
||||||
|
rs[4].uintValue = SVGA3D_FACE_FRONT;
|
||||||
|
}
|
||||||
|
SVGA_FIFOCommitAll();
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
SVGA3DUtil_ClearFullscreen(CID, SVGA3D_CLEAR_COLOR | SVGA3D_CLEAR_DEPTH,
|
||||||
|
0x000000, 1.0f, 0);
|
||||||
|
render();
|
||||||
|
SVGA3DUtil_PresentFullscreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue